Scripting Tutorial: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
This tutorial goes into the specifics of adding NPCs to an existing map, and giving them interactivity. | This tutorial goes into the specifics of adding NPCs to an existing map, and giving them interactivity. | ||
Start the game in | Start the game in [[Dev Mode]] and select “Edit Ground” in the Dev Controls. | ||
[[File:Scripting_Intro.png|frameless]] | |||
== Adding Entity == | == Adding Entity == | ||
Start by opening an existing ground map. We will open <code>Data\Ground\cliff_camp.rsground</code> | |||
[[File:Scripting_Ground.png|frameless]] | |||
Switch to the “Entities” tab, and create a new Character object with these settings: | |||
[[File:Scripting_Char.png|frameless]] | |||
Don’t forget to switch to “Add New” Mode! | |||
Setting the trigger type to “Action” is what allows the character to be spoken to; the two callbacks listed below are the ones available when choosing that trigger type. They will be referred to later. | |||
[[File:Scripting_Char_Display.png|frameless]] | |||
Char display allows you to change everything about the character’s sprite. | |||
[[File:Scripting_Nickname.png|frameless]] | |||
You can specify a nickname for the character; if left blank, the species name is used. | You can specify a nickname for the character; if left blank, the species name is used. | ||
Click on the position in the map to place the character. | Click on the position in the map to place the character. | ||
[[File:Scripting_Map.png|frameless]] | |||
Save the map. | Save the map. | ||
== Setting Strings == | == Setting Strings == | ||
Switch to the Strings tab, and add dialogue. | Switch to the Strings tab, and add dialogue. | ||
[[File:Scripting_Strings.png|frameless]] | |||
Save the map as you would normally, to save the changes to the strings. | Save the map as you would normally, to save the changes to the strings. | ||
== Scripting == | == Scripting == | ||
Switch to the “Script” tab and open the script directory for this map: | Switch to the “Script” tab and open the script directory for this map: | ||
[[File:Scripting_Folder.png|frameless]] | |||
Alternatively, you can find the directory manually by going to <code>Data\Script\ground\cliff_camp</code> | Alternatively, you can find the directory manually by going to <code>Data\Script\ground\cliff_camp</code> | ||
[[File:Scripting_Folder_Opened.png|frameless]] | |||
Open <code>init.lua</code> in order to edit the logic behind the ground map. | Open <code>init.lua</code> in order to edit the logic behind the ground map. | ||
[[File:Scripting_Event.png|frameless]] | |||
There’s plenty of existing code here, you will need to add the following code: | There’s plenty of existing code here, you will need to add the following code: | ||
<pre> | |||
function cliff_camp.Meditite_Action(chara, activator) | function cliff_camp.Meditite_Action(chara, activator) | ||
DEBUG.EnableDbgCoro() --Enable debugging this coroutine | DEBUG.EnableDbgCoro() --Enable debugging this coroutine | ||
Line 99: | Line 62: | ||
UI:WaitShowDialogue(STRINGS:Format(MapStrings['Meditite_Line_002'])) | UI:WaitShowDialogue(STRINGS:Format(MapStrings['Meditite_Line_002'])) | ||
end | end | ||
</pre> | |||
Whenever you speak to an object, the game looks for a method named <code><Object name>_Action</code> and calls it. This is why our function is named <code>Meditite_Action</code>. | Whenever you speak to an object, the game looks for a method named <code><Object name>_Action</code> and calls it. This is why our function is named <code>Meditite_Action</code>. | ||
Line 105: | Line 68: | ||
The second argument, <code>activator</code>, is the player object. | The second argument, <code>activator</code>, is the player object. | ||
Save the file with your edits | Save the file with your edits, go back to the ground editor and reload the scripts. | ||
[[File:Scripting_Reload.png|frameless]] | |||
Exit the ground editor, and you will be returned to the title screen. | Exit the ground editor, and you will be returned to the title screen. | ||
Fast-travel to the cliff camp, and the Meditite should be added. | Fast-travel to the cliff camp, and the Meditite should be added. | ||
[[File:Scripting_Test.png|frameless]] | |||
If you experience issues, check the logs for the most recent errors in your current session. They are found in the <code>LOGS</code> folder. | If you experience issues, check the logs for the most recent errors in your current session. They are found in the <code>LOGS</code> folder. |
Latest revision as of 02:37, 7 September 2022
This tutorial goes into the specifics of adding NPCs to an existing map, and giving them interactivity.
Start the game in Dev Mode and select “Edit Ground” in the Dev Controls.
Adding Entity
Start by opening an existing ground map. We will open Data\Ground\cliff_camp.rsground
Switch to the “Entities” tab, and create a new Character object with these settings:
Don’t forget to switch to “Add New” Mode!
Setting the trigger type to “Action” is what allows the character to be spoken to; the two callbacks listed below are the ones available when choosing that trigger type. They will be referred to later.
Char display allows you to change everything about the character’s sprite.
You can specify a nickname for the character; if left blank, the species name is used.
Click on the position in the map to place the character.
Save the map.
Setting Strings
Switch to the Strings tab, and add dialogue.
Save the map as you would normally, to save the changes to the strings.
Scripting
Switch to the “Script” tab and open the script directory for this map:
Alternatively, you can find the directory manually by going to Data\Script\ground\cliff_camp
Open init.lua
in order to edit the logic behind the ground map.
There’s plenty of existing code here, you will need to add the following code:
function cliff_camp.Meditite_Action(chara, activator) DEBUG.EnableDbgCoro() --Enable debugging this coroutine GROUND:CharTurnToChar(chara,CH('PLAYER'))--make the chara turn to the player UI:SetSpeaker(chara)--set the dialogue box's speaker to the character UI:WaitShowDialogue(STRINGS:Format(MapStrings['Meditite_Line_001'])) UI:WaitShowDialogue(STRINGS:Format(MapStrings['Meditite_Line_002'])) end
Whenever you speak to an object, the game looks for a method named <Object name>_Action
and calls it. This is why our function is named Meditite_Action
.
The first argument, chara
, is the character being spoken to (Meditite).
The second argument, activator
, is the player object.
Save the file with your edits, go back to the ground editor and reload the scripts.
Exit the ground editor, and you will be returned to the title screen. Fast-travel to the cliff camp, and the Meditite should be added.
If you experience issues, check the logs for the most recent errors in your current session. They are found in the LOGS
folder.