Monster Scripts: Difference between revisions

From Gothongs Wiki
Jump to navigationJump to search
Panda (talk | contribs)
No edit summary
Panda (talk | contribs)
No edit summary
Line 1: Line 1:
Monster scripts are scripts that are injected into monsters on demand inside levels. The monster scripts are custom and stored inside of each level.
Monster scripts are scripts that are injected into monsters on demand inside levels. The monster scripts are custom and stored inside of each level.
A good template of a monster script can be found in ms MonsterScript which is included with the developer tools.
You can make a monster script any way you want! The only requirement is that you raise the SCRIPT_INIT event once your script is ready to go. In the template this is added to the state_entry event handler: raiseEvent(evt$SCRIPT_INIT, "");
== 1. Adding a monster script to the level ==
# Edit the level and create a new script. To make it easy to distinguish you should start the script name with "ms ". Like "ms Goblin".
# Set the script to full perm (mod/copy/transfer).
# Open the script and uncheck the Running box.
# Copy the contents from ms MonsterScript to your ms Goblin script.
# In state entry add llOwnerSay("The monster script loaded successfully!");
# Rez a goblin or some other NPC by saying: spawn Cock Goblin 2
# Set its description to: $<nowiki>[["SC","ms Goblin"]]</nowiki>
# Create a spawn entry by saying: add
# Spawn the monster as live. If you did everything right you will get a chat message saying that the script loaded successfully.
# What you do with the monster script is up to you. It can interact with all events and run methods on the scripts involved with NPCs. Like got Monster or got Status. The methods and events are defined in the script header files: https://github.com/JasXSL/GoThongs/tree/master/classes
== 2. Interacting with an NPC ==
# Let us use a monster script called "ms Goblin". We set the monster description to ''$[["SC","ms Goblin"],[0,8664]]'' You can edit an existing description by finding its id by saying listSpawns. If you created a goblin in the last section you can replace its spawn description by finding its id. In my case the ID of my goblin was 7. So I say ''setSpawnVal 7 4 [["SC","ms Goblin"],[0,8662]]''
# The 0 task means to set a bitwise combination of monster flags. The flags 8664 Monster$RF_NOAGGRO, Monster$RF_FREEZE_AGGRO, Monster$RF_INVUL, Monster$RF_NO_TARGET, Monster$RF_NO_SPELLS, Monster$RF_ANIMESH. This means that the monster cannot aggro, it is invulnerable, it cannot be targeted by players, it cannot use spells, and it is animesh. The animesh flag is required for animesh monsters because they use X forward instead of the old monsters that use Z forward.
# Interacts (E) will only be sent to a script called got LocalConf. But we can add a script alias to our monsterscript. Before #include "got_mods/pandamod/_core.lsl" you must put #define SCRIPT_ALIASES ["got LocalConf"]
# Find the "// Put your initialization code in here" comment and below it put: Status$monster_overrideDesc("D$Hello!$$STDIN");
# Replace the link message handler with:<pre>
// Standard in
    #include "xobj_core/_LM.lsl"
    if( method$isCallback )
        return;
    if( METHOD == LocalConfMethod$stdInteract ){
        llOwnerSay("I have been interacted with!");
    }
    #define LM_BOTTOM 
    #include "xobj_core/_LM.lsl"
</pre>
# Compile the script and spawn your monster live.
# If you did it correct you can now press E on the monster to interact with it. Doing so will output your "I have been interacted with!" message.
# You can remove interactivity from a monster by running ''Status$monster_overrideDesc("");''
== 3. Using the walk helper to create a path for your NPC ==
[[Category:Tutorials]]
[[Category:Tutorials]]

Revision as of 12:13, 15 April 2024

Monster scripts are scripts that are injected into monsters on demand inside levels. The monster scripts are custom and stored inside of each level.

A good template of a monster script can be found in ms MonsterScript which is included with the developer tools.

You can make a monster script any way you want! The only requirement is that you raise the SCRIPT_INIT event once your script is ready to go. In the template this is added to the state_entry event handler: raiseEvent(evt$SCRIPT_INIT, "");

1. Adding a monster script to the level

  1. Edit the level and create a new script. To make it easy to distinguish you should start the script name with "ms ". Like "ms Goblin".
  2. Set the script to full perm (mod/copy/transfer).
  3. Open the script and uncheck the Running box.
  4. Copy the contents from ms MonsterScript to your ms Goblin script.
  5. In state entry add llOwnerSay("The monster script loaded successfully!");
  6. Rez a goblin or some other NPC by saying: spawn Cock Goblin 2
  7. Set its description to: $[["SC","ms Goblin"]]
  8. Create a spawn entry by saying: add
  9. Spawn the monster as live. If you did everything right you will get a chat message saying that the script loaded successfully.
  10. What you do with the monster script is up to you. It can interact with all events and run methods on the scripts involved with NPCs. Like got Monster or got Status. The methods and events are defined in the script header files: https://github.com/JasXSL/GoThongs/tree/master/classes

2. Interacting with an NPC

  1. Let us use a monster script called "ms Goblin". We set the monster description to $[["SC","ms Goblin"],[0,8664]] You can edit an existing description by finding its id by saying listSpawns. If you created a goblin in the last section you can replace its spawn description by finding its id. In my case the ID of my goblin was 7. So I say setSpawnVal 7 4 [["SC","ms Goblin"],[0,8662]]
  2. The 0 task means to set a bitwise combination of monster flags. The flags 8664 Monster$RF_NOAGGRO, Monster$RF_FREEZE_AGGRO, Monster$RF_INVUL, Monster$RF_NO_TARGET, Monster$RF_NO_SPELLS, Monster$RF_ANIMESH. This means that the monster cannot aggro, it is invulnerable, it cannot be targeted by players, it cannot use spells, and it is animesh. The animesh flag is required for animesh monsters because they use X forward instead of the old monsters that use Z forward.
  3. Interacts (E) will only be sent to a script called got LocalConf. But we can add a script alias to our monsterscript. Before #include "got_mods/pandamod/_core.lsl" you must put #define SCRIPT_ALIASES ["got LocalConf"]
  4. Find the "// Put your initialization code in here" comment and below it put: Status$monster_overrideDesc("D$Hello!$$STDIN");
  5. Replace the link message handler with:

// Standard in #include "xobj_core/_LM.lsl" if( method$isCallback ) return; if( METHOD == LocalConfMethod$stdInteract ){ llOwnerSay("I have been interacted with!"); } #define LM_BOTTOM #include "xobj_core/_LM.lsl"

  1. Compile the script and spawn your monster live.
  2. If you did it correct you can now press E on the monster to interact with it. Doing so will output your "I have been interacted with!" message.
  3. You can remove interactivity from a monster by running Status$monster_overrideDesc("");

3. Using the walk helper to create a path for your NPC