How to open doors
oCMobDoor
object has 2 free positions:
- FRONT
- BACK
This information is stored in zCList<TMobOptPos> oCMobInter.optimalPosList
in nodeName
:
class TMobOptPos {
var int trafo[16]; //zMAT4
var int distance; //int
var int npc; //oCNpc*
var string nodeName; //zSTRING
};
When engine searches for free positions oCMobInter::SearchFreePosition
for NPC, it will update oCMobDoor.addName
with nodeName
of a position that is closer to NPC.
With this we can figure out where NPC is standing and where it needs to go:
So how do we open and close doors then?
- NPC goes to the doors.
- With
AI_UseMobPtr_Ext (self, vobPtr, 1, "UNLOCK");
(function from AFSP) NPC will unlock doors (if locked) and will open them. - We will use both free positions (FRONT & BACK) to calculate target position, where NPC needs to go to once doors are open.
- NPC goes to new calculated target position.
- NPC will either use
AI_UseMobPtr (self, vobPtr, 0);
function orAI_UseMobPtr_Ext (self, vobPtr, 0, "LOCK");
if doors were locked before to close them. - NPC goes to position of next waypoint in its route
AI_GotoPos (self, _@ (nextWP.pos));
- this is important, because if NPC would try to use 'vanilla' navigation method, it might go back to previous waypoint (if it is nearest one, and would get stuck on the door opening/closing them)