PDA

View Full Version : CreateRNPCPolice Dont Spawn


bookknp
18/07/2018, 10:01 PM
hello guys, i have a problem, when i try to spawn an RNPC using CreateRNPCPolice not spawn and dont know the why?. Im using 0.3.7 r2 Samp dont know if RNPC is compatible?? thx for help me...


#include <a_samp>
#include <RNPC>
#include <ZCMD>
#pragma tabsize 0



public OnGameModeInit()
{
new rp = CreateRNPCPolice ("Officerino", 280);
AddRPOLWaypoint (rp, 2029.42, 1354.34, 10.5);
AddRPOLWaypoint (rp, 2033.55, 1286.21, 10.5);
AddRPOLWaypoint (rp, 2079.03, 1286.00, 10.5);
AddRPOLWaypoint (rp, 2079.02, 1362.08, 10.5);
StartRPOLRoute(rp);


return 1;
}

C:\Users\1320703\Desktop\GTA3\server2\pawno\includ e\RNPC2.inc(222) : warning 209: function "RNPC_OnPlayerSpawn" should return a value
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Warning.

RedRex
18/07/2018, 10:27 PM
Show us line RNPC2.inc(222) at the include.

bookknp
18/07/2018, 10:58 PM
Show us line RNPC2.inc(222) at the include.

This is include... can u help me?? i donwloaded it


/**
* RNPC Police include
* Simple AI and tutorial script
* Mauzen, 10.7.2012, V1.0
*/

#include <RNPC>

#define RPOL_MAX_WAYPOINTS (12) // Maximum number of waypoints for a policeman
#define RPOL_VISIONRANGE (25.0) // Attacking players in that range will be chased
#define RPOL_ATTACKRANGE (15.0) // Policeman starts firing when in this range to the player
#define MAX_RNPC_POLICE (8) // Max number of police officers
#define RPOL_UPDATE (200) // Interval in ms to update movements, attacks, etc

new pol;

// The enum containing all data for a single policeman
enum RPol_enum {
RPOL_NPCID,
RPOL_TIMER,
Float: RPOL_WAYPOINTS_X[RPOL_MAX_WAYPOINTS],
Float: RPOL_WAYPOINTS_Y[RPOL_MAX_WAYPOINTS],
Float: RPOL_WAYPOINTS_Z[RPOL_MAX_WAYPOINTS],
RPOL_WPINDEX,
RPOL_NEXTWP,
RPOL_CURTARGET,
RPOL_SKIN
};

// Initial data
new rpol[MAX_RNPC_POLICE][RPol_enum] = {{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1},
{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1},
{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1} };

// Creates a new policeman
stock CreateRNPCPolice(name[], skin)
{
// Find a free spot in the rpol array
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == -1) {
slot = i;
break;
}
}
if (slot == -1) return -1;

// Connect the NPC
rpol[slot][RPOL_NPCID] = ConnectRNPC(name);
rpol[slot][RPOL_SKIN] = skin;
return slot;
}

// Adds a waypoint to the Policeman's path
stock AddRPOLWaypoint(rpolid, Float:x, Float:y, Float:z) {
if (rpol[rpolid][RPOL_NPCID] == -1) return false;
if (rpol[rpolid][RPOL_WPINDEX] >= RPOL_MAX_WAYPOINTS) return false;
// Store the waypoint coordinates at the last free position
new slot = rpol[rpolid][RPOL_WPINDEX];
rpol[rpolid][RPOL_WAYPOINTS_X][slot] = x;
rpol[rpolid][RPOL_WAYPOINTS_Y][slot] = y;
rpol[rpolid][RPOL_WAYPOINTS_Z][slot] = z;

rpol[rpolid][RPOL_WPINDEX]++;
return true;
}

stock StartRPOLRoute(rpolid)
{
// If valid and not already walking
if (rpol[rpolid][RPOL_TIMER] == -1 && rpol[rpolid][RPOL_NPCID] != -1) {
rpol[rpolid][RPOL_TIMER] = SetTimerEx("WatchTimer", RPOL_UPDATE, 1, "i", rpolid);
// Move to the first waypoint
MoveRNPC(rpol[rpolid][RPOL_NPCID], rpol[rpolid][RPOL_WAYPOINTS_X][0], rpol[rpolid][RPOL_WAYPOINTS_Y][0],
rpol[rpolid][RPOL_WAYPOINTS_Z][0], RNPC_SPEED_RUN);
return true;
}
return 0;
}

stock RemoveRNPCPolice(rpolid)
{
if (rpol[rpolid][RPOL_TIMER] > -1) {
// Stop timer
KillTimer(rpol[slot][RPOL_TIMER]);
}
// Kick the NPC
Kick(rpol[rpolid][RPOL_NPCID];
// Reset data
rpol[rpolid] = {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1};
}
public OnGameModeInit()
{
if(IsPlayerNPC(playerid)){
pol = ConnectRNPC("Officerino");
new rp = CreateRNPCPolice ("Officerino", 280);
AddRPOLWaypoint (rp, 2029.42, 1354.34, 10.5);
AddRPOLWaypoint (rp, 2033.55, 1286.21, 10.5);
AddRPOLWaypoint (rp, 2079.03, 1286.00, 10.5);
AddRPOLWaypoint (rp, 2079.02, 1362.08, 10.5);
StartRPOLRoute(rp);

}
return 1;
}
// This is the timer that actually controls the policeman
// and so the actually interesting "KI" for the RNPC
forward Bots(playerid);
public Bots(playerid)
{

SetTimer("StartAllRoutes", 500, 0);
}
forward StartAllRoutes();
public StartAllRoutes() {

// etc
}
forward WatchTimer(id);
public WatchTimer(id) {
if (rpol[id][RPOL_CURTARGET] > -1) {
new Float:x, Float:y, Float:z;
GetPlayerPos(rpol[id][RPOL_CURTARGET], x, y ,z);
if (!IsPlayerInRangeOfPoint(rpol[id][RPOL_NPCID], RPOL_VISIONRANGE * 2.0, x, y, z)
|| GetPlayerState(rpol[id][RPOL_CURTARGET]) != PLAYER_STATE_ONFOOT) {
// Target escaped or died
// Stop shooting
RNPC_SetKeys(0);
// Continue route
MoveRNPC(rpol[id][RPOL_NPCID], rpol[id][RPOL_WAYPOINTS_X][rpol[id][RPOL_NEXTWP]],
rpol[id][RPOL_WAYPOINTS_Y][rpol[id][RPOL_NEXTWP]], rpol[id][RPOL_WAYPOINTS_Z][rpol[id][RPOL_NEXTWP]],
RNPC_SPEED_RUN);
rpol[id][RPOL_CURTARGET] = -1;
return;
} else
if (IsPlayerInRangeOfPoint(rpol[id][RPOL_NPCID], RPOL_ATTACKRANGE, x, y, z)) {
// Target is in attackrange
// Stop running and start shhoting
new Float:ox, Float:oy, Float:oz;
GetPlayerPos(rpol[id][RPOL_NPCID], ox, oy, oz);
// Angle to the target
new Float:angle = atan2(ox - x, oy - y) + 180.0;
// Stop and build, alternate slot for security
RNPC_StopPlayback(rpol[id][RPOL_NPCID]);
RNPC_CreateBuild(rpol[id][RPOL_NPCID], PLAYER_RECORDING_TYPE_ONFOOT, 1);
// Set weapon
RNPC_SetWeaponID(22);
// Set facing angle to the target
RNPC_SetAngleQuats(0.0, angle, 0.0);
// Start firing
RNPC_SetKeys(KEY_FIRE);
// Move towards the target from the current position
RNPC_ConcatMovement(x, y, z, RNPC_SPEED_RUN);
// Finish build
RNPC_FinishBuild();

// Start playback
RNPC_StartBuildPlayback(id, 1);

} else {
// Stop shooting
RNPC_SetKeys(0);
// Move towards the targets
MoveRNPC(rpol[id][RPOL_NPCID], x, y, z, RNPC_SPEED_RUN);
}
}
}

// Hook OnNPCPlaybackFinished to determine when a NPC reached his current waypoint
public OnRNPCPlaybackFinished(npcid)
{
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == npcid) {
slot = i;
break;
}
}
if (slot > -1) {
// NPC is a RNPC policeman
if (rpol[slot][RPOL_CURTARGET] == -1) {
// Increase current waypoint index, and set it to 0 when the last one is reached
rpol[slot][RPOL_NEXTWP] = (rpol[slot][RPOL_NEXTWP] + 1) % rpol[slot][RPOL_WPINDEX];
// Make him walk to the next waypoint
MoveRNPC(rpol[slot][RPOL_NPCID], rpol[slot][RPOL_WAYPOINTS_X][rpol[slot][RPOL_NEXTWP]],
rpol[slot][RPOL_WAYPOINTS_Y][rpol[slot][RPOL_NEXTWP]], rpol[slot][RPOL_WAYPOINTS_Z][rpol[slot][RPOL_NEXTWP]],
RNPC_SPEED_WALK);
}
}
CallLocalFunction("RNPC_OnRNPCPlaybackFinished", "i", npcid);
}
#if defined _ALS_OnRNPCPlaybackFinished
#undef OnRNPCPlaybackFinished
#else
#define _ALS_OnRNPCPlaybackFinished
#endif
#define OnRNPCPlaybackFinished RNPC_OnRNPCPlaybackFinished
forward RNPC_OnRNPCPlaybackFinished(npcid);

// Hook OnPlayerKeyStateChange to detect firing players
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
// Check if player started firing
if (!(oldkeys & KEY_FIRE) && (newkeys & KEY_FIRE)) {
// Check if player holds a gun
if (GetPlayerWeapon(playerid) > 16 && GetPlayerWeapon(playerid) < 40) {
new Float:px, Float:py, Float:pz;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
// Skip invalid and already following npcs
if (rpol[i][RPOL_NPCID] == -1 || rpol[i][RPOL_CURTARGET] > -1) continue;
GetPlayerPos(rpol[i][RPOL_NPCID], px, py, pz);
// If police in in range make him chase the attacking player
if (IsPlayerInRangeOfPoint(playerid, RPOL_VISIONRANGE, px, py, pz)) {
rpol[i][RPOL_CURTARGET] = playerid;
}
}
}
}
CallLocalFunction("RNPC_OnPlayerKeyStateChange", "iii", playerid, newkeys, oldkeys);

}
#if defined _ALS_OnPlayerKeyStateChange
#undef OnPlayerKeyStateChange
#else
#define _ALS_OnPlayerKeyStateChange
#endif
#define OnPlayerKeyStateChange RNPC_OnPlayerKeyStateChange
forward RNPC_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);

// Hook OnPlayerSpawn to set the NPCs skin
public OnPlayerSpawn(playerid)
{
if (IsPlayerNPC(playerid)) {
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == playerid) {
slot = i;
break;
}
}
// If playerid is a policeman
if (slot > -1) {
SetPlayerSkin(playerid, rpol[slot][RPOL_SKIN]);
}
}
CallLocalFunction("RNPC_OnPlayerSpawn", "i", playerid);

} //<--------------- (Line 222)
#if defined _ALS_OnPlayerSpawn
#undef OnPlayerSpawn
#else
#define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn RNPC_OnPlayerSpawn
forward RNPC_OnPlayerSpawn(playerid);

RedRex
18/07/2018, 11:02 PM
Hi buddy! Try this code!

Make this defines top of your script..
#if defined _ALS_OnPlayerSpawn
#undef OnPlayerSpawn
#else
#define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn RNPC_OnPlayerSpawn
forward RNPC_OnPlayerSpawn(playerid);

Then change your old code to this new code.
public OnPlayerSpawn(playerid)
{
if (IsPlayerNPC(playerid)) {
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == playerid) {
slot = i;
break;
}
}
// If playerid is a policeman
if (slot > -1) {
SetPlayerSkin(playerid, rpol[slot][RPOL_SKIN]);
}
}
CallLocalFunction("RNPC_OnPlayerSpawn", "i", playerid);
return 1;
}

bookknp
18/07/2018, 11:10 PM
Hi buddy! Try this code!

Make this defines top of your script..
#if defined _ALS_OnPlayerSpawn
#undef OnPlayerSpawn
#else
#define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn RNPC_OnPlayerSpawn
forward RNPC_OnPlayerSpawn(playerid);

Then change your old code to this new code.
public OnPlayerSpawn(playerid)
{
if (IsPlayerNPC(playerid)) {
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == playerid) {
slot = i;
break;
}
}
// If playerid is a policeman
if (slot > -1) {
SetPlayerSkin(playerid, rpol[slot][RPOL_SKIN]);
}
}
CallLocalFunction("RNPC_OnPlayerSpawn", "i", playerid);
return 1;
}

hi friend, error :/, i change all u said me...

C:\Users\1320703\Desktop\GTA3\server2\pawno\includ e\../include/RNPC2.inc(222) : warning 209: function "RNPC_OnPlayerSpawn" should return a value
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Warning.


/**
* RNPC Police include
* Simple AI and tutorial script
* Mauzen, 10.7.2012, V1.0
*/

#include <RNPC>

#define RPOL_MAX_WAYPOINTS (12) // Maximum number of waypoints for a policeman
#define RPOL_VISIONRANGE (25.0) // Attacking players in that range will be chased
#define RPOL_ATTACKRANGE (15.0) // Policeman starts firing when in this range to the player
#define MAX_RNPC_POLICE (8) // Max number of police officers
#define RPOL_UPDATE (200) // Interval in ms to update movements, attacks, etc

#if defined _ALS_OnPlayerSpawn
#undef OnPlayerSpawn
#else
#define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn RNPC_OnPlayerSpawn
forward RNPC_OnPlayerSpawn(playerid);


// The enum containing all data for a single policeman
enum RPol_enum {
RPOL_NPCID,
RPOL_TIMER,
Float: RPOL_WAYPOINTS_X[RPOL_MAX_WAYPOINTS],
Float: RPOL_WAYPOINTS_Y[RPOL_MAX_WAYPOINTS],
Float: RPOL_WAYPOINTS_Z[RPOL_MAX_WAYPOINTS],
RPOL_WPINDEX,
RPOL_NEXTWP,
RPOL_CURTARGET,
RPOL_SKIN
};

// Initial data
new rpol[MAX_RNPC_POLICE][RPol_enum] = {{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1},
{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1},
{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1} };

// Creates a new policeman
stock CreateRNPCPolice(name[], skin)
{
// Find a free spot in the rpol array
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == -1) {
slot = i;
break;
}
}
if (slot == -1) return -1;

// Connect the NPC
rpol[slot][RPOL_NPCID] = ConnectRNPC(name);
rpol[slot][RPOL_SKIN] = skin;
return slot;
}

// Adds a waypoint to the Policeman's path
stock AddRPOLWaypoint(rpolid, Float:x, Float:y, Float:z) {
if (rpol[rpolid][RPOL_NPCID] == -1) return false;
if (rpol[rpolid][RPOL_WPINDEX] >= RPOL_MAX_WAYPOINTS) return false;
// Store the waypoint coordinates at the last free position
new slot = rpol[rpolid][RPOL_WPINDEX];
rpol[rpolid][RPOL_WAYPOINTS_X][slot] = x;
rpol[rpolid][RPOL_WAYPOINTS_Y][slot] = y;
rpol[rpolid][RPOL_WAYPOINTS_Z][slot] = z;

rpol[rpolid][RPOL_WPINDEX]++;
return true;
}

stock StartRPOLRoute(rpolid)
{
// If valid and not already walking
if (rpol[rpolid][RPOL_TIMER] == -1 && rpol[rpolid][RPOL_NPCID] != -1) {
rpol[rpolid][RPOL_TIMER] = SetTimerEx("WatchTimer", RPOL_UPDATE, 1, "i", rpolid);
// Move to the first waypoint
MoveRNPC(rpol[rpolid][RPOL_NPCID], rpol[rpolid][RPOL_WAYPOINTS_X][0], rpol[rpolid][RPOL_WAYPOINTS_Y][0],
rpol[rpolid][RPOL_WAYPOINTS_Z][0], RNPC_SPEED_RUN);
return true;
}
return 0;
}

stock RemoveRNPCPolice(rpolid)
{
if (rpol[rpolid][RPOL_TIMER] > -1) {
// Stop timer
KillTimer(rpol[slot][RPOL_TIMER]);
}
// Kick the NPC
Kick(rpol[rpolid][RPOL_NPCID];
// Reset data
rpol[rpolid] = {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1};
}
public OnGameModeInit()
{


new rp = CreateRNPCPolice ("Officerino", 280);
AddRPOLWaypoint (rp, 2029.42, 1354.34, 10.5);
AddRPOLWaypoint (rp, 2033.55, 1286.21, 10.5);
AddRPOLWaypoint (rp, 2079.03, 1286.00, 10.5);
AddRPOLWaypoint (rp, 2079.02, 1362.08, 10.5);
StartRPOLRoute(rp);


return 1;
}
// This is the timer that actually controls the policeman
// and so the actually interesting "KI" for the RNPC
forward Bots(playerid);
public Bots(playerid)
{

SetTimer("StartAllRoutes", 500, 0);
}
forward StartAllRoutes();
public StartAllRoutes() {

// etc
}
forward WatchTimer(id);
public WatchTimer(id) {
if (rpol[id][RPOL_CURTARGET] > -1) {
new Float:x, Float:y, Float:z;
GetPlayerPos(rpol[id][RPOL_CURTARGET], x, y ,z);
if (!IsPlayerInRangeOfPoint(rpol[id][RPOL_NPCID], RPOL_VISIONRANGE * 2.0, x, y, z)
|| GetPlayerState(rpol[id][RPOL_CURTARGET]) != PLAYER_STATE_ONFOOT) {
// Target escaped or died
// Stop shooting
RNPC_SetKeys(0);
// Continue route
MoveRNPC(rpol[id][RPOL_NPCID], rpol[id][RPOL_WAYPOINTS_X][rpol[id][RPOL_NEXTWP]],
rpol[id][RPOL_WAYPOINTS_Y][rpol[id][RPOL_NEXTWP]], rpol[id][RPOL_WAYPOINTS_Z][rpol[id][RPOL_NEXTWP]],
RNPC_SPEED_RUN);
rpol[id][RPOL_CURTARGET] = -1;
return;
} else
if (IsPlayerInRangeOfPoint(rpol[id][RPOL_NPCID], RPOL_ATTACKRANGE, x, y, z)) {
// Target is in attackrange
// Stop running and start shhoting
new Float:ox, Float:oy, Float:oz;
GetPlayerPos(rpol[id][RPOL_NPCID], ox, oy, oz);
// Angle to the target
new Float:angle = atan2(ox - x, oy - y) + 180.0;
// Stop and build, alternate slot for security
RNPC_StopPlayback(rpol[id][RPOL_NPCID]);
RNPC_CreateBuild(rpol[id][RPOL_NPCID], PLAYER_RECORDING_TYPE_ONFOOT, 1);
// Set weapon
RNPC_SetWeaponID(22);
// Set facing angle to the target
RNPC_SetAngleQuats(0.0, angle, 0.0);
// Start firing
RNPC_SetKeys(KEY_FIRE);
// Move towards the target from the current position
RNPC_ConcatMovement(x, y, z, RNPC_SPEED_RUN);
// Finish build
RNPC_FinishBuild();

// Start playback
RNPC_StartBuildPlayback(id, 1);

} else {
// Stop shooting
RNPC_SetKeys(0);
// Move towards the targets
MoveRNPC(rpol[id][RPOL_NPCID], x, y, z, RNPC_SPEED_RUN);
}
}
}

// Hook OnNPCPlaybackFinished to determine when a NPC reached his current waypoint
public OnRNPCPlaybackFinished(npcid)
{
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == npcid) {
slot = i;
break;
}
}
if (slot > -1) {
// NPC is a RNPC policeman
if (rpol[slot][RPOL_CURTARGET] == -1) {
// Increase current waypoint index, and set it to 0 when the last one is reached
rpol[slot][RPOL_NEXTWP] = (rpol[slot][RPOL_NEXTWP] + 1) % rpol[slot][RPOL_WPINDEX];
// Make him walk to the next waypoint
MoveRNPC(rpol[slot][RPOL_NPCID], rpol[slot][RPOL_WAYPOINTS_X][rpol[slot][RPOL_NEXTWP]],
rpol[slot][RPOL_WAYPOINTS_Y][rpol[slot][RPOL_NEXTWP]], rpol[slot][RPOL_WAYPOINTS_Z][rpol[slot][RPOL_NEXTWP]],
RNPC_SPEED_WALK);
}
}
CallLocalFunction("RNPC_OnRNPCPlaybackFinished", "i", npcid);
}
#if defined _ALS_OnRNPCPlaybackFinished
#undef OnRNPCPlaybackFinished
#else
#define _ALS_OnRNPCPlaybackFinished
#endif
#define OnRNPCPlaybackFinished RNPC_OnRNPCPlaybackFinished
forward RNPC_OnRNPCPlaybackFinished(npcid);

// Hook OnPlayerKeyStateChange to detect firing players
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
// Check if player started firing
if (!(oldkeys & KEY_FIRE) && (newkeys & KEY_FIRE)) {
// Check if player holds a gun
if (GetPlayerWeapon(playerid) > 16 && GetPlayerWeapon(playerid) < 40) {
new Float:px, Float:py, Float:pz;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
// Skip invalid and already following npcs
if (rpol[i][RPOL_NPCID] == -1 || rpol[i][RPOL_CURTARGET] > -1) continue;
GetPlayerPos(rpol[i][RPOL_NPCID], px, py, pz);
// If police in in range make him chase the attacking player
if (IsPlayerInRangeOfPoint(playerid, RPOL_VISIONRANGE, px, py, pz)) {
rpol[i][RPOL_CURTARGET] = playerid;
}
}
}
}
CallLocalFunction("RNPC_OnPlayerKeyStateChange", "iii", playerid, newkeys, oldkeys);

}
#if defined _ALS_OnPlayerKeyStateChange
#undef OnPlayerKeyStateChange
#else
#define _ALS_OnPlayerKeyStateChange
#endif
#define OnPlayerKeyStateChange RNPC_OnPlayerKeyStateChange
forward RNPC_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);

// Hook OnPlayerSpawn to set the NPCs skin
public OnPlayerSpawn(playerid)
{
if (IsPlayerNPC(playerid)) {
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == playerid) {
slot = i;
break;
}
}
// If playerid is a policeman
if (slot > -1) {
SetPlayerSkin(playerid, rpol[slot][RPOL_SKIN]);
}
}
CallLocalFunction("RNPC_OnPlayerSpawn", "i", playerid);
return 1;
}

RedRex
18/07/2018, 11:15 PM
hi friend, error :/, i change all u said me...

C:\Users\1320703\Desktop\GTA3\server2\pawno\includ e\../include/RNPC2.inc(222) : warning 209: function "RNPC_OnPlayerSpawn" should return a value
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Warning.


/**
* RNPC Police include
* Simple AI and tutorial script
* Mauzen, 10.7.2012, V1.0
*/

#include <RNPC>

#define RPOL_MAX_WAYPOINTS (12) // Maximum number of waypoints for a policeman
#define RPOL_VISIONRANGE (25.0) // Attacking players in that range will be chased
#define RPOL_ATTACKRANGE (15.0) // Policeman starts firing when in this range to the player
#define MAX_RNPC_POLICE (8) // Max number of police officers
#define RPOL_UPDATE (200) // Interval in ms to update movements, attacks, etc

#if defined _ALS_OnPlayerSpawn
#undef OnPlayerSpawn
#else
#define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn RNPC_OnPlayerSpawn
forward RNPC_OnPlayerSpawn(playerid);


// The enum containing all data for a single policeman
enum RPol_enum {
RPOL_NPCID,
RPOL_TIMER,
Float: RPOL_WAYPOINTS_X[RPOL_MAX_WAYPOINTS],
Float: RPOL_WAYPOINTS_Y[RPOL_MAX_WAYPOINTS],
Float: RPOL_WAYPOINTS_Z[RPOL_MAX_WAYPOINTS],
RPOL_WPINDEX,
RPOL_NEXTWP,
RPOL_CURTARGET,
RPOL_SKIN
};

// Initial data
new rpol[MAX_RNPC_POLICE][RPol_enum] = {{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1},
{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1},
{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1} };

// Creates a new policeman
stock CreateRNPCPolice(name[], skin)
{
// Find a free spot in the rpol array
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == -1) {
slot = i;
break;
}
}
if (slot == -1) return -1;

// Connect the NPC
rpol[slot][RPOL_NPCID] = ConnectRNPC(name);
rpol[slot][RPOL_SKIN] = skin;
return slot;
}

// Adds a waypoint to the Policeman's path
stock AddRPOLWaypoint(rpolid, Float:x, Float:y, Float:z) {
if (rpol[rpolid][RPOL_NPCID] == -1) return false;
if (rpol[rpolid][RPOL_WPINDEX] >= RPOL_MAX_WAYPOINTS) return false;
// Store the waypoint coordinates at the last free position
new slot = rpol[rpolid][RPOL_WPINDEX];
rpol[rpolid][RPOL_WAYPOINTS_X][slot] = x;
rpol[rpolid][RPOL_WAYPOINTS_Y][slot] = y;
rpol[rpolid][RPOL_WAYPOINTS_Z][slot] = z;

rpol[rpolid][RPOL_WPINDEX]++;
return true;
}

stock StartRPOLRoute(rpolid)
{
// If valid and not already walking
if (rpol[rpolid][RPOL_TIMER] == -1 && rpol[rpolid][RPOL_NPCID] != -1) {
rpol[rpolid][RPOL_TIMER] = SetTimerEx("WatchTimer", RPOL_UPDATE, 1, "i", rpolid);
// Move to the first waypoint
MoveRNPC(rpol[rpolid][RPOL_NPCID], rpol[rpolid][RPOL_WAYPOINTS_X][0], rpol[rpolid][RPOL_WAYPOINTS_Y][0],
rpol[rpolid][RPOL_WAYPOINTS_Z][0], RNPC_SPEED_RUN);
return true;
}
return 0;
}

stock RemoveRNPCPolice(rpolid)
{
if (rpol[rpolid][RPOL_TIMER] > -1) {
// Stop timer
KillTimer(rpol[slot][RPOL_TIMER]);
}
// Kick the NPC
Kick(rpol[rpolid][RPOL_NPCID];
// Reset data
rpol[rpolid] = {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1};
}
public OnGameModeInit()
{


new rp = CreateRNPCPolice ("Officerino", 280);
AddRPOLWaypoint (rp, 2029.42, 1354.34, 10.5);
AddRPOLWaypoint (rp, 2033.55, 1286.21, 10.5);
AddRPOLWaypoint (rp, 2079.03, 1286.00, 10.5);
AddRPOLWaypoint (rp, 2079.02, 1362.08, 10.5);
StartRPOLRoute(rp);


return 1;
}
// This is the timer that actually controls the policeman
// and so the actually interesting "KI" for the RNPC
forward Bots(playerid);
public Bots(playerid)
{

SetTimer("StartAllRoutes", 500, 0);
}
forward StartAllRoutes();
public StartAllRoutes() {

// etc
}
forward WatchTimer(id);
public WatchTimer(id) {
if (rpol[id][RPOL_CURTARGET] > -1) {
new Float:x, Float:y, Float:z;
GetPlayerPos(rpol[id][RPOL_CURTARGET], x, y ,z);
if (!IsPlayerInRangeOfPoint(rpol[id][RPOL_NPCID], RPOL_VISIONRANGE * 2.0, x, y, z)
|| GetPlayerState(rpol[id][RPOL_CURTARGET]) != PLAYER_STATE_ONFOOT) {
// Target escaped or died
// Stop shooting
RNPC_SetKeys(0);
// Continue route
MoveRNPC(rpol[id][RPOL_NPCID], rpol[id][RPOL_WAYPOINTS_X][rpol[id][RPOL_NEXTWP]],
rpol[id][RPOL_WAYPOINTS_Y][rpol[id][RPOL_NEXTWP]], rpol[id][RPOL_WAYPOINTS_Z][rpol[id][RPOL_NEXTWP]],
RNPC_SPEED_RUN);
rpol[id][RPOL_CURTARGET] = -1;
return;
} else
if (IsPlayerInRangeOfPoint(rpol[id][RPOL_NPCID], RPOL_ATTACKRANGE, x, y, z)) {
// Target is in attackrange
// Stop running and start shhoting
new Float:ox, Float:oy, Float:oz;
GetPlayerPos(rpol[id][RPOL_NPCID], ox, oy, oz);
// Angle to the target
new Float:angle = atan2(ox - x, oy - y) + 180.0;
// Stop and build, alternate slot for security
RNPC_StopPlayback(rpol[id][RPOL_NPCID]);
RNPC_CreateBuild(rpol[id][RPOL_NPCID], PLAYER_RECORDING_TYPE_ONFOOT, 1);
// Set weapon
RNPC_SetWeaponID(22);
// Set facing angle to the target
RNPC_SetAngleQuats(0.0, angle, 0.0);
// Start firing
RNPC_SetKeys(KEY_FIRE);
// Move towards the target from the current position
RNPC_ConcatMovement(x, y, z, RNPC_SPEED_RUN);
// Finish build
RNPC_FinishBuild();

// Start playback
RNPC_StartBuildPlayback(id, 1);

} else {
// Stop shooting
RNPC_SetKeys(0);
// Move towards the targets
MoveRNPC(rpol[id][RPOL_NPCID], x, y, z, RNPC_SPEED_RUN);
}
}
}

// Hook OnNPCPlaybackFinished to determine when a NPC reached his current waypoint
public OnRNPCPlaybackFinished(npcid)
{
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == npcid) {
slot = i;
break;
}
}
if (slot > -1) {
// NPC is a RNPC policeman
if (rpol[slot][RPOL_CURTARGET] == -1) {
// Increase current waypoint index, and set it to 0 when the last one is reached
rpol[slot][RPOL_NEXTWP] = (rpol[slot][RPOL_NEXTWP] + 1) % rpol[slot][RPOL_WPINDEX];
// Make him walk to the next waypoint
MoveRNPC(rpol[slot][RPOL_NPCID], rpol[slot][RPOL_WAYPOINTS_X][rpol[slot][RPOL_NEXTWP]],
rpol[slot][RPOL_WAYPOINTS_Y][rpol[slot][RPOL_NEXTWP]], rpol[slot][RPOL_WAYPOINTS_Z][rpol[slot][RPOL_NEXTWP]],
RNPC_SPEED_WALK);
}
}
CallLocalFunction("RNPC_OnRNPCPlaybackFinished", "i", npcid);
}
#if defined _ALS_OnRNPCPlaybackFinished
#undef OnRNPCPlaybackFinished
#else
#define _ALS_OnRNPCPlaybackFinished
#endif
#define OnRNPCPlaybackFinished RNPC_OnRNPCPlaybackFinished
forward RNPC_OnRNPCPlaybackFinished(npcid);

// Hook OnPlayerKeyStateChange to detect firing players
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
// Check if player started firing
if (!(oldkeys & KEY_FIRE) && (newkeys & KEY_FIRE)) {
// Check if player holds a gun
if (GetPlayerWeapon(playerid) > 16 && GetPlayerWeapon(playerid) < 40) {
new Float:px, Float:py, Float:pz;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
// Skip invalid and already following npcs
if (rpol[i][RPOL_NPCID] == -1 || rpol[i][RPOL_CURTARGET] > -1) continue;
GetPlayerPos(rpol[i][RPOL_NPCID], px, py, pz);
// If police in in range make him chase the attacking player
if (IsPlayerInRangeOfPoint(playerid, RPOL_VISIONRANGE, px, py, pz)) {
rpol[i][RPOL_CURTARGET] = playerid;
}
}
}
}
CallLocalFunction("RNPC_OnPlayerKeyStateChange", "iii", playerid, newkeys, oldkeys);

}
#if defined _ALS_OnPlayerKeyStateChange
#undef OnPlayerKeyStateChange
#else
#define _ALS_OnPlayerKeyStateChange
#endif
#define OnPlayerKeyStateChange RNPC_OnPlayerKeyStateChange
forward RNPC_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);

// Hook OnPlayerSpawn to set the NPCs skin
public OnPlayerSpawn(playerid)
{
if (IsPlayerNPC(playerid)) {
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == playerid) {
slot = i;
break;
}
}
// If playerid is a policeman
if (slot > -1) {
SetPlayerSkin(playerid, rpol[slot][RPOL_SKIN]);
}
}
CallLocalFunction("RNPC_OnPlayerSpawn", "i", playerid);
return 1;
}


Try this code.

public OnPlayerSpawn(playerid)
{
if (IsPlayerNPC(playerid)) {
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == playerid) {
slot = i;
break;
}
}
// If playerid is a policeman
if (slot > -1) {
SetPlayerSkin(playerid, rpol[slot][RPOL_SKIN]);
}
return 1;
}
CallLocalFunction("RNPC_OnPlayerSpawn", "i", playerid);
return 1;
}

bookknp
18/07/2018, 11:23 PM
Try this code.

public OnPlayerSpawn(playerid)
{
if (IsPlayerNPC(playerid)) {
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == playerid) {
slot = i;
break;
}
}
// If playerid is a policeman
if (slot > -1) {
SetPlayerSkin(playerid, rpol[slot][RPOL_SKIN]);
}
return 1;
}
CallLocalFunction("RNPC_OnPlayerSpawn", "i", playerid);
return 1;
}

Very thx, but the error continue, friend... is it old script?? is it compatible with samp 0.3.7 r2??

C:\Users\1320703\Desktop\GTA3\server2\pawno\includ e\../include/RNPC2.inc(222) : warning 209: function "RNPC_OnPlayerSpawn" should return a value
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


1 Warning.


i fixed it, but dont spawn RNPCPolice, why??

#pragma tabsize 0

RedRex
19/07/2018, 01:14 AM
Your code since 2013 and must be updated includes + plugins try download SAMP 0.3.7 RC 2 AND RE-compatible IT

And did you copy your script? http://forum.sa-mp.com/showthread.php?t=583378

Mauzen
19/07/2018, 04:39 PM
Check the maxnpcs setting in the server.cfg. Should be bigger than 0, or eventually add it if that setting is missing in your config.
If this doesnt help, make sure youve got the "npcmodes" subdirectory in the server directory, and in there the freshly compiled RNPC npcmode, as well as the "recordings" directory, all with the correct permissions (if youre using linux).

bookknp
19/07/2018, 07:28 PM
Check the maxnpcs setting in the server.cfg. Should be bigger than 0, or eventually add it if that setting is missing in your config.
If this doesnt help, make sure youve got the "npcmodes" subdirectory in the server directory, and in there the freshly compiled RNPC npcmode, as well as the "recordings" directory, all with the correct permissions (if youre using linux).

Hello Mauzen!!!,

I have checked Server.cfg and it is all right, I have the folder npcmodes and recording, but now I do not know how to put an npc recorded. I am new, can you explain it to me?

Server.cfg

echo Executing Server Config...
lanmode 1
rcon_password playground
maxplayers 100
port 7887
hostname KoN
gamemode0 gamemode 1
filterscripts Skins dropweapon me Cars
plugins streamer pawn-memory RNPC
announce 1
query 1
weburl http://konclan.net/
maxnpc 100
onfoot_rate 40
incar_rate 40
weapon_rate 40
stream_distance 300.0
stream_rate 1000
logtimeformat [%H:%M:%S]
ackslimit 50000



i put this in my gamemode, but dont spawn RNPCPolice... help me plz?? (i fixed all errors, and now compile rightly)


forward Bots(playerid);
forward Route(playerid);

public OnGameModeInit()
{

SetTimer("Bots",0,false);

public Bots(playerid)
{
new rp = CreateRNPCPolice ("Officerino", 280);
AddRPOLWaypoint (rp, 2029.42, 1354.34, 10.5);
AddRPOLWaypoint (rp, 2033.55, 1286.21, 10.5);
AddRPOLWaypoint (rp, 2079.03, 1286.00, 10.5);
AddRPOLWaypoint (rp, 2079.02, 1362.08, 10.5);
SetTimerEx ("Route", 500, 0, "i", playerid);
return 1;
}

public Route()
{
StartRPOLRoute (CreateRNPCPolice("Officerino", 280));
return 1;
}

Mauzen
19/07/2018, 08:02 PM
No need to add recordings, RNPC does that automatically. Theres a RNPC.pwn in npcmodes though, that you need to recompile like a normal gamemode.

Your spawn code also is a bit messy, better use it like this:


forward Route(playerid);

public OnGameModeInit()
{
// No need for the first timer
new rp = CreateRNPCPolice ("Officerino", 280);
AddRPOLWaypoint (rp, 2029.42, 1354.34, 10.5);
AddRPOLWaypoint (rp, 2033.55, 1286.21, 10.5);
AddRPOLWaypoint (rp, 2079.03, 1286.00, 10.5);
AddRPOLWaypoint (rp, 2079.02, 1362.08, 10.5);
SetTimerEx ("Route", 500, 0, "i", rp); // Pass the police officer id


public Route(rp)
{
StartRPOLRoute (rp); // Start the route for the given police officer id
return 1;
}

bookknp
19/07/2018, 09:25 PM
No need to add recordings, RNPC does that automatically. Theres a RNPC.pwn in npcmodes though, that you need to recompile like a normal gamemode.

Your spawn code also is a bit messy, better use it like this:


forward Route(playerid);

public OnGameModeInit()
{
// No need for the first timer
new rp = CreateRNPCPolice ("Officerino", 280);
AddRPOLWaypoint (rp, 2029.42, 1354.34, 10.5);
AddRPOLWaypoint (rp, 2033.55, 1286.21, 10.5);
AddRPOLWaypoint (rp, 2079.03, 1286.00, 10.5);
AddRPOLWaypoint (rp, 2079.02, 1362.08, 10.5);
SetTimerEx ("Route", 500, 0, "i", rp); // Pass the police officer id


public Route(rp)
{
StartRPOLRoute (rp); // Start the route for the given police officer id
return 1;
}



I am trying to spawn the NPC but it does not appear, I show you my includes to see if anything is missing. thx friend.

/**
* RNPC Police include
* Simple AI and tutorial script
* Mauzen, 10.7.2012, V1.0
*/
#include <RNPC>
#pragma tabsize 0

#define RPOL_MAX_WAYPOINTS (12) // Maximum number of waypoints for a policeman
#define RPOL_VISIONRANGE (25.0) // Attacking players in that range will be chased
#define RPOL_ATTACKRANGE (15.0) // Policeman starts firing when in this range to the player
#define MAX_RNPC_POLICE (8) // Max number of police officers
#define RPOL_UPDATE (200) // Interval in ms to update movements, attacks, etc


#if defined _ALS_OnPlayerSpawn
#undef OnPlayerSpawn
#else
#define _ALS_OnPlayerSpawn
#endif
#define OnPlayerSpawn RNPC_OnPlayerSpawn
forward RNPC_OnPlayerSpawn(playerid);
// The enum containing all data for a single policeman
enum RPol_enum {
RPOL_NPCID,
RPOL_TIMER,
Float: RPOL_WAYPOINTS_X[RPOL_MAX_WAYPOINTS],
Float: RPOL_WAYPOINTS_Y[RPOL_MAX_WAYPOINTS],
Float: RPOL_WAYPOINTS_Z[RPOL_MAX_WAYPOINTS],
RPOL_WPINDEX,
RPOL_NEXTWP,
RPOL_CURTARGET,
RPOL_SKIN
};

// Initial data
new rpol[MAX_RNPC_POLICE][RPol_enum] = {{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1},
{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1},
{-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1}, {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1} };

// Creates a new policeman
stock CreateRNPCPolice(name[], skin)
{
// Find a free spot in the rpol array
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == -1) {
slot = i;
break;
}
}
if (slot == -1) return -1;

// Connect the NPC
rpol[slot][RPOL_NPCID] = ConnectRNPC(name);
rpol[slot][RPOL_SKIN] = skin;
return slot;
}

// Adds a waypoint to the Policeman's path
stock AddRPOLWaypoint(rpolid, Float:x, Float:y, Float:z) {
if (rpol[rpolid][RPOL_NPCID] == -1) return false;
if (rpol[rpolid][RPOL_WPINDEX] >= RPOL_MAX_WAYPOINTS) return false;
// Store the waypoint coordinates at the last free position
new slot = rpol[rpolid][RPOL_WPINDEX];
rpol[rpolid][RPOL_WAYPOINTS_X][slot] = x;
rpol[rpolid][RPOL_WAYPOINTS_Y][slot] = y;
rpol[rpolid][RPOL_WAYPOINTS_Z][slot] = z;

rpol[rpolid][RPOL_WPINDEX]++;
return true;
}

stock StartRPOLRoute(rpolid)
{
// If valid and not already walking
if (rpol[rpolid][RPOL_TIMER] == -1 && rpol[rpolid][RPOL_NPCID] != -1) {
rpol[rpolid][RPOL_TIMER] = SetTimerEx("WatchTimer", RPOL_UPDATE, 1, "i", rpolid);
// Move to the first waypoint
MoveRNPC(rpol[rpolid][RPOL_NPCID], rpol[rpolid][RPOL_WAYPOINTS_X][0], rpol[rpolid][RPOL_WAYPOINTS_Y][0],
rpol[rpolid][RPOL_WAYPOINTS_Z][0], RNPC_SPEED_RUN);
return true;
}
return 0;
}

stock RemoveRNPCPolice(rpolid)
{
if (rpol[rpolid][RPOL_TIMER] > -1) {
// Stop timer
KillTimer(rpol[slot][RPOL_TIMER]);
}
// Kick the NPC
Kick(rpol[rpolid][RPOL_NPCID];
// Reset data
rpol[rpolid] = {-1, -1, 0.0, 0.0, 0.0, 0, 0, -1};
}

// This is the timer that actually controls the policeman
// and so the actually interesting "KI" for the RNPC
forward WatchTimer(id);
public WatchTimer(id) {
if (rpol[id][RPOL_CURTARGET] > -1) {
new Float:x, Float:y, Float:z;
GetPlayerPos(rpol[id][RPOL_CURTARGET], x, y ,z);
if (!IsPlayerInRangeOfPoint(rpol[id][RPOL_NPCID], RPOL_VISIONRANGE * 2.0, x, y, z)
|| GetPlayerState(rpol[id][RPOL_CURTARGET]) != PLAYER_STATE_ONFOOT) {
// Target escaped or died
// Stop shooting
RNPC_SetKeys(0);
// Continue route
MoveRNPC(rpol[id][RPOL_NPCID], rpol[id][RPOL_WAYPOINTS_X][rpol[id][RPOL_NEXTWP]],
rpol[id][RPOL_WAYPOINTS_Y][rpol[id][RPOL_NEXTWP]], rpol[id][RPOL_WAYPOINTS_Z][rpol[id][RPOL_NEXTWP]],
RNPC_SPEED_RUN);
rpol[id][RPOL_CURTARGET] = -1;
return;
} else
if (IsPlayerInRangeOfPoint(rpol[id][RPOL_NPCID], RPOL_ATTACKRANGE, x, y, z)) {
// Target is in attackrange
// Stop running and start shhoting
new Float:ox, Float:oy, Float:oz;
GetPlayerPos(rpol[id][RPOL_NPCID], ox, oy, oz);
// Angle to the target
new Float:angle = atan2(ox - x, oy - y) + 180.0;
// Stop and build, alternate slot for security
RNPC_StopPlayback(rpol[id][RPOL_NPCID]);
RNPC_CreateBuild(rpol[id][RPOL_NPCID], PLAYER_RECORDING_TYPE_ONFOOT, 1);
// Set weapon
RNPC_SetWeaponID(22);
// Set facing angle to the target
RNPC_SetAngleQuats(0.0, angle, 0.0);
// Start firing
RNPC_SetKeys(KEY_FIRE);
// Move towards the target from the current position
RNPC_ConcatMovement(x, y, z, RNPC_SPEED_RUN);
// Finish build
RNPC_FinishBuild();

// Start playback
RNPC_StartBuildPlayback(id, 1);

} else {
// Stop shooting
RNPC_SetKeys(0);
// Move towards the targets
MoveRNPC(rpol[id][RPOL_NPCID], x, y, z, RNPC_SPEED_RUN);
}
}
}

// Hook OnNPCPlaybackFinished to determine when a NPC reached his current waypoint
public OnRNPCPlaybackFinished(npcid)
{
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == npcid) {
slot = i;
break;
}
}
if (slot > -1) {
// NPC is a RNPC policeman
if (rpol[slot][RPOL_CURTARGET] == -1) {
// Increase current waypoint index, and set it to 0 when the last one is reached
rpol[slot][RPOL_NEXTWP] = (rpol[slot][RPOL_NEXTWP] + 1) % rpol[slot][RPOL_WPINDEX];
// Make him walk to the next waypoint
MoveRNPC(rpol[slot][RPOL_NPCID], rpol[slot][RPOL_WAYPOINTS_X][rpol[slot][RPOL_NEXTWP]],
rpol[slot][RPOL_WAYPOINTS_Y][rpol[slot][RPOL_NEXTWP]], rpol[slot][RPOL_WAYPOINTS_Z][rpol[slot][RPOL_NEXTWP]],
RNPC_SPEED_WALK);
}
}
CallLocalFunction("RNPC_OnRNPCPlaybackFinished", "i", npcid);
}
#if defined _ALS_OnRNPCPlaybackFinished
#undef OnRNPCPlaybackFinished
#else
#define _ALS_OnRNPCPlaybackFinished
#endif
#define OnRNPCPlaybackFinished RNPC_OnRNPCPlaybackFinished
forward RNPC_OnRNPCPlaybackFinished(npcid);

// Hook OnPlayerKeyStateChange to detect firing players
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
// Check if player started firing
if (!(oldkeys & KEY_FIRE) && (newkeys & KEY_FIRE)) {
// Check if player holds a gun
if (GetPlayerWeapon(playerid) > 16 && GetPlayerWeapon(playerid) < 40) {
new Float:px, Float:py, Float:pz;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
// Skip invalid and already following npcs
if (rpol[i][RPOL_NPCID] == -1 || rpol[i][RPOL_CURTARGET] > -1) continue;
GetPlayerPos(rpol[i][RPOL_NPCID], px, py, pz);
// If police in in range make him chase the attacking player
if (IsPlayerInRangeOfPoint(playerid, RPOL_VISIONRANGE, px, py, pz)) {
rpol[i][RPOL_CURTARGET] = playerid;
}
}
}
}
CallLocalFunction("RNPC_OnPlayerKeyStateChange", "iii", playerid, newkeys, oldkeys);
}
#if defined _ALS_OnPlayerKeyStateChange
#undef OnPlayerKeyStateChange
#else
#define _ALS_OnPlayerKeyStateChange
#endif
#define OnPlayerKeyStateChange RNPC_OnPlayerKeyStateChange
forward RNPC_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);

// Hook OnPlayerSpawn to set the NPCs skin
public OnPlayerSpawn(playerid)
{
if (IsPlayerNPC(playerid)) {
// Find the array index of the npc
new slot = -1;
for (new i = 0; i < MAX_RNPC_POLICE; i++) {
if (rpol[i][RPOL_NPCID] == playerid) {
slot = i;
break;
}
}
// If playerid is a policeman
if (slot > -1) {
SetPlayerSkin(playerid, rpol[slot][RPOL_SKIN]);
}
}
CallLocalFunction("RNPC_OnPlayerSpawn", "i", playerid);
return 1;
}

Do u know this error??

http://i63.tinypic.com/2qjkegn.png

bookknp
20/07/2018, 04:30 PM
Bump

bookknp
20/07/2018, 11:46 PM
I solve it, the RNPCPolice only join if u have samp VERSION 0.3e!!!

bookknp
21/07/2018, 04:56 AM
If dont spawn RNPCPolice cause is file called sampnpc.exe surely no i have It. Search in ****** sampnpc.exe 0.3.7 R2 anda download It and copy in samp server carpet...

Mauzen, 1) what is te way for spawn RNPCPolice in an Zone?? for example SetPlayerPos(rp,...); i dont know if could i use it?

Other question, 2) the weapon of RNPCPolice dont hurt me, why??

Thx for all Mauzen, +rep