From 043e5696b73ca44eac69bc8d8bc8962c50fc5b79 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Wed, 22 Jun 2022 12:57:54 +0100 Subject: allow titan loadouts to be modified in script through callbacks (#316) --- .../mod/scripts/vscripts/_loadouts_mp.gnut | 45 ++++++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'Northstar.CustomServers/mod') diff --git a/Northstar.CustomServers/mod/scripts/vscripts/_loadouts_mp.gnut b/Northstar.CustomServers/mod/scripts/vscripts/_loadouts_mp.gnut index a31963cf..5359eac9 100644 --- a/Northstar.CustomServers/mod/scripts/vscripts/_loadouts_mp.gnut +++ b/Northstar.CustomServers/mod/scripts/vscripts/_loadouts_mp.gnut @@ -3,11 +3,24 @@ global function SvLoadoutsMP_Init global function SetLoadoutGracePeriodEnabled global function SetWeaponDropsEnabled + +global function AddCallback_OnTryGetTitanLoadout global function GetTitanLoadoutForPlayer +global struct sTryGetTitanLoadoutCallbackReturn +{ + bool wasChanged = false + bool runMoreCallbacks = true + TitanLoadoutDef& loadout +} + +typedef TryGetTitanLoadoutCallbackType sTryGetTitanLoadoutCallbackReturn functionref( entity player, TitanLoadoutDef loadout, bool wasChanged ) + struct { bool loadoutGracePeriodEnabled = true bool weaponDropsEnabled = true + array< TryGetTitanLoadoutCallbackType > onTryGetTitanLoadoutCallbacks + array dirtyLoadouts } file @@ -65,16 +78,40 @@ void function DelayDestroyDroppedWeapon( entity weapon ) weapon.Destroy() } +void function AddCallback_OnTryGetTitanLoadout( TryGetTitanLoadoutCallbackType callback ) +{ + file.onTryGetTitanLoadoutCallbacks.append( callback ) +} + TitanLoadoutDef function GetTitanLoadoutForPlayer( entity player ) { SetActiveTitanLoadout( player ) // set right loadout - + TitanLoadoutDef loadout = GetActiveTitanLoadout( player ) + // fix bug with titan weapons having null mods // null mods aren't valid and crash if we try to give them to npc - TitanLoadoutDef def = GetActiveTitanLoadout( player ) - def.primaryMods.removebyvalue( "null" ) + loadout.primaryMods.removebyvalue( "null" ) + + // allow scripts to modify loadouts + bool wasChanged = false + foreach ( TryGetTitanLoadoutCallbackType callback in file.onTryGetTitanLoadoutCallbacks ) + { + sTryGetTitanLoadoutCallbackReturn callbackRet = callback( player, loadout, wasChanged ) + + // whether the callback has changed the player's titan loadout + wasChanged = wasChanged || callbackRet.wasChanged + if ( wasChanged ) + loadout = callbackRet.loadout + + // whether the callback has indicated that we should run no more callbacks ( e.g. if we're forcing a given loadout to be chosen, we shouldn't run any more ) + if ( !callbackRet.runMoreCallbacks ) + break + } + + // do this again just in case + loadout.primaryMods.removebyvalue( "null" ) - return def + return loadout } void function LoadoutsMPInitPlayer( entity player ) -- cgit v1.2.3