From 9d346f8c96cbfad841c82eaefa437015c9bf4ce4 Mon Sep 17 00:00:00 2001 From: hummusbird Date: Fri, 14 Jan 2022 00:57:51 +0000 Subject: Add ns_force_melee cvar (#105) --- .../mod/scripts/vscripts/_force_melee.gnut | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Northstar.Custom/mod/scripts/vscripts/_force_melee.gnut (limited to 'Northstar.Custom/mod') diff --git a/Northstar.Custom/mod/scripts/vscripts/_force_melee.gnut b/Northstar.Custom/mod/scripts/vscripts/_force_melee.gnut new file mode 100644 index 00000000..cdc14fff --- /dev/null +++ b/Northstar.Custom/mod/scripts/vscripts/_force_melee.gnut @@ -0,0 +1,36 @@ +global function ForceMelee_Init + +struct { + string forcedMeleeWeapon +} file + +void function ForceMelee_Init() +{ + GetForcedMelee() + AddCallback_OnPlayerRespawned( ReplaceMelee ) + AddCallback_OnPlayerGetsNewPilotLoadout( ReplaceMeleeForLoadoutChange ) +} + +void function GetForcedMelee() +{ + string cvar = GetConVarString( "ns_force_melee" ) + if ( cvar == "" || cvar.len() == 0 ) + return + + file.forcedMeleeWeapon = cvar +} + +void function ReplaceMelee( entity player ) +{ + GetForcedMelee() + if ( file.forcedMeleeWeapon.len() == 0 ) + return + + player.TakeOffhandWeapon( 5 ) + player.GiveOffhandWeapon( file.forcedMeleeWeapon, OFFHAND_MELEE ) +} + +void function ReplaceMeleeForLoadoutChange( entity player, PilotLoadoutDef loadout ) +{ + ReplaceMelee( player ) +} \ No newline at end of file -- cgit v1.2.3