ScriptName RenGlueMissileArmorScript extends ObjectReference

import utility

float Property waitBetweenPicks = 0.5 Auto
{ Update time..keep as low as possible }

Actor Property myactor Auto

const int playTimerID = 10

float starttime = 0

float x_impulse
float y_impulse
float z_impulse
float mag_impulse

Function OnTimer(int aiTimerID)
	If (aiTimerID == playTimerID)
	
		if myactor == none
			return
		endif	
	
		Game.GetPlayer().PushActorAway(myactor, 1.0)
		myactor.ApplyHavokImpulse(x_impulse, y_impulse, z_impulse, mag_impulse)	
	
		x_impulse += RandomFloat(-0.1, 0.1)
		y_impulse += RandomFloat(-0.1, 0.1)
		z_impulse += RandomFloat(-0.01, 0.01)
		;mag_impulse += (RandomFloat(-1.0, 1.0) * 100)
	
		if ((Utility.GetCurrentRealTime() - starttime) <= 10)
			Self.StartTimer(waitBetweenPicks, playTimerID)
		else
			Self.CancelTimer(playTimerID)
			if (myactor.IsDead() == false)
				(myactor As ObjectReference).ForceRemoveRagdollFromWorld()			
			endif
			myactor.RemoveItem(Self.GetBaseObject(), 1, true, none)
		endif
	EndIf
EndFunction

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
		myactor = akNewContainer As Actor

		if myactor == none
			return
		endif
		
		x_impulse = RandomFloat(-0.5, 0.5)
		y_impulse = RandomFloat(-0.5, 0.5)
		z_impulse = RandomFloat(0.1, 0.2)
		mag_impulse = 2000

		starttime = Utility.GetCurrentRealTime()
		
		Self.StartTimer(waitBetweenPicks, playTimerID)
endEvent