diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2022-06-22 12:57:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-22 12:57:54 +0100 |
commit | 043e5696b73ca44eac69bc8d8bc8962c50fc5b79 (patch) | |
tree | be23f397d4219a7101fc0633353b1f89645b8597 /Northstar.CustomServers | |
parent | 0300ff5b4fb1d36b130daf44bef635f5697bca94 (diff) | |
download | NorthstarMods-043e5696b73ca44eac69bc8d8bc8962c50fc5b79.tar.gz NorthstarMods-043e5696b73ca44eac69bc8d8bc8962c50fc5b79.zip |
allow titan loadouts to be modified in script through callbacks (#316)
Diffstat (limited to 'Northstar.CustomServers')
-rw-r--r-- | Northstar.CustomServers/mod/scripts/vscripts/_loadouts_mp.gnut | 45 |
1 files changed, 41 insertions, 4 deletions
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<entity> 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 ) |