dim3 Forum

Full Version: How do you write an enemy script? Can you just edit the joe foe script?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
I have just finished my first fully rigged model but i want to write an enemy script (I have know scripting knowledge), so i have two questions.

1:How do you write an enemy script?
2:Can you just edit the Joe foe script?

Thanks.Smile
It would be best for you to start with the joe foe script and edit it the way you want. Once you fully understand joe foe you will understand how to write a basic enemy script.
First play around with the joefoe script, find out what does what, and yes you can edit the joefoe script. Writing a good enemy script is very complicated and i suggest you take a while to learn dim3 javascript before jumping in and making an enemy script.
I just have a few questions,
What would i need to change as the bare minimum to get it running, badly.
Where do i change the mesh?

Thanks.
Code:
const JF_WAIT_ID_FIRE_START=1;
const JF_WAIT_ID_MELEE_START=2;

const JF_PLAYER_DISTANCE=15000;

// variables

var lastHit=0;
var seekingPlayer=false;
var healthDropId;

// ================================================================================ ======
// STARTING THE OBJECT
// ================================================================================ ======
//
// This function is called from an event when a JoeFoe script has started (i.e., the script
// object is being constructed.)  It sets up a number of settings and options to describe
// the JoeFoe object.
//
// ================================================================================ ======

function joeFoeConstruct(obj)
{
        // setup model
        
    obj.model.on=true;
    obj.model.name='Royalist Power Knight Cloaked';
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;
    obj.model.truform=true;
    obj.model.shadow.on=true;

        // setup joefoe settings

    obj.setting.hitBox=true;
    obj.setting.damage=true;
    obj.setting.bumpUp=true;
    obj.setting.ignorePickUpItems=true;        // don't pickup the weapons/ammo
    obj.setting.openDoors=true;
    
    obj.size.x=1600;
    obj.size.z=1600;
    obj.size.y=2300;
    obj.size.weight=250;
    
    obj.turnSpeed.facingWalk=1.7;
    obj.turnSpeed.motionWalk=1.6;
    obj.turnSpeed.facingAir=0.9;
    obj.turnSpeed.motionAir=0.7;
    
    obj.forwardSpeed.walk=155;
    obj.forwardSpeed.acceleration=1.0;
    obj.forwardSpeed.deceleration=1.2;
    obj.forwardSpeed.accelerationAir=0.5;
    obj.forwardSpeed.decelerationAir=0.1;

    obj.health.maximum=60;
    obj.health.start=60;

        // set the hilite color to green for glowing
        
    obj.model.hiliteColor.red=1;
    obj.model.hiliteColor.green=1;
    obj.model.hiliteColor.blue=1;

        // joefoe melee
        
    obj.melee.strikeBoneTag='barr';
//
//
//
//
// ======CHANGE THESE, they are the bone which the melee comes from, and the pose which the melee comes from.
//
//
//
//
    obj.melee.strikePoseName='Attack4';
    obj.melee.radius=500;
    obj.melee.distance=1000;        // strike ahead of joefoe
    obj.melee.damage=70;
    obj.melee.force=0;
    
        // an item for JoeFoe to drop

}




function joeFoeSpawn(obj)
{
    lastHit=0;

        // put a watch on the map objects
        // this will throw an event when we get within
        // 8000 map units of the an object or leave
        // that distance.
        
    obj.watch.start(JF_PLAYER_DISTANCE);
}



function joeFoeSeekPlayer(obj,doGrowl)
{
        // cancel object watching, we found player

    obj.watch.stop();

        // start chasing player
        
    obj.motionVector.walkToPlayer();
    obj.model.animation.start('Walk');
//
//
//
//
//
// CHANGE ALL ANIMATIONS, LIKE YOUR WALK ANIMATION GOES ABOVE.
//
//
//
//
//
    
        // growl when noticing player
        
    if (doGrowl)
    
        // start a timer for melees
        
    obj.event.startWaitRandom(30,40,JF_WAIT_ID_MELEE_START);
    
        // set a flag so damage knows what we are seeking
        
    seekingPlayer=false;
}

function joeFoeWatch(obj,subEvent)
{
        // watch triggered for getting within range of object
        
    if (subEvent==DIM3_EVENT_WATCH_OBJECT_NEAR) {
        if (obj.watch.objectIsPlayer) joeFoeSeekPlayer(obj,true);
    }
}


    
function joeFoeMeleeStart(obj)
{
    var            x,z,y;
    
        // are we close enough to hit with melee?
        
    if (obj.position.distanceToPlayer()>2000) {
        obj.event.startWait(30,JF_WAIT_ID_MELEE_START);
        return;
    }

        // start the attack animation
        
    if (utility.random.getBoolean()) {
        obj.model.animation.start('Attack');
    }
    else {
        obj.model.animation.start('Attack');

//
//
//
//
//
//CHANGE THE ATTACK ANImATIONS ABOVE.
//
//
//
//
    }

        // glow green
        
    obj.model.lit=DIM3_MODEL_LIT_HILITE;

        // wait for a while to fire melee to synch with animation
        
    obj.event.chain(4,'joeFoeMeleeEnd');
}

function joeFoeMeleeEnd(obj)
{
        // turn off glow
        
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;

        // the melee attack
        
    obj.melee.spawnFromObjectBone();
        
        // make sure to go back to walk attack
    
    obj.model.animation.change('Walk');
//
//
//
//
//
//
//
//THATS THE WALK ANIMATION AGAIN!!!
//
//
//
//
//
    
        // prepare for next melee
        
    obj.event.startWaitRandom(30,40,JF_WAIT_ID_MELEE_START);
}


function joeFoeDamageStart(obj,tick)
{
    var        health,pauseCount;
    
    health=obj.health.current;
    if (health<=0) return;
    
        // don't run hurt animation or sound effects too much
        
    if (lastHit>tick) return;

    lastHit=tick+600;
    
        // reset hiliting out of fire mode
        
    obj.event.clearChain();
    obj.model.lit=DIM3_MODEL_LIT_VERTEX;
    
        // hurt animation
        // change for which hit box took the hit, default to body hits if none
        
    switch (obj.hit.hitBoxName) {
    
        case 'Head':
            obj.model.animation.start('flinch2');
            pauseCount=10;
            break;
            
        case 'Legs':
            obj.model.animation.start('flinch2');
            pauseCount=18;
            break;
            
        default:
            obj.model.animation.start('flinch2');
//^ ABOVE YOU NEED TO CHANGE THE HURT ANIMATION
//
//
//
//
            pauseCount=1;
            break;
            
    }
    
        // blood
        
    spawn.particle(obj.hitPosition.x,obj.hitPosition.z,obj.hitPosition.y,'JoeFoe Blood');
    
        // cancel the object watching so animation isn't interupted
        
    obj.watch.stop();
    
        // wait for animations to stop before continuing
        
    obj.motionVector.stop();
    obj.motionAngle.turnStop();
    
    obj.event.chain(pauseCount,'joeFoeDamageDone');
}

function joeFoeDamageDone(obj,tick)
{
        // always seek the player after hit
        
    joeFoeSeekPlayer(obj,false);
}

function joeFoeDie(obj)
{
        // turn into skull and run animation
      
    obj.model.animation.startThenChange('dying','dead');
    obj.setting.contact=false;
    obj.setting.suspend=true;
    obj.radar.on=false;
    
        // stop movement
        
    obj.event.clearWait();
    obj.motionVector.stop();
    obj.motionAngle.turnToAngle(obj.angle.y,0);
    

    
        // cancel the object watching
        
    obj.watch.stop();

    
    obj.event.chain(50,'joeFoeDieDone');
}

function joeFoeDieDone(obj,tick)
{
        // Furious Frogs, ROFLMAOQQQ!!!!
}



function joeFoeWait(obj,id,tick)
{
    switch (id) {

        case JF_WAIT_ID_MELEE_START:
            joeFoeMeleeStart(obj);
            return;
    }
}



function event(obj,mainEvent,subEvent,id,tick)
{
    switch (mainEvent) {

        case DIM3_EVENT_CONSTRUCT:
            joeFoeConstruct(obj);
            return;
    
        case DIM3_EVENT_SPAWN:
            joeFoeSpawn(obj);
            return;
            
        case DIM3_EVENT_DIE:
            joeFoeDie(obj);
            return;
            
        case DIM3_EVENT_DAMAGE:
            joeFoeDamageStart(obj,tick);
            return;
            
        case DIM3_EVENT_WATCH:
            joeFoeWatch(obj,subEvent);
            return;
            
        case DIM3_EVENT_WAIT:
            joeFoeWait(obj,id,tick);
            return;
            
    }
}
Typewriter, you forgot the last bracket on your [/code. Should be [/code]. Smile
In the first function, change this line:
Code:
obj.model.name="NAME HERE";

You can check out my basic scripting tutorial if you haven't already: http://dim3wiki.site88.net/wiki/index.ph...g_Tutorial
It tells me that my model has missing or no strike bone. i have set the bone.
What should i do to fix it?
Make sure that what you entered for
Code:
obj.melee.strikeBoneTag='<name>';
is correctly spelled and that the bone exists in your model.
Is the strike bone tag case sensitive?
Pages: 1 2 3 4
Reference URL's