diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-11-07 03:53:07 +0000 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2021-11-07 03:53:07 +0000 |
commit | 35dfd937798d105238db23ea86f90f21be46694b (patch) | |
tree | d0e1ee639bc6177649dbcbde054f1e6094fc054c /Northstar.CustomServers/mod/scripts/vscripts/_xp.gnut | |
parent | e79a58640e1ef1ea1c3c954aefccd36c3cb55286 (diff) | |
download | NorthstarMods-35dfd937798d105238db23ea86f90f21be46694b.tar.gz NorthstarMods-35dfd937798d105238db23ea86f90f21be46694b.zip |
code cleanup, xp, postgame and some small changes
Diffstat (limited to 'Northstar.CustomServers/mod/scripts/vscripts/_xp.gnut')
-rw-r--r-- | Northstar.CustomServers/mod/scripts/vscripts/_xp.gnut | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/Northstar.CustomServers/mod/scripts/vscripts/_xp.gnut b/Northstar.CustomServers/mod/scripts/vscripts/_xp.gnut index 37b89169..150de8bb 100644 --- a/Northstar.CustomServers/mod/scripts/vscripts/_xp.gnut +++ b/Northstar.CustomServers/mod/scripts/vscripts/_xp.gnut @@ -1 +1,75 @@ -//fuck
\ No newline at end of file +global function SvXP_Init +global function PlayerProgressionAllowed +global function HandleXPGainForScoreEvent + +void function SvXP_Init() +{ + AddCallback_OnClientConnected( SetupPlayerPreviousXPValues ) +} + +void function SetupPlayerPreviousXPValues( entity player ) +{ + InitXP( player ) + + foreach ( string xpFaction in GetAllFactionRefs() ) + player.SetPersistentVar( "previousFactionXP[" + xpFaction + "]", FactionGetXP( player, xpFaction ) ) + + foreach ( string xpTitan in shTitanXP.titanClasses ) + player.SetPersistentVar( "previousTitanXP[" + xpTitan + "]", TitanGetXP( player, xpTitan ) ) + + foreach ( string xpWeapon in shWeaponXP.weaponClassNames ) + player.SetPersistentVar( GetItemPersistenceStruct( xpWeapon ) + ".previousWeaponXP", WeaponGetXP( player, xpWeapon ) ) +} + +bool function PlayerProgressionAllowed( entity player ) +{ + return true +} + +void function HandleXPGainForScoreEvent( entity player, ScoreEvent event ) +{ + // note: obviously all xp stuff can be cheated in if people want to on customs, this is mainly just here for fun for those who want it and feature completeness + // most score events don't have this, so we'll set this to the xp value of other categories later if needed + int xpValue = ScoreEvent_GetXPValue( event ) + + entity activeWeapon = player.GetActiveWeapon() + int weaponXp = ScoreEvent_GetXPValueWeapon( event ) + if ( weaponXp != 0 && ShouldTrackXPForWeapon( activeWeapon.GetWeaponClassName() ) ) + { + AddWeaponXP( player, ScoreEvent_GetXPValueWeapon( event ) ) + if ( xpValue < weaponXp ) + xpValue = weaponXp + } + + int titanXp = ScoreEvent_GetXPValueTitan( event ) + if ( titanXp != 0 && player.IsTitan() ) + { + AddTitanXP( player, ScoreEvent_GetXPValueTitan( event ) ) + if ( xpValue < titanXp ) + xpValue = titanXp + } + + // most events don't have faction xp but almost everything should give it + int factionXp = ScoreEvent_GetXPValueFaction( event ) + if ( xpValue > factionXp ) + factionXp = xpValue + else if ( xpValue < factionXp ) + xpValue = factionXp + + if ( factionXp != 0 ) + AddFactionXP( player, factionXp ) + + if ( xpValue == 0 ) + return + + // global xp + int oldXp = player.GetPersistentVarAsInt( "xp" ) + int oldLevel = GetLevelForXP( oldXp ) + player.SetPersistentVar( "xp", min( oldXp + xpValue, PlayerGetMaxXPPerGen() ) ) + player.XPChanged() // network xp change to client, gen can't change here + + int newXp = player.GetPersistentVarAsInt( "xp" ) + int newLevel = GetLevelForXP( newXp ) + if ( newLevel != oldLevel ) + Remote_CallFunction_NonReplay( player, "ServerCallback_PlayerLeveledUp", player.GetPersistentVarAsInt( "gen" ), newLevel ) +}
\ No newline at end of file |