Advanced Level Features: Difference between revisions

From Gothongs Wiki
Jump to navigationJump to search
Panda (talk | contribs)
Panda (talk | contribs)
Line 47: Line 47:


=== Level scripts ===
=== Level scripts ===
Before you can start. You must install the GoThongs and LSL libraries: [[Installing Script Libraries]]


==== On level loaded ====
The level _MAIN script is a unique script to each level. The other scripts are loaded from the HUD and overwritten when you rez the level. All the custom game logic should go in the _MAIN script.


==== Triggers ====
There are two main ways to communicate:
 
* The built in scripts such as got Level, got LevelData etc raise events that you can do things with in the onEvt function. You can find events raised by built in scripts in their header files. Such as LevelEvt$ constants in https://github.com/JasXSL/GoThongs/blob/master/classes/got%20Level.lsl#L47 See the script header files for events that you can utilize!
* To communicate between custom scripts you use standard LSL listeners. Many levels use channel 69 or 80085 but you can pick your own channels.
 
The _MAIN script comes with a few of the most common events pre-defined. We will go through some of them:
 
==== LevelEvt$load ====
Raised when a spawn group (see below) has been loaded. An empty spawn group of "" means that the level start has loaded, and is a good place to reset your custom code such as level progress.
 
==== Triggers & Spawn Groups ====
Triggers are events tied to players walking through a trigger prim. They are often used to track player progress and spawn monsters as you go. Spawning only a few monsters at start and then more monsters as player proceed makes the level much faster to load and reduces prim cost. It is recommended.
 
# You can spawn a trigger the same way you do monsters. The recommended way is to say "spawn Trigger" in chat.
# Place and resize the trigger.
# Say "trig SPB" in chat. This will update the description for you which consists of an JSON array with 3 values:  1. A vector that should be the size of the trigger, so if your trigger is 6x2x4, the first value should be "<6,2,4>".  2. An integer of flags. Currently only 1 flag is supported: 0x1 and causes the trigger to despawn when triggered. 3. A name that is included in the trigger event.
# Save it like any other asset by saying "add".
# Edit your _MAIN script and find the LevelEvt$trigger handler and edit the if(d == "SPB") if statement to: if(d == "SPB"){ qd("Trigger named SPB triggered!"); }
# Say listAssets or click ASSETS on your dev HUD and spawn the trigger live. The trigger will flash quickly and go invisible.
# Walking into the trigger will make your _MAIN script output a debug message saying that you triggered it.
 
Let us create a monster spawn group and have it spawn when players walk into the trigger.
 
# Spawn a monster or a few like you did in the first guide.
# You are familiar with the "add" command. If you put some text after typing add, it creates spawns with a spawn group for that text. For now, type "add SPB" to create spawn entries with the spawn group "SPB". Remember to clean  up after adding them.
# You will get a message like this: [14:58] Test Level: Inserted 5 >>> [0,"Cock Goblin 2","<3,6,11.16>","<0,0,-0.707,.707>","","SPB"] (Remove)  [14:58] Test Level: Inserted 6 >>> [0,"Cock Goblin 2","<4.5,3,11.16>","","","SPB"] (Remove)
# The final value in the array (index #5) is the spawn group. You can test spawning the group live by saying "load live SPB"
# Go back to your _MAIN script and edit the SPB if statement again: if(d == "SPB"){ Level$intLoadSharp("SPB"); }
# Spawn your trigger live again. This time when you walk through it, all the NPCs with the spawn group set to "SPB" will spawn.


==== ID Events ====
==== ID Events ====

Revision as of 15:03, 13 April 2024

If you have not. You should check Creating a Level first.

Let us begin with level features that require no scripting. The following features are added by editing prim descriptions.

The XOBJ syntax for descriptions are task0$task0arg0$task0arg1...$$task1$task1arg0$task1arg1...

Separate tasks from arguments with a single $

Use multiple tasks in a description by separating them with $$

These three features are all set by scanning the description of the prim that a player is standing on. You do not have to set the soundspace or environment on every prim, because it will only updated when the player moves to another prim that has a soundspace or environment description. Footsteps require all prims that you walk on to have the proper sound in the description.

Soundspace

A soundspace is a way to set an ambient loop to play in the background. There are built in soundspaces, but you can also set your own via UUID.

The soundspace tasks looks like: "SS$sound$volume", so "SS$ru$0.2" will add a rumble ambient loop.

You can replace the ru with a UUID to use a custom sound, or use one of the preset sounds from the soundspace header file: https://github.com/JasXSL/SL-XOBJ/blob/master/xobj_core/classes/jas%20Soundspace.lsl

Footsteps

Footsteps use the same system. Footsteps should be set on all of the prims that avatars walk on. Many of the JasX library meshes come with footsteps already setup.

The footstep task looks like: "tFS$type", if you wanted sand you would use "tFS$SAND". You can find a full list of supported sounds in the header file: https://github.com/JasXSL/SL-XOBJ/blob/master/xobj_toonie/classes/ton%20Footsteps.lsl

You cannot use UUIDs for footsteps. But you can make pull requests on githup for additional sounds.

Environment Settings

Environment settings allow you to change the sky setting (formerly windlight). It works like Soundspace in that it is only needed on points where you want it to change, such as the prim players start their level on.

The environment task looks like: "WL$sky_uuid", such as "WL$96b70f39-ce1e-8e92-257d-d54d34bd3853"

You can only use UUIDs for this setting.

Doing all at once

Let us assume that we want to set footsteps, windlight, and a soundspace on the prim that players start the level on.

The soundspace looks like "SS$ru$0.2", the footsteps like "tFS$SAND", and windlight like "WL$96b70f39-ce1e-8e92-257d-d54d34bd3853".

We combine these with $$ to get the description: SS$ru$0.2$$tFS$SAND$$WL$96b70f39-ce1e-8e92-257d-d54d34bd3853

We edit the floor prim that player start on and set its description to that. The change should be immediately visible!

Water

Making your level more interactive with scripts

Level scripts

Before you can start. You must install the GoThongs and LSL libraries: Installing Script Libraries

The level _MAIN script is a unique script to each level. The other scripts are loaded from the HUD and overwritten when you rez the level. All the custom game logic should go in the _MAIN script.

There are two main ways to communicate:

  • The built in scripts such as got Level, got LevelData etc raise events that you can do things with in the onEvt function. You can find events raised by built in scripts in their header files. Such as LevelEvt$ constants in https://github.com/JasXSL/GoThongs/blob/master/classes/got%20Level.lsl#L47 See the script header files for events that you can utilize!
  • To communicate between custom scripts you use standard LSL listeners. Many levels use channel 69 or 80085 but you can pick your own channels.

The _MAIN script comes with a few of the most common events pre-defined. We will go through some of them:

LevelEvt$load

Raised when a spawn group (see below) has been loaded. An empty spawn group of "" means that the level start has loaded, and is a good place to reset your custom code such as level progress.

Triggers & Spawn Groups

Triggers are events tied to players walking through a trigger prim. They are often used to track player progress and spawn monsters as you go. Spawning only a few monsters at start and then more monsters as player proceed makes the level much faster to load and reduces prim cost. It is recommended.

  1. You can spawn a trigger the same way you do monsters. The recommended way is to say "spawn Trigger" in chat.
  2. Place and resize the trigger.
  3. Say "trig SPB" in chat. This will update the description for you which consists of an JSON array with 3 values: 1. A vector that should be the size of the trigger, so if your trigger is 6x2x4, the first value should be "<6,2,4>". 2. An integer of flags. Currently only 1 flag is supported: 0x1 and causes the trigger to despawn when triggered. 3. A name that is included in the trigger event.
  4. Save it like any other asset by saying "add".
  5. Edit your _MAIN script and find the LevelEvt$trigger handler and edit the if(d == "SPB") if statement to: if(d == "SPB"){ qd("Trigger named SPB triggered!"); }
  6. Say listAssets or click ASSETS on your dev HUD and spawn the trigger live. The trigger will flash quickly and go invisible.
  7. Walking into the trigger will make your _MAIN script output a debug message saying that you triggered it.

Let us create a monster spawn group and have it spawn when players walk into the trigger.

  1. Spawn a monster or a few like you did in the first guide.
  2. You are familiar with the "add" command. If you put some text after typing add, it creates spawns with a spawn group for that text. For now, type "add SPB" to create spawn entries with the spawn group "SPB". Remember to clean up after adding them.
  3. You will get a message like this: [14:58] Test Level: Inserted 5 >>> [0,"Cock Goblin 2","<3,6,11.16>","<0,0,-0.707,.707>","","SPB"] (Remove) [14:58] Test Level: Inserted 6 >>> [0,"Cock Goblin 2","<4.5,3,11.16>","","","SPB"] (Remove)
  4. The final value in the array (index #5) is the spawn group. You can test spawning the group live by saying "load live SPB"
  5. Go back to your _MAIN script and edit the SPB if statement again: if(d == "SPB"){ Level$intLoadSharp("SPB"); }
  6. Spawn your trigger live again. This time when you walk through it, all the NPCs with the spawn group set to "SPB" will spawn.

ID Events

Music

Objective Hints

Using the timer template for cutscenes

Monster Scripts