#include "scripts/common.txt"
#include "scripts/BP_common.txt"

//(3) Max Regenerations -32768..32767 (Trigger Script ID when not 0)

class BP_EventLink : ScriptObject
{
    kActor @self;
	bool isActivated;
	//------------------------------------------------------------------------------------------------------------------------
    BP_EventLink(kActor @actor)
	{
        @self = actor;
		isActivated = false;
		self.Flags() &= ~AF_SOLID;
    }
	//------------------------------------------------------------------------------------------------------------------------
	void OnActivate()
	{
		self.MarkPersistentBit(false);
		int triggerTID = self.SpawnParams(3);
		if (triggerTID != 0)
		{
			Game.CallDelayedMapScript(triggerTID, self, 0);
		}
	}
	//------------------------------------------------------------------------------------------------------------------------
    void OnRestore()
    {
		isActivated = true;
    }
	//------------------------------------------------------------------------------------------------------------------------
    void OnTick() {}
	//------------------------------------------------------------------------------------------------------------------------
    void OnSpawn() {}
	//------------------------------------------------------------------------------------------------------------------------
	void OnPostBeginLevel()
	{
		if (isActivated)
		{
			int triggerTID = self.SpawnParams(3);
			if (triggerTID == 0)
			{
				World.TriggerActorsByTID(self, self.TID());
			}
			else
			{
				Game.CallDelayedMapScript(triggerTID, self, 0);
			}
			self.Remove();
		}
	}
	//------------------------------------------------------------------------------------------------------------------------
}
