2007.09.25, 02:11 AM
Why doesn't this script work?
It is meant to be a bot that has two models, defined by a random number (oxo) and also changes between the two mesh weapons (sr and ar) so that each weapon does a different thing at different parts of the script. It follows a node path to a node defined by parameter 0, crouches down when it gets there (or if it finds an enemy before that), have a watch on but only shoot if the enemy is in the line of sight.
I know that the damage and die functions are not there, but I can do them later. The crouched variable will be used in the damage function to animate it differently wether it is crouched or standing up.
Also, the engine says that obj.setting.team is not a function. I'm guessing that it only works on multiplayer :P.
If it's really bad, plz don't laugh at my script
.
Code:
const WALK_TO_NODE1=1;
const FIRE_START=2;
var oxo=utility.random.getInteger(1,2);
var seekingAI=false;
var crouched=false;
//
//'1' is the soldier with AR, '2' is the soldier with SR.
//
//Param. 1 is Destination Node.
//
function Construct(obj)
{
obj.model.on=true;
switch (oxo)
{
case '1':
obj.model.name="Human Soldier AR";
return;
case '2':
obj.model.name="Human Soldier SR";
}
obj.model.light.on=true;
obj.model.light.intensity=1000;
obj.model.light.confineToPortal=true;
obj.model.lightColor.red=1;
obj.model.lightColor.green=0.25;
obj.model.lightColor.blue=0.25;
obj.setting.hitBox=true;
obj.setting.bumpUp=true;
obj.setting.ignorePickUpItems=true;
obj.setting.team(DIM3_TEAM_BLUE);
obj.turnSpeed.facingWalk=1.7;
obj.turnSpeed.motionWalk=1.6;
obj.turnSpeed.facingAir=0.9;
obj.turnSpeed.motionAir=0.7;
obj.forwardSpeed.walk=40;
obj.forwardSpeed.acceleration=1.0;
obj.forwardSpeed.deceleration=1.2;
obj.forwardSpeed.accelerationAir=0.5;
obj.forwardSpeed.decelerationAir=0.1;
obj.health.maximum=100;
obj.health.start=100;
switch (oxo)
{
case '1':
obj.weapon.add("AI AR");
return;
case '2':
obj.weapon.add("AI SR");
return;
}
}
function Spawn(obj)
{
obj.model.animation.start('Idle');
switch (oxo)
{
case '1':
obj.model.animation.showMesh('AR');
return;
case '2':
obj.model.animation.showMesh('SR');
return;
}
obj.watch.start(30000);
NodeWalkStart(obj);
}
function NodeWalkStart(obj)
{
var whichNodeDestiny=obj.setting.getParameter(0);
var nodeId,nodeName;
nodeId=map.node.nearest(obj.position.x,obj.position.z,obj.position.y,null,null,null,0,3000);
if (nodeId==-1) return;
nodeName=map.node.getName(nodeId);
obj.forwardSpeed.walk=40;
obj.model.animation.start('Walking');
obj.motionVector.walkToNode(nodeName,whichNodeDestiny,WALK_TO_NODE1);
obj.event.startWaitRandom(50,90,FIRE_START);
seekingAI=false;
}
function NodeWalkResume(obj)
{
obj.forwardSpeed.walk=40;
obj.model.animation.start('Walking');
obj.motionVector.walkToNodeResume();
obj.event.startWaitRandom(50,90,FIRE_START);
seekingAI=false;
}
function NodeWalkFinish(obj,subEvent,id)
{
if (subEvent!=DIM3_EVENT_PATH_DONE) return;
if (id==WALK_TO_NODE1 || trackingAI)
{
obj.motionVector.stop();
obj.model.animation.startThenChange('StandToCrouch','Crouch');
crouched=true;
}
else
{
obj.motionVector.walkToNode(nodeName,whichNodeDestiny,WALK_TO_NODE1);
}
}
function Watch(obj,subEvent)
{
var enemy;
if (subEvent==DIM3_EVENT_WATCH_OBJECT_NEAR)
{
if(!obj.watch.objectTeam)
{
enemy=obj.watch.objectId;
TrackEnemy(obj);
}
}
else
{
NodeWalkFinish(obj,subEvent);
}
}
function TrackEnemy(obj,enemy)
{
if(obj.sight.testObject(enemy))
{
obj.motionVector.turnToObject(enemy);
obj.watch.stop();
obj.event.chain(5,'FireStart');
trackingAI=true;
}
else
{
NodeWalkFinish(obj);
}
}
function FireStart(obj)
{
switch (oxo)
{
case '1':
obj.model.animation.start('FireAR');
return;
case '2':
obj.model.animation.start('FireSR');
return;
}
Projectile(obj);
}
function Projectile(obj)
{
switch (oxo)
{
case '1':
obj.weapon.fire('AI AR',0);
obj.event.chain(2,'FireEnd');
return;
case '2':
obj.weapon.fire('AI SR',0);
obj.event.chain(20,'FireEnd');
return;
}
}
function FireEnd(obj)
{
obj.watch.start(30000);
}
function event(obj,mainEvent,subEvent,id,tick)
{
switch(mainEvent)
{
case DIM3_EVENT_CONSTRUCT:
Construct(obj);
return;
case DIM3_EVENT_SPAWN:
Spawn(obj);
return;
case DIM3_EVENT_DIE:
Die(obj);
return;
case DIM3_EVENT_DAMAGE:
DamageStart(obj,tick);
return;
case DIM3_EVENT_WATCH:
Watch(obj,subEvent);
return;
case DIM3_EVENT_WAIT:
Wait(obj,id,tick);
return;
case DIM3_EVENT_PATH:
NodeWalkFinish(obj,subEvent,id);
return;
}
}It is meant to be a bot that has two models, defined by a random number (oxo) and also changes between the two mesh weapons (sr and ar) so that each weapon does a different thing at different parts of the script. It follows a node path to a node defined by parameter 0, crouches down when it gets there (or if it finds an enemy before that), have a watch on but only shoot if the enemy is in the line of sight.
I know that the damage and die functions are not there, but I can do them later. The crouched variable will be used in the damage function to animate it differently wether it is crouched or standing up.
Also, the engine says that obj.setting.team is not a function. I'm guessing that it only works on multiplayer :P.
If it's really bad, plz don't laugh at my script
.
.