dim3 Forum

Full Version: Human Soldier No Works :(
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Why doesn't this script work?

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 Sad.
Try replacing return; with break; in your switch blocks.
That script looks intresting! What are you trying to make?
Chainfist Wrote:If it's really bad, plz don't laugh at my script Sad.

Sorry I can't help you with your script right now (no time at the moment) but there's one thing I want to say.
NOBODY here will laugh at your script. We will probably tell you a better way to do it or give you tips to improve it but we won't laugh at you. Wink
cyst Wrote:Try replacing return; with break; in your switch blocks.

Yes, a lot of those are in really bad places.

return = leave the function
break = leave the current block

For instance:

Code:
function abc(....)
{
  a;
  b;
  for () {
     break;  // "break" out of loop, will continue on with c
   }
   c;
   return;   // completely leave function, return to caller function
   d;  // never gets executed
}

I know a lot of this code originated with the demo, and the places I used return (for instance, in the event script) is because there is only ONE event coming in at a time (of course), so after you deal with it, you don't have to do anything else so just exit the function.

You, on the other hand, want to use break in some cases, for instance:

Code:
a;
b;
switch (....) {
  case 1:
     break; // will go to line c (leaves the block, the thing between {})
  case 2:
     return; // will exit function, c will never be executed
}
c;

[>] Brian
The team thing probably won't work because it has no equals sign Smile.
Also I'm not sure you actually need to use the color teams. I'm using 2.2, using all the old string named teams, and it works just fine.
Could I do
Code:
obj.setting.team="humans";
?
No I dont think so. You have to use DIM3_TEAM_???. Replace ??? with blue, red, green, purple, orange, yellow or none.
Gordon CSA Wrote:The team thing probably won't work because it has no equals sign Smile.
Also I'm not sure you actually need to use the color teams. I'm using 2.2, using all the old string named teams, and it works just fine.

That shouldn't be working, what's probably happening is the string is getting turned into a number in the javascript and that's what's making it "seem" to work but I'll bet it'll break in some situation.

[>] Brian
Orixa Wrote:No I dont think so. You have to use DIM3_TEAM_???. Replace ??? with blue, red, green, purple, orange, yellow or none.

Yes. The reason for this change was all due to networking -- open ended team names meant much, much more complicated game scripting and network messages, and you couldn't even have a UI "pick a default team" because you wouldn't know the possible teams before joining a server.

[>] Brian
Pages: 1 2 3
Reference URL's