diff options
author | JMM889901 <41163714+JMM889901@users.noreply.github.com> | 2022-01-27 13:21:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 14:21:56 +0100 |
commit | 8ebc0a67c03886fe09c771af432683500ecabf83 (patch) | |
tree | 985b2cd15796b6a4d5142dc7653b4206fe907cb1 /docs/modding/squirrel/setting-mods | |
parent | 7f08b061845ca4f926b939acad6bd2dea8a7dce3 (diff) | |
download | NorthstarWiki-8ebc0a67c03886fe09c771af432683500ecabf83.tar.gz NorthstarWiki-8ebc0a67c03886fe09c771af432683500ecabf83.zip |
Began adding entries for squirrel GNUT scripting (#27)
* bruh
* Update what-is-squirrel.md
* Create Handling-threads-and-waits.md
* Update Handling-threads-and-waits.md
* Update What-are-callbacks.md
* i got locked out while making this
* Update what-is-squirrel.md
* confusion is bad
* funne colors
* bruh
* Language moment
* Update the-mod-file.md
* Json moment
* Update The-JSON.md
* Update The-JSON.md
* Update The-JSON.md
* Update The-language-file.md
* Update The-language-file.md
* Update the-mod-file.md
* Update The-language-file.md
* Create The-mod-init.md
* got distracted, will finish later
* pain
* Update The-mod-init.md
* fixed typo
* Rename What-are-callbacks.md to what-are-callbacks.md
* Rename Loops-Functions-and-if.md to loops-functions-and-if.md
* Rename docs/modding/squirrel/Setting mods/the-mod-file.md to docs/modding/squirrel/setting-mods/the-mod-file.md
* Rename docs/modding/squirrel/Setting mods/The-language-file.md to docs/modding/squirrel/setting mods/the-language-file.md
* Rename docs/modding/squirrel/Gamemode mods/The-mod-init.md to docs/modding/squirrel/gamemode mods/the-mod-init.md
* Rename Handling-threads-and-waits.md to handling-threads-and-waits.md
* Rename docs/modding/squirrel/Setting mods/The-JSON.md to docs/modding/squirrel/setting mods/the-json.md
* Rename Respawns-Functions.md to respawns-functions.md
* Rename docs/modding/squirrel/gamemode mods/the-mod-init.md to docs/modding/squirrel/gamemode-mods/the-mod-init.md
* Rename docs/modding/squirrel/setting mods/the-json.md to docs/modding/squirrel/setting-mods/the-json.md
* Rename docs/modding/squirrel/setting mods/the-language-file.md to docs/modding/squirrel/setting-mods/the-language-file.md
* tables do kinda be cool tho
* var is better now
* bruh
Diffstat (limited to 'docs/modding/squirrel/setting-mods')
-rw-r--r-- | docs/modding/squirrel/setting-mods/the-json.md | 38 | ||||
-rw-r--r-- | docs/modding/squirrel/setting-mods/the-language-file.md | 17 | ||||
-rw-r--r-- | docs/modding/squirrel/setting-mods/the-mod-file.md | 96 |
3 files changed, 151 insertions, 0 deletions
diff --git a/docs/modding/squirrel/setting-mods/the-json.md b/docs/modding/squirrel/setting-mods/the-json.md new file mode 100644 index 0000000..db80a55 --- /dev/null +++ b/docs/modding/squirrel/setting-mods/the-json.md @@ -0,0 +1,38 @@ +The mod.json +============ + +The mod.json is responsible for governing when, and where your mod is loaded, and follows a layout that is fairly complicated at first glance, but ultimately simple + +```json +{ + "Name" : "SimpleRandomiser", + "Description" : "SimpleRandomiser", + "Version": "0.1.0", + "LoadPriority": 1, +``` +The script above defines the pubic and listed details of the mod +```json + "Scripts": [ + { + "Path": "sh_SimpleRandomiser.gnut", + "RunOn": "MP", + "ClientCallback": { + "After": "simplerandomiser_init" + }, + + "ServerCallback": { + "After": "simplerandomiser_init" + } + } + ], +``` +The scirpt above defines both what functions to run, when to run them and WHERE to run them, in this case it runs your simplerandomiser_init, when on multiplayer and for both the server and the client +```json + "Localisation": [ + "resource/simplerandomiser_localisation_%language%.txt" + ] +} +``` +this defines the path to the language file + +name this file mod.json, and it should go in the mods root folder diff --git a/docs/modding/squirrel/setting-mods/the-language-file.md b/docs/modding/squirrel/setting-mods/the-language-file.md new file mode 100644 index 0000000..89adea8 --- /dev/null +++ b/docs/modding/squirrel/setting-mods/the-language-file.md @@ -0,0 +1,17 @@ +Language file +======= +This follows a fairly simple template, the only thing of note is that you often get strange behaviour using `utf-8` when saving the file instead of using `utf-16 le` + +``` +"lang" +{ + "Language" "english" + "Tokens" + { + "MODE_SETTING_CATEGORY_SIMPLERANDOMISER" "Simple Randomiser" + "SIMPLERANDOMISER" "Randomise" + } +} +``` + +Name this file simplerandomiser_localisation_english.txt and place it in the `yourmodsname/mod/resources/` folder diff --git a/docs/modding/squirrel/setting-mods/the-mod-file.md b/docs/modding/squirrel/setting-mods/the-mod-file.md new file mode 100644 index 0000000..069e3e2 --- /dev/null +++ b/docs/modding/squirrel/setting-mods/the-mod-file.md @@ -0,0 +1,96 @@ +Mod time +======== +lets actually get started then on making a setting mod, this will involve the making of 3 things for a simple one. a mod.json, a language file and the mod itself + +lets get started with the mod itself + +The mod +======= +to begin with we need to answer the simple question of "what are we making" for our example lets make a simple randomiser than randomises your weapon on each spawn. + +Because this is a setting mod it will only need to be installed on the serverside but it also wont appear in the browser unless the host puts it in the name. + +so lets get started with our **initial function** + +The initial function +--------- +The initial function is the function that is called on server startup and contains 2 important things. +the **callbacks** and the **setting buttons** to add the settings to the private match settings we need to use a new function: + +`AddPrivateMatchModeSettingEnum("string", "string", ["#SETTING_ENABLED", "#SETTING_ENABLED"], "0")` + +this might look complicated, but really its just (Category, settingname, [setting options], default value) however we use terms like "#MODE_SETTING_CATEGORY_RANDOMISER" in place of the category name so that we can create language files for different languages. +(we will make that later) +```cpp +void function simplerandomiser_init(){ + AddPrivateMatchModeSettingEnum("#MODE_SETTING_CATEGORY_SIMPLERANDOMISER", "SimpleRandomiser", ["#SETTING_ENABLED", "#SETTING_ENABLED"], "0") + + #if SERVER + AddCallback_OnPlayerRespawned(GiveRandomGun) + #endif + } + ``` +As you may have noticed, checking if it is a server is a special case, so we use #if SERVER and #endif instead of the usual if(thing){stuff} + +Now that our initial function is created we now have the game triggering `GiveRandomGun` on spawn, but we dont have any such function, so lets make one. but before we can do that, we need to know what weapons we can equip. +for this we define an array + +```cpp +array<string> pilotWeapons = [ + "mp_weapon_alternator_smg", + "mp_weapon_autopistol", + "mp_weapon_car", + "mp_weapon_dmr"] +``` +here we have defined an array with only 4 weapons in it, you can make this list as long or as short as you like but remember to seperate all but the last item with a , + +Now lets make a function to check if you enabled the setting +```cpp +bool +Next lets make the randomise function: + bool function SimpleRandomiserEnabled() + return GetCurrentPlaylistVarInt("SimpleRandomiser", 0) == 1 +``` + +Randomise function +---------------- +As we already know its going to call GiveRandomGun on respawn, lets define that now. + +First we strip any existing weapons: +```cpp +void function GiveRandomGun(entity player){ + foreach ( entity weapon in player.GetMainWeapons() ) + player.TakeWeaponNow( weapon.GetWeaponClassName() ) +``` +this iterates through each weapon and removes them individually. + +Then lets give them a new, random weapon by selecting a random item from our previous array: +```cpp + player.GiveWeapon(pilotweapons[RandomInt(pilotweapons.len())]) +``` +And done, surprisingly short script huh? +```cpp +void function simplerandomiser_init(){ + AddPrivateMatchModeSettingEnum("#MODE_SETTING_CATEGORY_SIMPLERANDOMISER", "SimpleRandomiser", ["#SETTING_ENABLED", "#SETTING_ENABLED"], "0") + + #if SERVER + AddCallback_OnPlayerRespawned(GiveRandomGun) + #endif + } + +array<string> pilotWeapons = [ + "mp_weapon_alternator_smg", + "mp_weapon_autopistol", + "mp_weapon_car", + "mp_weapon_dmr"] + +void function GiveRandomGun(entity player){ + foreach ( entity weapon in player.GetMainWeapons() ) + player.TakeWeaponNow( weapon.GetWeaponClassName() ) + player.GiveWeapon(pilotweapons[RandomInt(pilotweapons.len())]) +} +``` + +Alas **we arent done yet** We still need the **mod.json** and the **language file** + +Name this sh_SimpleRandomiser.gnut and place it in the `yourmodsname/mod/scripts/vscripts/` folder |