aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/scripts/vscripts/_powerup.gnut
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-06-22 14:30:49 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-06-22 14:30:49 +0100
commit207facbc402f5639cbcd31f079214351ef605cf2 (patch)
tree4710b2a88dd64f3dfea1609d31a5de9141640951 /Northstar.CustomServers/scripts/vscripts/_powerup.gnut
parentc2d438568df6d98cf731807e30eaa7da31e5ea52 (diff)
downloadNorthstarMods-207facbc402f5639cbcd31f079214351ef605cf2.tar.gz
NorthstarMods-207facbc402f5639cbcd31f079214351ef605cf2.zip
initial commit after moving to new repo
Diffstat (limited to 'Northstar.CustomServers/scripts/vscripts/_powerup.gnut')
-rw-r--r--Northstar.CustomServers/scripts/vscripts/_powerup.gnut102
1 files changed, 102 insertions, 0 deletions
diff --git a/Northstar.CustomServers/scripts/vscripts/_powerup.gnut b/Northstar.CustomServers/scripts/vscripts/_powerup.gnut
new file mode 100644
index 00000000..40984d0d
--- /dev/null
+++ b/Northstar.CustomServers/scripts/vscripts/_powerup.gnut
@@ -0,0 +1,102 @@
+untyped
+global function PowerUps_Init
+
+void function PowerUps_Init()
+{
+ SH_PowerUp_Init()
+
+ AddCallback_EntitiesDidLoad( EntitesDidLoad )
+}
+
+void function EntitesDidLoad()
+{
+ array<entity> scriptRefs = GetEntArrayByClass_Expensive( "script_ref" )
+ foreach ( entity ref in scriptRefs )
+ if ( ref.HasKey( "powerUpType" ) )
+ {
+ PowerUp powerup = GetPowerUpFromItemRef( expect string( ref.kv.powerUpType ) )
+
+ // CreatePickup is defined in mp/_pickups.gnut
+ // mp/_pickups.gnut is a sp-only script
+ // it's literally in the mp folder
+ // respawn PLEASE
+ //CreatePickup( ref, powerup.model, bool function( entity player ) { powerup.destroyFunc( player ); return true } )
+
+ if ( powerup.spawnFunc() )
+ {
+ CreatePropDynamic( powerup.baseModel, ref.GetOrigin(), ref.GetAngles(), 2 )
+ thread PowerUpThink( ref, powerup )
+ }
+ }
+
+ AddCallback_OnTouchHealthKit( "item_powerup", OnPowerUpCollected )
+}
+
+entity function CreatePowerUp( entity spawnpoint, PowerUp powerup )
+{
+ entity powerupEnt = CreateEntity( "item_powerup" )
+
+ powerupEnt.SetValueForModelKey( powerup.model )
+ powerupEnt.kv.fadedist = 10000
+ powerupEnt.kv.gravity = 0.000001 // really hacky, but gravity 0.0 is considered the same as 1.0, and i'm not sure how to enable/disable gravity on entities in script
+
+ DispatchSpawn( powerupEnt )
+
+ powerupEnt.SetModel( powerup.model )
+ powerupEnt.SetOrigin( spawnpoint.GetOrigin() + powerup.modelOffset )
+ powerupEnt.SetAngles( spawnpoint.GetAngles() + powerup.modelAngles )
+
+ powerupEnt.s.powerUpType <- powerup.itemRef
+
+ return powerupEnt
+}
+
+void function PowerUpThink( entity spawnpoint, PowerUp powerup )
+{
+ svGlobal.levelEnt.EndSignal( "RoundEnd" ) // should reset on round end
+
+ entity powerupEnt
+
+ while ( true )
+ {
+ powerupEnt = CreatePowerUp( spawnpoint, powerup )
+
+ OnThreadEnd( function() : ( powerupEnt, spawnpoint, powerup )
+ {
+ // should be called on round end
+ print( "resetting powerup..." )
+ if ( IsValid( powerupEnt ) )
+ powerupEnt.Destroy()
+
+ // recursively spawn new powerup
+ thread PowerUpThink( spawnpoint, powerup )
+ }
+ )
+
+ // handle the glow here so we can destroy it
+ PickupGlow glow = CreatePickupGlow( powerupEnt, powerup.glowColor.x.tointeger(), powerup.glowColor.y.tointeger(), powerup.glowColor.z.tointeger() )
+ glow.glowFX.SetOrigin( spawnpoint.GetOrigin() ) // want the glow to be parented to the powerup, but have the position of the spawnpoint
+
+ powerupEnt.WaitSignal( "OnDestroy" )
+
+ wait powerup.respawnDelay
+ }
+}
+
+bool function OnPowerUpCollected( entity player, entity healthpack )
+{
+ PowerUp powerup = GetPowerUpFromItemRef( expect string( healthpack.s.powerUpType ) )
+
+ 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 ) && PlayerHasBattery( player ) )
+ return false
+
+ powerup.destroyFunc( player )
+ return true // destroys the powerup
+ }
+
+ return false // keeps powerup alive
+} \ No newline at end of file