17.02.2014, 13:37
I want to make a PoliceNPC to follow players on the server
https://sampforum.blast.hk/showthread.php?tid=344747
http://forum.sa-mp.com/showthread.ph...highlight=knpc
I've tried to understand this thread
and from what I understood I should use this.
But I get an error, which says I should undefine BuildRecording, let's say I have made an NPC from KNPC, should that work? A Car following players.
BuildRecording(tmps,npx,npy,npz,px,py,pz, 0.006);
https://sampforum.blast.hk/showthread.php?tid=344747
http://forum.sa-mp.com/showthread.ph...highlight=knpc
I've tried to understand this thread
and from what I understood I should use this.
But I get an error, which says I should undefine BuildRecording, let's say I have made an NPC from KNPC, should that work? A Car following players.
BuildRecording(tmps,npx,npy,npz,px,py,pz, 0.006);
pawn Код:
#define FILTERSCRIPT
#include <a_samp>
#include <FileManager>
new NPCTarget[MAX_PLAYERS];
public OnFilterScriptInit()
{
SetTimer("NPCFollow",1000,1);
return 1;
}
public OnPlayerConnect(playerid)
{
if(IsPlayerNPC(playerid))
{
NPCTarget[playerid]=INVALID_PLAYER_ID; //Reset NPCs target
return 1;
}
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate==PLAYER_STATE_SPAWNED) //Reset NPCs target when player dies
for(new npc;npc<MAX_PLAYERS;npc++)if(NPCTarget[npc]==playerid)NPCTarget[npc]=INVALID_PLAYER_ID;
return 1;
}
public OnPlayerText(playerid, text[])
{
if(IsPlayerNPC(playerid))
{
if(!strcmp(text,"Command Accepted: npc",false,21)) //Only method I could think of to communicate between NPC Mode and Filterscript
{
new tmps[48];
format(tmps,48,"npcmodes\\recordings\\npc%03d.rec",strval(text[21]));
file_delete(tmps);
return 0;
}
}
return 1;
}
forward NPCFollow();
public NPCFollow()
{
new Float:npx,Float:npy,Float:npz;
new Float:px,Float:py,Float:pz;
new tmps[48];
new tmps2[48];
for(new npc=0;npc<MAX_PLAYERS;npc++)
{
if(!IsPlayerNPC(npc)||!IsPlayerConnected(npc))continue;
GetPlayerPos(npc,npx,npy,npz);
if(NPCTarget[npc]==INVALID_PLAYER_ID) //Has no Target
{
for(new playerid=0;playerid<MAX_PLAYERS;playerid++) //Search for targets
{
if(IsPlayerNPC(playerid)||!IsPlayerConnected(playerid)||(npc==playerid))continue;
if(IsPlayerInRangeOfPoint(playerid,30,npx,npy,npz))
{
NPCTarget[npc]=playerid;
printf("NPC[%d]: Target Player %d",npc,playerid);
}
}
}else{ //Has Target
GetPlayerPos(NPCTarget[npc],px,py,pz);
if(IsPlayerInRangeOfPoint(npc,0.5,px,py,pz))continue; //Poor attempt at preventing lock up
format(tmps2,48,"npcmodes\\recordings\\npc%03d.rec",npc);
if(!file_exists(tmps2))
{
format(tmps,48,"npc%03d.rec",npc);
BuildRecording(tmps,npx,npy,npz,px,py,pz, 0.006);
format(tmps,48,"scriptfiles\\npc%03d.rec",npc);
format(tmps2,48,"npcmodes\\recordings\\npc%03d.rec",npc);
file_move(tmps,tmps2);
SendClientMessage(npc,0,"GO TO FUNCTION CALLED"); //Communicate to NPC
}
}
}
}