aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/scripts/vscripts/_powerup.gnut
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-06-23 05:06:17 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-06-23 05:06:17 +0100
commit8d4c71f7779120298773c9232dcdaa0fa0063786 (patch)
treeba87b4e511de66161faabd7ba8ffa3efcab08974 /Northstar.CustomServers/scripts/vscripts/_powerup.gnut
parent207facbc402f5639cbcd31f079214351ef605cf2 (diff)
downloadNorthstarMods-8d4c71f7779120298773c9232dcdaa0fa0063786.tar.gz
NorthstarMods-8d4c71f7779120298773c9232dcdaa0fa0063786.zip
lts and powerup rewrite, more gamestate changes
Diffstat (limited to 'Northstar.CustomServers/scripts/vscripts/_powerup.gnut')
-rw-r--r--Northstar.CustomServers/scripts/vscripts/_powerup.gnut119
1 files changed, 56 insertions, 63 deletions
diff --git a/Northstar.CustomServers/scripts/vscripts/_powerup.gnut b/Northstar.CustomServers/scripts/vscripts/_powerup.gnut
index 40984d0d..a154ddb6 100644
--- a/Northstar.CustomServers/scripts/vscripts/_powerup.gnut
+++ b/Northstar.CustomServers/scripts/vscripts/_powerup.gnut
@@ -1,91 +1,84 @@
untyped
global function PowerUps_Init
+struct {
+ array<entity> powerupSpawns
+} file
+
void function PowerUps_Init()
{
- SH_PowerUp_Init()
-
- AddCallback_EntitiesDidLoad( EntitesDidLoad )
+ SH_PowerUp_Init()
+
+ AddSpawnCallbackEditorClass( "script_ref", "script_power_up_other", AddPowerupSpawn )
+ AddCallback_OnTouchHealthKit( "item_powerup", OnPowerupCollected )
}
-void function EntitesDidLoad()
+void function AddPowerupSpawn( entity spawnpoint )
{
- 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 )
+ file.powerupSpawns.append( spawnpoint )
}
-entity function CreatePowerUp( entity spawnpoint, PowerUp powerup )
+void function RespawnPowerups()
{
- 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
+ foreach ( entity spawnpoint in file.powerupSpawns )
+ {
+ PowerUp powerupDef = GetPowerUpFromItemRef( expect string( spawnpoint.kv.powerUpType ) )
+ thread PowerupSpawnerThink( spawnpoint, powerupDef )
+ }
}
-void function PowerUpThink( entity spawnpoint, PowerUp powerup )
+void function PowerupSpawnerThink( entity spawnpoint, PowerUp powerupDef )
{
- svGlobal.levelEnt.EndSignal( "RoundEnd" ) // should reset on round end
+ svGlobal.levelEnt.EndSignal( "CleanUpEntitiesForRoundEnd" )
- entity powerupEnt
+ entity base = CreatePropDynamic( powerupDef.baseModel, spawnpoint.GetOrigin(), spawnpoint.GetAngles(), 2 )
+ OnThreadEnd( function() : ( base )
+ {
+ base.Destroy()
+ })
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() )
+ if ( !powerupDef.spawnFunc() )
+ {
+ // unsure if this is the best way of doing it
+ WaitFrame()
+ continue
+ }
+
+ entity powerup = CreateEntity( "item_powerup" )
+
+ powerup.SetParent( base ) // parenting ensures that gravity isn't an issue
+ powerup.SetValueForModelKey( powerupDef.model )
+
+ DispatchSpawn( powerup )
+
+ // offset from parent's position/angles
+ powerup.SetOrigin( powerupDef.modelOffset )
+ powerup.SetAngles( 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
- powerupEnt.WaitSignal( "OnDestroy" )
+ OnThreadEnd( function() : ( powerup )
+ {
+ if ( IsValid( powerup ) )
+ {
+ powerup.Destroy()
+ }
+ })
- wait powerup.respawnDelay
+ powerup.WaitSignal( "OnDestroy" )
+ wait powerupDef.respawnDelay
}
}
-bool function OnPowerUpCollected( entity player, entity healthpack )
+bool function OnPowerupCollected( entity player, entity healthpack )
{
- PowerUp powerup = GetPowerUpFromItemRef( expect string( healthpack.s.powerUpType ) )
+ PowerUp powerup = GetPowerUpFromItemRef( expect string( healthpack.s.powerupRef ) )
if ( player.IsTitan() == powerup.titanPickup )
{