From 9a96d0bff56f1969c68bb52a2f33296095bdc67d Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Tue, 31 Aug 2021 23:14:58 +0100 Subject: move to new mod format --- .../mod/scripts/vscripts/_powerup.gnut | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Northstar.CustomServers/mod/scripts/vscripts/_powerup.gnut (limited to 'Northstar.CustomServers/mod/scripts/vscripts/_powerup.gnut') diff --git a/Northstar.CustomServers/mod/scripts/vscripts/_powerup.gnut b/Northstar.CustomServers/mod/scripts/vscripts/_powerup.gnut new file mode 100644 index 000000000..03b9fcfc7 --- /dev/null +++ b/Northstar.CustomServers/mod/scripts/vscripts/_powerup.gnut @@ -0,0 +1,93 @@ +untyped +global function PowerUps_Init + +struct { + array powerupSpawns +} file + +void function PowerUps_Init() +{ + SH_PowerUp_Init() + + AddSpawnCallbackEditorClass( "script_ref", "script_power_up_other", AddPowerupSpawn ) + AddCallback_OnTouchHealthKit( "item_powerup", OnPowerupCollected ) + AddCallback_GameStateEnter( eGameState.Prematch, RespawnPowerups ) +} + +void function AddPowerupSpawn( entity spawnpoint ) +{ + file.powerupSpawns.append( spawnpoint ) +} + +void function RespawnPowerups() +{ + foreach ( entity spawnpoint in file.powerupSpawns ) + { + PowerUp powerupDef = GetPowerUpFromItemRef( expect string( spawnpoint.kv.powerUpType ) ) + thread PowerupSpawnerThink( spawnpoint, powerupDef ) + } +} + +void function PowerupSpawnerThink( entity spawnpoint, PowerUp powerupDef ) +{ + svGlobal.levelEnt.EndSignal( "CleanUpEntitiesForRoundEnd" ) + + entity base = CreatePropDynamic( powerupDef.baseModel, spawnpoint.GetOrigin(), spawnpoint.GetAngles(), 2 ) + OnThreadEnd( function() : ( base ) + { + base.Destroy() + }) + + while ( true ) + { + if ( !powerupDef.spawnFunc() ) + return + + entity powerup = CreateEntity( "item_powerup" ) + + powerup.SetOrigin( base.GetOrigin() + powerupDef.modelOffset ) + powerup.SetAngles( base.GetAngles() + powerupDef.modelAngles ) + powerup.SetValueForModelKey( powerupDef.model ) + + DispatchSpawn( powerup ) + + // unless i'm doing something really dumb, this all has to be done after dispatchspawn to get the powerup to not have gravity + powerup.StopPhysics() + powerup.SetOrigin( base.GetOrigin() + powerupDef.modelOffset ) + powerup.SetAngles( base.GetAngles() + powerupDef.modelAngles ) + + powerup.SetModel( powerupDef.model ) + powerup.s.powerupRef <- powerupDef.itemRef + + PickupGlow glow = CreatePickupGlow( powerup, powerupDef.glowColor.x.tointeger(), powerupDef.glowColor.y.tointeger(), powerupDef.glowColor.z.tointeger() ) + glow.glowFX.SetOrigin( spawnpoint.GetOrigin() ) // want the glow to be parented to the powerup, but have the position of the spawnpoint + + OnThreadEnd( function() : ( powerup ) + { + if ( IsValid( powerup ) ) + powerup.Destroy() + }) + + powerup.WaitSignal( "OnDestroy" ) + wait powerupDef.respawnDelay + } +} + +bool function OnPowerupCollected( entity player, entity healthpack ) +{ + PowerUp powerup = GetPowerUpFromItemRef( expect string( healthpack.s.powerupRef ) ) + + if ( player.IsTitan() == powerup.titanPickup ) + { + // hack because i couldn't figure out any other way to do this without modifying sh_powerup + // ensure we don't kill the powerup if it's a battery the player can't pickup + if ( ( powerup.index == ePowerUps.titanTimeReduction || powerup.index == ePowerUps.LTS_TitanTimeReduction ) && ( player.IsTitan() || PlayerHasMaxBatteryCount( player ) ) ) + return false + + // idk why the powerup.destroyFunc doesn't just return a bool? would mean they could just handle stuff like this in powerup code + powerup.destroyFunc( player ) + return true // destroys the powerup + } + + return false // keeps powerup alive +} \ No newline at end of file -- cgit v1.2.3