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/gamemode-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/gamemode-mods')
-rw-r--r-- | docs/modding/squirrel/gamemode-mods/the-mod-init.md | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/docs/modding/squirrel/gamemode-mods/the-mod-init.md b/docs/modding/squirrel/gamemode-mods/the-mod-init.md new file mode 100644 index 0000000..2661429 --- /dev/null +++ b/docs/modding/squirrel/gamemode-mods/the-mod-init.md @@ -0,0 +1,136 @@ +Creating Gamemodes +================== +In this section we will be creating our custom gamemode. this is more complicated than creating setting mods however also allows for more freedom at the cost of being required clientside as well + +the gamemode itself +-------------- +We are going to make a simplified version of the "infection" gamemode. + +Lets break it down into steps before we make the gamemode itself + +1. Set the gamerules such as player count, team layout and score system +2. force all players on to 1 team at the start of the game +3. randomly select 1 player as being the zombie + - equip this player with the correct weapons + - modify their health + - provide them a speedboost +4. have players become zombies on death +5. have players joining mid way become zombies +6. end the game when the last player dies. + +Now lets breakdown the callbacks we will need + +for steps 2 and 5 we will need `AddCallback_OnClientConnected( PlayerJoined )` to trigger on join + +for step 3 we will need to `AddCallback_GameStateEnter( eGameState.Playing, StartGame )` + +for step 4 we need `AddCallback_OnPlayerRespawned( RespawnInfected )` + +and finally to decide the winner we need a new function we havent seen yet. `SetTimeoutWinnerDecisionFunc( DecideWinners )` + +this function is used to decide the winner when the game runs out of time by calling a function. + +now that we know our steps its time to start our initialisation function + +Initialisation function +-------------------- +first, lets declare our game settings +```cpp +global function SimpleInfection_init +void function SimpleInfection_init(){ + SetSpawnpoint GamemodeOverrde( FFA )// This line makes the player spawn locations like those from ffa + SetLoadoutGracePeriodEnabled( false )// we dont want the zombies to be able to change loadouts and grab their guns, so lets disable that + SetWeaponDropsEnabled(false )// we dont want zombies grabbing the weapons for dead survivors, so lets disable that. + Riff_ForceTitanAvailability( eTitanAvailability.Never )// we dont want zombies to have titans either, so lets disable that + Riff_ForceBoostAvailability( eBoostAvailability.Disabled )// we also dont want the zombies grabbing smart pistols and turrets, so lets disable that + ClassMP_ForceDisableEpilogue( true )// As the goal is surviving till the timer runs out, we dont need the evac dropship +``` +Next lets setup our callbacks: +```cpp + AddCallback_OnClientConnected( PlayerJoined ) + AddCallback_GameStateEnter( eGameState.Playing, StartGame ) + AddCallback_OnPlayerRespawned( RespawnInfected ) + SetTimeoutWinnerDecisionFunc( DecideWinners ) +} +``` +great, now we have our gamemodes initialisation function we need a way for our callbacks to know some things, such as whether the game has started or not, you will see why later +```cpp +struct { + bool HasStarted = false +} file +``` +Structs like this allow us to store Values that can be accessed elsewhere in the script, without having to pass them as arguments in all our functions. we place them in a struct instead of just defining them as a global variable cannot +be modified by a function in squirrel, wheras a struct like this one can. + +to access a variable in a struct you must format it using the name of the stuct followed by the variable itself, in this case `file.HasStarted` + +Main functions +--------- +Now it time to start writing our callbacks +```cpp +void function PlayerJoined(entity player){ + if (file.HasStarted){ + InfectPlayer( player, player) + RespawnInfected( player ) + } + else{ + SetTeam( player, 0) + } +} +``` +This manages what happens when a player joins, but it calls a function we dont have yet `InfectPlayer` so lets define it now +```cpp +void function InfectPlayer(entity player, entity attacker){ + SetTeam( player, 1) + if ((GetPlayerArrayOfteam(0).len()) == 0){ + SetRespawnsEnabled(false) + SetKillcamsEnabled(false) + SetWinner( 1 ) + } +} +``` +This function simply changes the players team, then checks if there are any survivors left, and if not sets the zombies as the winners. + +Now for the script that chooses the first zombie, in order to allow more time for players to join lets put a delay on it using a `thread` +```cpp +void function StartGame(){ + firstinfected = GetPlayerArray()[RandomInt(GetPlayerArray().len())] + InfectPlayer( firstinfected, firstinfected) + file.HasStarted = true +} +``` +This function changes the file.HasStarted value to true and randomly selects a player from the player array as a target for the infectplayer function. + +Next lets create the function that provides the zombies the correct equipment +```cpp +void function RespawnInfected( entity player ){ + if (player.GetTeam() != 1){//this makes sure players dont accidentally get given zombie weapons when first spawning as a survivor + return + } + //lets give them stim, followed by increased air accel + StimPlayer( player, 9999) + player.kv.airAcceleration = 2000 + //lets give them less health than normal + payer.SetMaxHealth(20) + //lets set their loadout + foreach ( entity weapon in player.GetMainWeapons() ) + player.TakeWeaponNow( weapon.GetWeaponClassName() ) + + foreach ( entity weapon in player.GetOffhandWeapons() ) + player.TakeWeaponNow( weapon.GetWeaponClassName() ) + + player.GiveOffhandWeapon( "melee_pilot_emptyhanded", OFFHAND_MELEE ) + //unfortunately the game requires that you have a weapon of some kind in order to use secondaries, so lets give zombies an MGL + player.GiveWeapon( "mp_weapon_mgl" ) +} +``` +Finally lets define what occurs when the match ends +```cpp +void function DecideWinners(){ + SetRespawnsEnabled( false ) + SetKillcamsEnabled( false ) + return 0 +} +``` +Now we can save this file as _gamemode_simpleinf.gnut and place it in +`"ourmodsname"/mod/scripts/vscripts/gamemodes` |