09.01.2013, 20:46
(
Last edited by badnum23; 09/01/2013 at 09:59 PM.
Reason: a little mistake in RemovePlayerFromVehicle
)
...and without this check IsPlayerConnected(playerid). I want to tell you how to make loops a little bit faster.
The base
First of all. Create a two variables and one define.
And then add two this functions:
Ok. Next step is to add some code to OnPlayerConnect and OnPlayerDisconnect publics.
As you can see pListPush added in the start of the public and pListPop in the end.
How to use?
Simply. For example you have some loop, something like this:
You should make it looks like this:
One more example
and...
I hope you will use it in your gamemode. Just imagine how faster would work GodFather based gamemodes, if you replaced all the loops, lol.
The base
First of all. Create a two variables and one define.
Code:
new pList[MAX_PLAYERS], pListSize; #define pLoop(%0) for (new %0 = 0; %0 < pListSize; %0++)
Code:
pListPush(playerid) { pList[pListSize] = playerid; pListSize++; } pListPop(playerid) { new i,j; for (i = 0; i < pListSize; i++) if (playerid == pList[i]) { j = i; break; } for (i = j; i < pListSize-1; i++) pList[i] = pList[i+1]; pListSize--; }
Code:
public OnPlayerConnect(playerid) { pListPush(playerid); // your code return 1; } public OnPlayerDisconnect(playerid) { // your code pListPop(playerid); return 1; }
How to use?
Simply. For example you have some loop, something like this:
Code:
for (new i = 0; i < MAX_PLAYERS; i++) { if (IsPlayerConnected(i)) { .... } }
Code:
new i; pLoop(j) { i = pList[j]; // some of your old code... }
Code:
for (new i = 0; i < MAX_PLAYERS; i++) if (IsPlayerConnected(i)) RemovePlayerFromVehicle(i);
Code:
pLoop(i) RemovePlayerFromVehicle(pList[i]);