25.01.2019, 20:26
Yeah I see what you mean I guess I overlooked this line.
Anyways that brings me to another point. You can eliminate most of your loops which find the correct NPC very easily.
All you need to do is create a reference array.
Then what you do is when creating an NPC simply set copid to the index of NPCID
Now all those loops become this.
Old way
New way
Код:
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);