Quote:
Originally Posted by AtomicStryker
I included Frameskips and made it as easy to run as possible. Im quite certain you could run 100 instances of the plugin without slowing a server down
|
Well I am going to assume it's just not possible to do this without OnGameFrame. That being said your OnGameFrame has a lot of redundant checks.
PHP Code:
if (!IsClientInGame(target)) continue;
if (GetClientTeam(target) != 2) continue;
if (!IsPlayerAlive(target)) continue;
It loops from 1,MaxClients every time and skips all the "invalid" clients. However if we consider the typical situation of 4 alive survivors, 18 maxclients, that means you're skipping 66.66% of the time. Plus calling extra natives which is relatively expensive.
By doing something like this you can reclaim a 66% speedup.
PHP Code:
#define MAX_SUPPORTED_CLIENTS 32
new survivor_clients[MAX_SUPPORTED_CLIENTS];
new survivor_count = 0;
FindSurvivorIdx(client)
{
for(new i = 0; i < survivor_count; ++i)
if(survivor_clients[i] == client) return i;
return 0;
}
SwapArrayElements(array[], a, b)
{
if(a == b) return;
new tmp = array[a];
array[a] = array[b];
array[b] = tmp;
}
//call this when player connects AND hes a survivor AND hes alive
OnPlayerJoinSurvivors(client)
{
if(!FindSurvivorIdx(client))
survivor_clients[survivor_count++] = client;
}
//call this when a player disconnects OR hes not a survivor OR hes not alive
OnPlayerLeaveSurvivors(client)
{
new idx = FindSurvivorIdx(client);
//keep the array contiguous
if(idx)
{
SwapArrayElements(survivor_clients, idx, survivor_count-1);
survivor_count--;
}
}
////////////
public OnGameFrame()
{
//early out checks as before
for(new idx = 0; idx < survivor_count; i++)
{
new target = survivor_clients[idx];
new level = GetEntData(target, WaterOffset, 1);
// etc rest of this is the same as before
}
}