Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // Foreach (fast loop in arrays)
- // Author: Bruno da Silva
- // www.ips-team.blogspot.com
- //
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- #define newItterArray:%0<%1> ipsArray%0[%1] = {-1, ...}, ipsInit%0 = -1, ipsFinal%0 = 0
- #define addItterArray:%0<%1> intervalChangeItter(ipsArray%0, %1, ipsInit%0, ipsFinal%0)
- #define delItterArray:%0<%1> intervalDeleteItter(ipsArray%0, %1, ipsInit%0, ipsFinal%0)
- #define getItterArray:%0<%1> ipsArray%0[%1]
- #define foreach(%0,%1) for(new %1 = ipsInit%0 ; %1 != -1; %1 = ipsArray%0[%1])
- new newItterArray:Player<MAX_PLAYERS>;
- intervalChangeItter(array[], valor, &inicio, &ultimoNumeroVar)
- {
- if(array[valor] != -1 || valor == -1) {
- return false;
- }
- if(inicio == -1) {
- return inicio = valor, true;
- }
- if(valor < inicio) {
- return array[valor] = inicio, inicio = valor, true;
- }
- if(array[inicio] == -1) {
- return array[inicio] = valor, ultimoNumeroVar = valor;
- }
- return array[ultimoNumeroVar] = valor, ultimoNumeroVar = valor, true;
- }
- intervalDeleteItter(array[], value, &inicio, &ultimoNumeroVar)
- {
- if(inicio == -1 || value == -1) {
- return false;
- }
- if(inicio == value) {
- return inicio = -1, array[value] = -1, true;
- }
- ultimoNumeroVar = 0;
- for( ; array[ultimoNumeroVar] != value; ultimoNumeroVar = array[ultimoNumeroVar]) {
- if(ultimoNumeroVar == -1) return false;
- }
- return array[ultimoNumeroVar] = array[value], array[value] = -1, true;
- }
- public OnPlayerConnect(playerid)
- {
- addItterArray:Player<playerid>;
- return CallLocalFunction("CallOnPlayerConnect", "i", playerid);
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- delItterArray:Player<playerid>;
- return CallLocalFunction("CallOnPlayerDisconnect", "ii", playerid, reason);
- }
- #if defined HookOnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define HookOnPlayerConnect
- #endif
- #define OnPlayerConnect CallOnPlayerConnect
- #if defined HookOnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define HookOnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect CallOnPlayerDisconnect
- forward OnPlayerConnect(playerid);
- forward OnPlayerDisconnect(playerid, reason);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement