Skip to content

Commit

Permalink
Release 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JMM889901 committed Aug 27, 2022
1 parent 50b7e41 commit 57571f2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 564 deletions.
51 changes: 42 additions & 9 deletions mod/scripts/vscripts/_loadouts_mp.gnut
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -65,20 +78,40 @@ void function DelayDestroyDroppedWeapon( entity weapon )
weapon.Destroy()
}

void function AddCallback_OnTryGetTitanLoadout( TryGetTitanLoadoutCallbackType callback )
{
file.onTryGetTitanLoadoutCallbacks.append( callback )
}

TitanLoadoutDef function GetTitanLoadoutForPlayer( entity player )
{
//print("SetActiveTitanloadout")
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
//print("GetActiveTitanLoadout")
TitanLoadoutDef def = GetActiveTitanLoadout( player )
def.primaryMods.removebyvalue( "null" )
//print("//////////GET TITAN LOADOUT FOR PLAYER///////////")
//PrintTitanLoadout(def)
//print("//////////FINISHED TITAN LOADOOUT FOR PLAYER////")
return def
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 ( callbackRet.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 loadout
}

void function LoadoutsMPInitPlayer( entity player )
Expand Down
Loading

0 comments on commit 57571f2

Please sign in to comment.