Tut | Monsterscript - JasXSL/GoThongs GitHub Wiki

I'm assuming you've read the tutorial on [descriptions](Tut | Descriptions). Let's make a goblin that will patrol a path through a simple monsterscript.

Spawn a cock goblin as per usual and position him where he should start. I'm not gonna tweak any of his abilities, just make him patrol, so his description will look like:

$[["SC","ms GoblinPatrol"]]

Add it

Now make a new script inside the level root prim, name it ms GoblinPatrol, make it full perm, set it to not running. Open from your devkit templates ms MonsterScript and copy the script over to ms GoblinPatrol. I'm going to remove the content from timerEvent and remove listen. In onEvt on the bridge init event I'll put multiTimer(["WALK", 0, 1, FALSE]);

The full script should now look something like:

#define USE_EVENTS
#include "got/_core.lsl"
list PLAYERS;

onEvt(string script, integer evt, string data){
    // The template script says "got Bridge", but it should be "got Portal"
    if(script == "got Portal" && evt == evt$SCRIPT_INIT){
        PLAYERS = llJson2List(data);
        multiTimer(["WALK", 0, 1, FALSE]);
    }
}
timerEvent(string id, string data){
    
}
default
{
    state_entry()
    {
        raiseEvent(evt$SCRIPT_INIT, "");
    }
    timer(){multiTimer([]);}
    #include "xobj_core/_LM.lsl"
    #define LM_BOTTOM  
    #include "xobj_core/_LM.lsl" 
}

Compile the script for now and minimize it. Then say "walkpad" in chat to spawn a walk designer. I'll copy the goblin's position and rotation in the build tools floater and paste into the walkpad so they have the same root position and rotation. Then touch the walkpad. You should see "start pos SET"

Now edit both the goblin and walkpad at the same time to move the goblin to where you want it go to. It will go in a straight path. Then touch the walkpad and you will get "1 nodes set".

We also need him to walk back, but first we need him to rotate quickly, because the rotation is tweened between nodes.

Now we move him back to the starting position. I'll use ctrl+z on both walkpad and the goblin, and then rotate him and click the walkpad again.

Now all I need to do is rotate him back to his original state and touch again. 4 nodes should be set. Now say "WA" in chat and you will get some output with a list you can put into keyframed motion.

We'll do just that.

#define USE_EVENTS
#include "got/_core.lsl"
list PLAYERS;

onEvt(string script, integer evt, string data){
    if(script == "got Portal" && evt == evt$SCRIPT_INIT){
        PLAYERS = llJson2List(data);
        multiTimer(["WALK", 0, 1, FALSE]);
    }
}
timerEvent(string id, string data){
    if(id == "WALK"){
        llSetKeyframedMotion([
         <2.90126, 0.00000, 0.00000>,NormRot(<0.00000, 0.00000, 0.00000, 1.00000>),2.911111,
         <0.00000, 0.00000, 0.00000>,NormRot(<-1.00000, -0.00017, 0.00000, 0.00017>),0.111111,
         <-2.90126, 0.00000, 0.00000>,NormRot(<-0.00017, 0.00000, 0.00017, 1.00000>),2.911111,
         <0.00000, 0.00000, 0.00000>,NormRot(<1.00000, 0.00000, 0.00000, 0.00000>),0.111111
        ], [KFM_MODE, KFM_LOOP]);
    }
}
default
{
    state_entry()
    {
        raiseEvent(evt$SCRIPT_INIT, "");
    }
    timer(){multiTimer([]);}
    #include "xobj_core/_LM.lsl"
    #define LM_BOTTOM  
    #include "xobj_core/_LM.lsl" 
}

If you get an error about delta times you'll want to change any 0.111111 to 0.111112 in your script. Now we have a goblin that walks back and forth along a straight line. Generally if you need a monster that just roams around you should use the "Monster free roaming range" setting (see the monster setting sheet) as keyframed motion has a tendency to drift off of target after a while.

If you now test the monster by finding it's ID with listSpawns and testSpawn -1, 1 you'll notice that the monster just glides back and forth. We can fix this by simply adding MaskAnim$start("walk"); before the keyframed motion call. Note: If the monster aggros you, just build a wall or something to separate you from the monster.

If the monster doesn't start animating, you probably need to wait longer for jas MaskAnim to be fully initialized. Just change multiTimer(["WALK", 0, 1, FALSE]); to multiTimer(["WALK", 0, 3, FALSE]);

And that's how simple it is. Here are some header files on what methods you can use on monsters and what events they raise that can be captured from your monsterscript:

⚠️ **GitHub.com Fallback** ⚠️