51 lines
1.6 KiB
Plaintext
51 lines
1.6 KiB
Plaintext
// When zombies bash a door, a certain number of "bash points" are lost.
|
|
// When this number falls under zero the door opens and all zombies currently attacking
|
|
// the door will return to chasing their original target.
|
|
// If that target is no longer in the same area, the zombies will simply return to randomly walking.
|
|
|
|
void main()
|
|
{
|
|
object oDoor = OBJECT_SELF;
|
|
int iBashPoints = GetLocalInt(oDoor, "DOOR_BASH_POINTS");
|
|
|
|
// Door needs to be initialized
|
|
if(iBashPoints == 0)
|
|
{
|
|
SetLocalInt(oDoor, "DOOR_BASH_POINTS", 7);
|
|
return;
|
|
}
|
|
|
|
// Reduce by two to prevent initialization from firing again
|
|
iBashPoints = iBashPoints - 2;
|
|
if(iBashPoints < 0 || GetIsOpen(oDoor))
|
|
{
|
|
SetLocalInt(oDoor, "DOOR_BASH_POINTS", 9);
|
|
|
|
// Open door if it's not already open (PC may have opened it)
|
|
if(!GetIsOpen(oDoor))
|
|
AssignCommand(oDoor, ActionOpenDoor(oDoor));
|
|
|
|
int iCurrentZombie = 1;
|
|
object oZombie = GetNearestObject(OBJECT_TYPE_CREATURE, oDoor, iCurrentZombie);
|
|
|
|
|
|
// All zombies currently attacking this door will return to their original target once
|
|
// the door opens.
|
|
while(GetIsObjectValid(oZombie))
|
|
{
|
|
if(GetAttackTarget(oZombie) == oDoor)
|
|
{
|
|
AssignCommand(oZombie, ClearAllActions(TRUE));
|
|
}
|
|
|
|
iCurrentZombie++;
|
|
oZombie = GetNearestObject(OBJECT_TYPE_CREATURE, oDoor, iCurrentZombie);
|
|
}
|
|
}
|
|
// Update the door's bash points
|
|
else
|
|
{
|
|
SetLocalInt(oDoor, "DOOR_BASH_POINTS", iBashPoints);
|
|
}
|
|
}
|