18.05.2015, 10:20
Mate, I'm using Finite State Machine method. All conditions controlled by PVar's. It's the most simple and effective enough way to do something. Many of the games used it early, but I think many of the games still using it=) get me in skype for more details=) But in general for this things I'm using the main NPC timer with 100 ms checking. Your NPC has a conditions which changed when something happens. For example, after spawn your NPC has SetPVar(npcid,"Condition",0); - it will the first check of your timer, the most easier check - to get the closest player. If(TheClosestPlayerDistance < 40.0) SetPVar(npcid,"Condition",1); next you should to write what will happens if condition will be = 1. For example
If(GetPVar(npcid,"Condition")==1)
{
if(FCNPC_GetAmmo(npcid)==0)
{
SetPVar(npcid,"Condition",2);
}
if(FCNPC_GetAmmo(npcid)!=0)
{
SetPVar(npcid,"Condition",3);
}
}
If(GetPVar(npcid,"Condition")==2)
{
FCNPC_GoTo(npcid,escape_x,escape_y,escape_z,MOVE_T YPE_SPRINT,0.0,0.0);
SetPVar(npcid,"Condition",4); // that this PVar does not be called early that we need
}
If(GetPVar(npcid,"Condition")==3)
{
new Float, Float:y, Float:z;
GetPlayerPos(TheClosestPlayer,x,y,z);
FCNPC_AimAt(npcid,x,y,z,1.0);
}
public FCNPC_OnReachDestination(npcid)
{
If(GetPVar(npcid,"Condition")==4)
{
SetPVar(npcid,"Condition",0);
}
}
So it's just an example, if you need something specific just ask me about it=)
If(GetPVar(npcid,"Condition")==1)
{
if(FCNPC_GetAmmo(npcid)==0)
{
SetPVar(npcid,"Condition",2);
}
if(FCNPC_GetAmmo(npcid)!=0)
{
SetPVar(npcid,"Condition",3);
}
}
If(GetPVar(npcid,"Condition")==2)
{
FCNPC_GoTo(npcid,escape_x,escape_y,escape_z,MOVE_T YPE_SPRINT,0.0,0.0);
SetPVar(npcid,"Condition",4); // that this PVar does not be called early that we need
}
If(GetPVar(npcid,"Condition")==3)
{
new Float, Float:y, Float:z;
GetPlayerPos(TheClosestPlayer,x,y,z);
FCNPC_AimAt(npcid,x,y,z,1.0);
}
public FCNPC_OnReachDestination(npcid)
{
If(GetPVar(npcid,"Condition")==4)
{
SetPVar(npcid,"Condition",0);
}
}
So it's just an example, if you need something specific just ask me about it=)