#define FILTERSCRIPT #include <a_samp> #include <fcnpc> #include <cops> //requires fcnpc 2.0.0
CRIME_KILL 0 //called only if you kill players, for cops use oncopdeath CRIME_SHOOT 1 CRIME_DAMAGE 2 //called only if you shoot players, for cops use oncoptakedamage
native CreateCop(skinid, name[], Float:detection_area, Float:health, Float:x, Float:y, Float:z, Float:angle, weapon, Float:accuracy); native IsCopDead(cop_id); native IsCopInvulnerable(cop_id); native IsCopMoving(cop_id); native IsCopValid(cop_id); native GetCopHealth(cop_id); native GetCopTarget(cop_id); native GetClosestPlayerToCop(cop_id); native GetCopDetectionArea(cop_id); native GetCopPos(cop_id, &Float:x, &Float:y, &Float:z); native GetCopAngle(cop_id, &Float:angle); native GetCopCreationPos(cop_id, &Float:x, &Float:y, &Float:z); native GetCopCreationAngle(cop_id, &Float:angle); native GetCopInterior(cop_id); native GetCopVirtualWorld(cop_id); native GetCopSkin(cop_id); native GetCopCustomSkin(cop_id); native GetCopWeapon(cop_id); native SetCopWeapon(cop_id, weaponid); native SetCopInvulnerable(cop_id, bool:invulnerable); native SetCopSkin(cop_id, skinid); native SetCopInterior(cop_id, interiorid); native SetCopVirtualWorld(cop_id, worldid); native SetCopHealth(cop_id, Float:health); native RespawnCop(cop_id); native DestroyCop(cop_id);
OnCopDeath(cop_id, killerid, weaponid); OnCopTakeDamage(cop_id, damagerid, weaponid, bodypart, Float:health_loss); OnCopKillPlayer(cop_id, playerid); OnCrimeHappenNearCop(playerid, crime);
#define FILTERSCRIPT
#include <a_samp>
#include <fcnpc>
#include <cops>
#include <zcmd>
new cop;
CMD:cop(playerid)
{
new Float:x, Float:y, Float:z;
if(!IsCopValid(cop)) //you could do without the check as well the include checks if cop allready exist
{
GetPlayerPos(playerid, x, y, z);
cop = CreateCop(284, "Cop01", 45.0, 100.0, x+4, y, z, -1, 22, 1.0);
}
return 1;
}
CMD:dcop(playerid)
{
if(IsCopValid(cop)) //could do without the check as well
{
DestroyCop(cop);
}
return 1;
}
public OnCrimeHappenNearCop(playerid, crime)
{
switch(crime)
{
case CRIME_KILL:
{
if(GetPlayerWantedLevel(playerid) < 5)
{
SetPlayerWantedLevel(playerid, 5);
}
}
case CRIME_SHOOT:
{
if(GetPlayerWantedLevel(playerid) < 2)
{
SetPlayerWantedLevel(playerid, 2);
}
}
case CRIME_DAMAGE:
{
if(GetPlayerWantedLevel(playerid) < 3)
{
SetPlayerWantedLevel(playerid, 3);
}
}
}
return 1;
}
public OnCopKillPlayer(cop_id, playerid)
{
if(GetPlayerWantedLevel(playerid) > 1)
{
SetPlayerWantedLevel(playerid, 0);
}
return 1;
}
Dont have time to look it over but IsValidCop has no array bounds checking
|
new e_cops[MAX_COPS][ee_cops];
stock GetCopCreationPos(cop_id, &Float:x, &Float:y, &Float:z) { if(IsCopValid(cop_id)) { x = e_cops[cop_id][cop_pos_x]; y = e_cops[cop_id][cop_pos_y]; z = e_cops[cop_id][cop_pos_z]; } return 0; }
CreateCop()[ ...... new id; for(new i = 0; i < MAX_COPS; i++) { if(IsCopValid(i)) continue; id = FCNPC_Create(name); if(FCNPC_IsValid(e_cops[i][copid])) { e_cops[i][copid] = id; FCNPC_Spawn(e_cops[i][copid], skinid, x, y, z); FCNPC_SetHealth(e_cops[i][copid], health); FCNPC_SetAngle(e_cops[i][copid], angle); FCNPC_SetWeaponAccuracy(e_cops[i][copid], weapon, accuracy); FCNPC_SetWeapon(e_cops[i][copid], weapon); FCNPC_UseInfiniteAmmo(e_cops[i][copid], true); e_cops[i][cop_pos_x] = x; e_cops[i][cop_pos_y] = y; e_cops[i][cop_pos_z] = z; e_cops[i][cop_angle] = angle; e_cops[i][cop_detection] = detection_area; e_cops[i][cop_target] = 0xFFFF; e_cops[i][cop_exist] = true; return i; } } return 0xFFFF;
GetCopTarget(cop_id) { return e_cops[cop_id][cop_target]; }
if(GetPlayerDistanceFromPoint(i, x, y, z) >= last) continue; last = GetPlayerDistanceFromPoint(i, x, y, z);
new Float:tmp; for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) { if(!IsPlayerConnected(i) || IsPlayerNPC(i)) continue; tmp = GetPlayerDistanceFromPoint(i, x, y, z); if(tmp >= last) continue; last = tmp; id = i; }
public FCNPC_OnUpdate(npcid) { new Float:x, Float:y, Float:z; for(new k = 0; k < MAX_COPS; k++) {
public OnPlayerDeath(playerid, killerid, reason)
fixed all of these except those:
Major fuck-up here. Код:
public FCNPC_OnUpdate(npcid) { new Float:x, Float:y, Float:z; for(new k = 0; k < MAX_COPS; k++) { Why bother doing anything until you check if the killerid is an NPC? Код:
public OnPlayerDeath(playerid, killerid, reason) |
i think that you should use more includes in your include, that would make it more readable, for example y_hooks, y_iterate
function names could also be a little bit better |
if(e_cops[k][copid] != npcid) continue;
g_CopReferences[MAX_PLAYERS] = { -1, ... };
e_cops[i][copid] = FCNPC_Create(name); g_CopReferences[e_cops[i][copid]] = i;
for(new i = 0; i < MAX_COPS; i++) { if(!IsCopValid(i) || e_cops[i][copid] != npcid) continue; CallLocalFunction("OnCopDeath", "iii", i, killerid, reason); }
// Yes this is a cop! if(g_CopReferences[npcid] != -1) CallLocalFunction("OnCopDeath", "iii", g_CopReferences[npcid], killerid, reason);
Yeah I see what you mean I guess I overlooked this line.
Код:
if(e_cops[k][copid] != npcid) continue; All you need to do is create a reference array. Код:
g_CopReferences[MAX_PLAYERS] = { -1, ... }; Код:
e_cops[i][copid] = FCNPC_Create(name); g_CopReferences[e_cops[i][copid]] = i; Old way Код:
for(new i = 0; i < MAX_COPS; i++) { if(!IsCopValid(i) || e_cops[i][copid] != npcid) continue; CallLocalFunction("OnCopDeath", "iii", i, killerid, reason); } New way Код:
// Yes this is a cop! if(g_CopReferences[npcid] != -1) CallLocalFunction("OnCopDeath", "iii", g_CopReferences[npcid], killerid, reason); |