24.01.2019, 18:05
(
Last edited by Pottus; 24/01/2019 at 06:39 PM.
)
Okay here we go.
Should be static to maintain encapsulation. Shouldn't be able to be modified outside of include unless calling functions directly.
IsCopValid() should return 1 if successful. There are other functions with this problem as well.
Why bother calling so many functions before checking if the NPC is actually valid? Check if the NPC is valid first then create.
Missing array bounds checking.
Why are you calling this function twice?
Major fuck-up here.
I don't even see npcid used at all, you are basically using this callback like a timer! That means you are doing as many times more work as the number of cops that are spawned!
Why bother doing anything until you check if the killerid is an NPC?
Should be static to maintain encapsulation. Shouldn't be able to be modified outside of include unless calling functions directly.
Code:
new e_cops[MAX_COPS][ee_cops];
Code:
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; }
Code:
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;
Code:
GetCopTarget(cop_id) { return e_cops[cop_id][cop_target]; }
Code:
if(GetPlayerDistanceFromPoint(i, x, y, z) >= last) continue; last = GetPlayerDistanceFromPoint(i, x, y, z);
Code:
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; }
Code:
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?
Code:
public OnPlayerDeath(playerid, killerid, reason)