First of all you have to go ingame and load the filterscript npc_record then write /vrecord "anyname you want"
and it will start record,then when you finish recording write /stoprecord
then go to npcmodes and you will find the file with the name you wrote at /vrecord ,then go to pawno and:
pawn Код:
public OnGameModeInit()
{
ConnectNPC("YourNPC","Record"); // Your NPC's name,you can choose anything,Recor is the name you wrote at /vrecord..
return 1;
}
pawn Код:
public OnPlayerSpawn(playerid)
{
if(!IsPlayerNPC(playerid)) return 0; // If the player is not NPC, nothing will happend
new playername[64]; //Player String
GetPlayerName(playerid,playername,64); //This is to get the NPC's name
if(!strcmp(playername, "YourNPC", true)) { // Detecting if the NPC is spawned. If it is not spawned or the name is wrong, nothing will happend
// The code you want to do with the NPC...,like if you have recorded npc using a vehicle just make under ongamemode in it NpcCar = AddStaticVehicle(.....
}
return 1;
}
Now to anti Npc hackers:
pawn Код:
public OnPlayerConnect(playerid)
{
if(IsPlayerNPC(playerid)) {
new ip_addr_npc[64+1];
new ip_addr_server[64+1];
GetServerVarAsString("bind",ip_addr_server,64);
GetPlayerIp(playerid,ip_addr_npc,64);
if(!strlen(ip_addr_server)) {
ip_addr_server = "Your server ip..";
}
if(strcmp(ip_addr_npc,ip_addr_server,true) != 0) {
// this bot is remote connecting
printf("NPC: Got a remote NPC connecting from %s and I'm kicking it.",ip_addr_npc);
Kick(playerid);
return 0;
}
printf("NPC: Connection from %s is allowed.",ip_addr_npc);
}
return 1;
}