aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/scripts/vscripts/_powerup.gnut
blob: 40984d0dba5af2d17dd80d981bfd4d237b0eb80f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
}