mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
72 lines
2.1 KiB
Plaintext
72 lines
2.1 KiB
Plaintext
/**********************************************************************
|
|
|
|
*
|
|
* Title: quest_creature
|
|
* Description: Script that attaches to any creature spawned via the quest
|
|
* spawner
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
const string VAR_SPAWNER_CURRENT_POPULATION = "quest_spawner.current_pop";
|
|
const string VAR_SPAWNED_BY = "quest_spawner.spawned_by";
|
|
|
|
/***** TRIGGERS ********************************************************/
|
|
trigger OnIncapacitated(obj_id attacker)
|
|
{
|
|
LOG("quests", "quest_creature.OnIncapacitated(" + self + ", " + attacker + ") - notifying spawner");
|
|
notifySpawner();
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnDestroy()
|
|
{
|
|
LOG("quests", "quest_creature.OnDestroy(" + self + ") - notifying spawner");
|
|
if(! isIncapacitated(self))
|
|
notifySpawner();
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** MESSAGEHANDLERS *************************************************/
|
|
|
|
|
|
/***** COMMANDHANDLERS *************************************************/
|
|
|
|
|
|
/***** FUNCTIONS *******************************************************/
|
|
|
|
void notifySpawner()
|
|
{
|
|
obj_id self = getSelf();
|
|
obj_id spawner = getObjIdObjVar(self, VAR_SPAWNED_BY);
|
|
if (isIdValid(spawner))
|
|
{
|
|
if (spawner.isLoaded())
|
|
{
|
|
if (hasObjVar(spawner, VAR_SPAWNER_CURRENT_POPULATION))
|
|
{
|
|
// If the spawner isn't keeping track of current population, don't decrement the counter.
|
|
int population = getIntObjVar(spawner, VAR_SPAWNER_CURRENT_POPULATION);
|
|
setObjVar(spawner, VAR_SPAWNER_CURRENT_POPULATION, population - 1);
|
|
//LOG("LOG_CHANNEL", "population ->" + population);
|
|
}
|
|
else
|
|
{
|
|
LOG("quests", "quest_creature.notifySpawner(" + self + ") - spawner doesn't have objvar " + VAR_SPAWNER_CURRENT_POPULATION);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LOG("quests", "quest_creature.notifySpawner(" + self + ") - spawner " + spawner + " isn't loaded");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LOG("quests", "quest_creature.notifySpawner(" + self + ") - invalid spawner id");
|
|
}
|
|
}
|