From e79a58640e1ef1ea1c3c954aefccd36c3cb55286 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Wed, 20 Oct 2021 20:11:43 +0100 Subject: automatic mod enable/disable, refactors and item registration callbacks --- .../scripts/vscripts/gamemodes/_gamemode_gg.gnut | 4 ++ .../scripts/vscripts/gamemodes/_gamemode_sbox.gnut | 49 --------------- .../scripts/vscripts/gamemodes/_riff_instagib.gnut | 65 ------------------- .../vscripts/gamemodes/sh_gamemode_sbox.gnut | 20 ------ .../vscripts/gamemodes/sh_riff_instagib.gnut | 73 ++++++++++++++++++++++ 5 files changed, 77 insertions(+), 134 deletions(-) delete mode 100644 Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_sbox.gnut delete mode 100644 Northstar.Custom/mod/scripts/vscripts/gamemodes/_riff_instagib.gnut delete mode 100644 Northstar.Custom/mod/scripts/vscripts/gamemodes/sh_gamemode_sbox.gnut create mode 100644 Northstar.Custom/mod/scripts/vscripts/gamemodes/sh_riff_instagib.gnut (limited to 'Northstar.Custom/mod/scripts/vscripts/gamemodes') diff --git a/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_gg.gnut b/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_gg.gnut index e01780347..8c68f5543 100644 --- a/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_gg.gnut +++ b/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_gg.gnut @@ -15,6 +15,10 @@ void function GamemodeGG_Init() AddCallback_OnPlayerKilled( OnPlayerKilled ) AddCallback_GameStateEnter( eGameState.WinnerDetermined, OnWinnerDetermined ) + + // set scorelimit if it's wrongm sort of a jank way to do it but best i've got rn + if ( GetCurrentPlaylistVarInt( "scorelimit", GetGunGameWeapons().len() ) != GetGunGameWeapons().len() ) + SetPlaylistVarOverride( "scorelimit", GetGunGameWeapons().len().tostring() ) } void function OnPlayerRespawned( entity player ) diff --git a/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_sbox.gnut b/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_sbox.gnut deleted file mode 100644 index 27581aeac..000000000 --- a/Northstar.Custom/mod/scripts/vscripts/gamemodes/_gamemode_sbox.gnut +++ /dev/null @@ -1,49 +0,0 @@ -untyped -global function GamemodeSbox_Init - -struct { - array spawnpoints -} file - -void function GamemodeSbox_Init() -{ - SetConVarInt( "sv_cheats", 1 ) // cheats on by default - - // cache spawnpoints - //file.spawnpoints = GetEntArrayByClass_Expensive( "info_spawnpoint_human" ) - // todo just use a spawn callback for this rather than weird late cache in spawn - - AddCallback_OnClientConnected( SboxSpawnPlayer ) - AddDeathCallback( "player", SboxRespawnPlayer ) -} - -void function SboxSpawnPlayer( entity player ) -{ - if ( player.GetPlayerSettings() == "spectator" ) // if they haven't spawned yet - player.SetPlayerSettings( "pilot_grapple_male" ) - - if ( file.spawnpoints.len() == 0 ) // have to cache late rather than on init due to spawnpoints not existing in init - file.spawnpoints = GetEntArrayByClass_Expensive( "info_spawnpoint_human" ) - - if ( GetGameState() != eGameState.Playing ) // hacky but can't set this in init either - SetGameState( eGameState.Playing ) - - entity spawnpoint = file.spawnpoints[ RandomInt( file.spawnpoints.len() ) ] - - ScreenFadeFromBlack( player, 0.0, 0.0 ) // HACK before non-classicmp intros are ready, remove the blackscreen we get from waitingforplayers - player.RespawnPlayer( spawnpoint ) - player.GiveWeapon( "mp_weapon_toolgun" ) -} - -void function SboxRespawnPlayer( entity player, var damageInfo ) -{ - thread SboxRespawnPlayerThreaded( player ) -} - -void function SboxRespawnPlayerThreaded( entity player ) -{ - // todo: replace this with real respawn logic when that's ready - - wait 2.5 - SboxSpawnPlayer( player ) -} \ No newline at end of file diff --git a/Northstar.Custom/mod/scripts/vscripts/gamemodes/_riff_instagib.gnut b/Northstar.Custom/mod/scripts/vscripts/gamemodes/_riff_instagib.gnut deleted file mode 100644 index b3868359e..000000000 --- a/Northstar.Custom/mod/scripts/vscripts/gamemodes/_riff_instagib.gnut +++ /dev/null @@ -1,65 +0,0 @@ -global function RiffInstagib_Init - -struct { - table playerWeapons - array instagibWeapons -} file - -void function RiffInstagib_Init() -{ - if ( GetCurrentPlaylistVarInt( "riff_instagib", 0 ) == 0 ) - return - - SetLoadoutGracePeriodEnabled( false ) - SetWeaponDropsEnabled( false ) - - file.instagibWeapons = [ - "mp_weapon_sniper", - "mp_weapon_wingman", - "mp_weapon_defender", - "mp_weapon_arena3", - "mp_weapon_wingman_n", - "mp_weapon_doubletake", - ] - file.instagibWeapons.randomize() - - AddCallback_OnPlayerRespawned( InstagibSetWeapons ) - AddCallback_OnPlayerKilled( InstagibCycleWeaponsForKill ) - AddCallback_OnClientDisconnected( InstagibCleanupClient ) -} - -void function InstagibSetWeapons( entity player ) -{ - if ( !( player in file.playerWeapons ) ) - file.playerWeapons[ player ] <- 0 - - player.SetMaxHealth( 1 ) - InstagibUpdateWeapons( player ) -} - -void function InstagibUpdateWeapons( entity player ) -{ - foreach( entity weapon in player.GetMainWeapons() ) - player.TakeWeaponNow( weapon.GetWeaponClassName() ) - - player.TakeWeaponNow( player.GetOffhandWeapon( OFFHAND_RIGHT ).GetWeaponClassName() ) - if ( !HasOffhandWeapon( player, "mp_weapon_grenade_sonar" ) ) - player.GiveOffhandWeapon( "mp_weapon_grenade_sonar", OFFHAND_RIGHT ) - - player.GiveWeapon( file.instagibWeapons[ file.playerWeapons[ player ] ] ) -} - -void function InstagibCycleWeaponsForKill( entity victim, entity attacker, var damageInfo ) -{ - if ( !victim.IsPlayer() || !attacker.IsPlayer() || victim == attacker ) - return - - file.playerWeapons[ attacker ] = ( file.playerWeapons[ attacker ] + 1 ) % file.instagibWeapons.len() - InstagibUpdateWeapons( attacker ) -} - -void function InstagibCleanupClient( entity player ) -{ - if ( player in file.playerWeapons ) - delete file.playerWeapons[ player ] -} \ No newline at end of file diff --git a/Northstar.Custom/mod/scripts/vscripts/gamemodes/sh_gamemode_sbox.gnut b/Northstar.Custom/mod/scripts/vscripts/gamemodes/sh_gamemode_sbox.gnut deleted file mode 100644 index 893d94108..000000000 --- a/Northstar.Custom/mod/scripts/vscripts/gamemodes/sh_gamemode_sbox.gnut +++ /dev/null @@ -1,20 +0,0 @@ -global function Sh_GamemodeSbox_Init - -global const string GAMEMODE_SBOX = "sbox" - -void function Sh_GamemodeSbox_Init() -{ - // create custom gametype - AddCallback_OnCustomGamemodesInit( CreateGamemodeSbox ) -} - -void function CreateGamemodeSbox() -{ - GameMode_Create( GAMEMODE_SBOX ) - GameMode_SetName( GAMEMODE_SBOX, "#PL_sbox" ) - GameMode_SetDesc( GAMEMODE_SBOX, "#PL_sbox_desc" ) - - #if SERVER - GameMode_AddServerInit( GAMEMODE_SBOX, GamemodeSbox_Init ) - #endif -} \ No newline at end of file diff --git a/Northstar.Custom/mod/scripts/vscripts/gamemodes/sh_riff_instagib.gnut b/Northstar.Custom/mod/scripts/vscripts/gamemodes/sh_riff_instagib.gnut new file mode 100644 index 000000000..316893bb4 --- /dev/null +++ b/Northstar.Custom/mod/scripts/vscripts/gamemodes/sh_riff_instagib.gnut @@ -0,0 +1,73 @@ +global function RiffInstagib_Init + +#if SERVER +struct { + table playerWeapons + array instagibWeapons +} file +#endif + +void function RiffInstagib_Init() +{ + AddPrivateMatchModeSettingEnum( "#MODE_SETTING_CATEGORY_RIFF", "riff_instagib", [ "Disabled", "Enabled" ], "0" ) + + #if SERVER + if ( GetCurrentPlaylistVarInt( "riff_instagib", 0 ) == 0 ) + return + + SetLoadoutGracePeriodEnabled( false ) + SetWeaponDropsEnabled( false ) + + file.instagibWeapons = [ + "mp_weapon_sniper", + "mp_weapon_wingman", + "mp_weapon_defender", + "mp_weapon_arena3", + "mp_weapon_wingman_n", + "mp_weapon_doubletake", + ] + file.instagibWeapons.randomize() + + AddCallback_OnPlayerRespawned( InstagibSetWeapons ) + AddCallback_OnPlayerKilled( InstagibCycleWeaponsForKill ) + AddCallback_OnClientDisconnected( InstagibCleanupClient ) + #endif +} + +#if SERVER +void function InstagibSetWeapons( entity player ) +{ + if ( !( player in file.playerWeapons ) ) + file.playerWeapons[ player ] <- 0 + + player.SetMaxHealth( 1 ) + InstagibUpdateWeapons( player ) +} + +void function InstagibUpdateWeapons( entity player ) +{ + foreach( entity weapon in player.GetMainWeapons() ) + player.TakeWeaponNow( weapon.GetWeaponClassName() ) + + player.TakeWeaponNow( player.GetOffhandWeapon( OFFHAND_RIGHT ).GetWeaponClassName() ) + if ( !HasOffhandWeapon( player, "mp_weapon_grenade_sonar" ) ) + player.GiveOffhandWeapon( "mp_weapon_grenade_sonar", OFFHAND_RIGHT ) + + player.GiveWeapon( file.instagibWeapons[ file.playerWeapons[ player ] ] ) +} + +void function InstagibCycleWeaponsForKill( entity victim, entity attacker, var damageInfo ) +{ + if ( !victim.IsPlayer() || !attacker.IsPlayer() || victim == attacker ) + return + + file.playerWeapons[ attacker ] = ( file.playerWeapons[ attacker ] + 1 ) % file.instagibWeapons.len() + InstagibUpdateWeapons( attacker ) +} + +void function InstagibCleanupClient( entity player ) +{ + if ( player in file.playerWeapons ) + delete file.playerWeapons[ player ] +} +#endif \ No newline at end of file -- cgit v1.2.3