[Include] Cops
#10

Okay here we go.

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];
IsCopValid() should return 1 if successful. There are other functions with this problem as well.
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;
}
Why bother calling so many functions before checking if the NPC is actually valid? Check if the NPC is valid first then create.

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;
Missing array bounds checking.
Code:
GetCopTarget(cop_id)
{
    return e_cops[cop_id][cop_target];
}
Why are you calling this function twice?
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;
}
Major fuck-up here.
Code:
public FCNPC_OnUpdate(npcid)
{
    new Float:x, Float:y, Float:z;
    for(new k = 0; k < MAX_COPS; k++)
    {
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?
Code:
public OnPlayerDeath(playerid, killerid, reason)
Reply


Messages In This Thread
Cops AI - by Lokii - 23.01.2019, 15:00
Re: Cops - by Pottus - 23.01.2019, 15:34
Re: Cops - by Lokii - 23.01.2019, 15:51
Re: Cops - by Hazon - 23.01.2019, 18:27
Re: Cops - by Lokii - 23.01.2019, 18:45
Re: Cops - by Lucky13 - 23.01.2019, 19:27
Re: Cops - by Lokii - 23.01.2019, 19:28
Re: Cops - by N0FeaR - 23.01.2019, 20:24
Re: Cops - by Lokii - 23.01.2019, 20:27
Re: Cops - by Pottus - 24.01.2019, 18:05
Re: Cops - by Lokii - 25.01.2019, 15:53
Re: Cops - by codExpert - 25.01.2019, 16:01
Re: Cops - by Lokii - 25.01.2019, 16:05
Re: Cops - by Pottus - 25.01.2019, 20:26
Re: Cops - by Lokii - 25.01.2019, 20:33
Re: Cops - by Lokii - 28.01.2019, 12:55

Forum Jump:


Users browsing this thread: 1 Guest(s)