| #if defined _FOREACH_LOCAL_VERSION
|
| #endinput
|
| #endif
|
| #define _FOREACH_LOCAL_VERSION 19
|
| #if defined _FOREACH_INC_TEST
|
| #endinput
|
| #endif
|
| #define _FOREACH_INC_TEST
|
| #if !defined _samp_included
|
| #error "Please include a_samp or a_npc before foreach"
|
| #endif
|
| #if defined SendChat || defined FOREACH_NO_PLAYERS
|
| #define BOTSYNC_IS_BOT (true)
|
| #endif
|
| #if defined IsPlayerNPC
|
| #define _FOREACH_BOT
|
| #endif
|
| #define ITER_NONE -1
|
| #define _Y_ITER_ARRAY: _:_Y_ITER_C0:
|
| #define _Y_ITER_ARRAY_SIZE(%1) _:_Y_ITER_C1:_Y_ITER_C2:sizeof %1@YSII_Ag-1
|
| #define _Y_ITER_C0:%0[%1]@YSII_%4g%3) %0@YSII_%4g[%1]%3)
|
| #define _Y_ITER_C1:_Y_ITER_C2:%0[%1]@YSII_Ag%3) %0@YSII_Ag[]%3)
|
| #define _Y_ITER_C2:sizeof%0(%1)@YSII_Ag-1
|
| #define _Y_ITER_C3:%0[%1]@YSII_Cg,%2[%3]@YSII_Ag[%4]={%5} _Y_ITER_C3:%0@YSII_Cg[%1],%0@YSII_Ag[%1][%4]
|
| #if !defined BOTSYNC_IS_BOT
|
| static stock
|
| YSI_g_sCallbacks = 0 |
| forward Iter_OPDCInternal(playerid) |
| #if !defined FOREACH_I_Vehicle
|
| #define FOREACH_I_Vehicle 1
|
| #endif
|
| #else
|
| #if !defined FOREACH_I_Vehicle
|
| #define FOREACH_I_Vehicle 0
|
| #endif
|
| #endif
|
| #define IteratorArray:%1[%2]<%3> %1@YSII_Cg[%2],%1@YSII_Ag[%2][%3+1]
|
| #define Iterator:%1<%2> _Y_ITER_C3:%1@YSII_Cg,%1@YSII_Ag[(%2)+1]={(%2)*2,(%2)*2-1,...}
|
| #define iterator%0<%1> new Iterator:%0<%1>
|
| #define Iter_Init(%1) \
|
| Iter_InitInternal(%1@YSII_Ag,sizeof %1@YSII_Ag,sizeof %1@YSII_Ag[]-1)
|
| #define Iter_Add(%1,%2) Iter_AddInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,%2,_Y_ITER_ARRAY_SIZE(%1))
|
| #define Iter_Free(%1) Iter_FreeInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1))
|
| #define Iter_Remove(%1,%2) Iter_RemoveInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,%2,_Y_ITER_ARRAY_SIZE(%1))
|
| #define Iter_Contains(%1,%2) Iter_ContainsInternal(_Y_ITER_ARRAY:%1@YSII_Ag,%2,_Y_ITER_ARRAY_SIZE(%1))
|
| #define Iter_SafeRemove(%1,%2,%3) Iter_SafeRemoveInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,%2,%3,_Y_ITER_ARRAY_SIZE(%1))
|
| #define Iter_Random(%1) Iter_RandomInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1))
|
| #define Iter_Count(%1) (_Y_ITER_ARRAY:%1@YSII_Cg)
|
| #define Iter_Clear(%1) Iter_ClearInternal(_Y_ITER_ARRAY:%1@YSII_Cg,_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1))
|
| #if !defined BOTSYNC_IS_BOT
|
| new
|
| Iterator:Player<MAX_PLAYERS>,
|
| Iterator:Actor<MAX_ACTORS> |
| #if FOREACH_I_Vehicle
|
| new Iterator:Vehicle<MAX_VEHICLES> |
| #endif
|
| #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
|
| new
|
| Iterator:Bot<MAX_PLAYERS>,
|
| Iterator:Character<MAX_PLAYERS> |
| #define NPC@YSII_Cg Bot@YSII_Cg
|
| #define NPC@YSII_Ag Bot@YSII_Ag
|
| #endif
|
| #endif
|
| static stock
|
| YSI_gsOnPlayerConnect[] = "Iter_OnPlayerConnect",
|
| YSI_gsOnPlayerDisconnect[] = "Iter_OnPlayerDisconnect",
|
| YSI_gsOnGameModeInit[] = "Iter_OnGameModeInit",
|
| YSI_OnFilterScriptInit[] = "Iter_OnFilterScriptInit",
|
| YSI_gsSpecifier@[] = "",
|
| YSI_gsSpecifier@i[] = "i" |
| #define foreach%1(%0) for(new Y_FOREACH_SECOND|||Y_FOREACH_THIRD|||%0|||)
|
| #define new%0|||%9|||%1:%2||| %9|||%0|||%1|||%2|||
|
| #define Y_FOREACH_THIRD|||%0|||%1|||%2||| %1=Y_FOREACH_FIFTH|||Y_FOREACH_FOURTH|||%1:%2|||
|
| #define Y_FOREACH_FOURTH|||%0=Y_FOREACH_FIFTH|||%1|||%2||| new Y_FOREACH_SIXTH
|
| #define Y_FOREACH_SEVENTH|||%9Y_FOREACH_SIXTH
|
| #define Y_FOREACH_SIXTH
|
| #define Y_FOREACH_FIFTH|||Y_FOREACH_FOURTH|||%1:%2||| _Y_ITER_ARRAY_SIZE(%2)
|
| #define Y_FOREACH_SECOND|||Y_FOREACH_THIRD|||%1,%2||| %2=_Y_ITER_ARRAY_SIZE(%1)
|
| #define foreachex(%1,%2) foreach(%2:%1)
|
| stock Iter_ScriptInit()
|
| {
|
| Iter_Clear(Player) |
| #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
|
| Iter_Clear(Bot) |
| Iter_Clear(Character) |
| #endif
|
| #if FOREACH_I_Vehicle
|
| Iter_Clear(Vehicle) |
| for(new vehicleid = 1
|
| if(!GetVehicleModel(vehicleid)) {
|
| continue |
| }
|
| Iter_Add(Vehicle, vehicleid) |
| }
|
| #endif
|
| Iter_Clear(Actor) |
| for(new actorid = 0
|
| if(!IsValidActor(actorid)) {
|
| continue |
| }
|
| Iter_Add(Actor, actorid) |
| }
|
| if(funcidx(YSI_gsOnPlayerDisconnect) != -1) {
|
| YSI_g_sCallbacks |= 1 |
| }
|
| if(funcidx(YSI_gsOnPlayerConnect) != -1) {
|
| YSI_g_sCallbacks |= 2 |
| }
|
| }
|
| #if !defined BOTSYNC_IS_BOT
|
| public OnFilterScriptInit()
|
| {
|
| Iter_ScriptInit() |
| #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
|
| Bot@YSII_Cg = _Y_ITER_C3:0 |
| Character@YSII_Cg = _Y_ITER_C3:0 |
| new
|
| lastBot = MAX_PLAYERS,
|
| lastCharacter = MAX_PLAYERS |
| #endif
|
| Player@YSII_Cg = _Y_ITER_C3:0 |
| new
|
| lastPlayer = MAX_PLAYERS |
| for(new i = 0
|
| if(IsPlayerConnected(i)) {
|
| #if defined _FOREACH_BOT
|
| if(!IsPlayerNPC(i)) {
|
| Player@YSII_Ag[lastPlayer] = i |
| ++Player@YSII_Cg |
| lastPlayer = i |
| }
|
| #if !defined FOREACH_NO_BOTS
|
| else {
|
| Bot@YSII_Ag[lastBot] = i |
| ++Bot@YSII_Cg |
| lastBot = i |
| }
|
| #pragma tabsize 4
|
| Character@YSII_Ag[lastCharacter] = i |
| ++Character@YSII_Cg |
| lastCharacter = i |
| #endif
|
| #else
|
| Player@YSII_Ag[lastPlayer] = i |
| ++Player@YSII_Cg |
| lastPlayer = i |
| #endif
|
| } else {
|
| #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
|
| Bot@YSII_Ag[i] = MAX_PLAYERS + 1 |
| Character@YSII_Ag[i] = MAX_PLAYERS + 1 |
| #endif
|
| Player@YSII_Ag[i] = MAX_PLAYERS + 1 |
| }
|
| }
|
| #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
|
| Bot@YSII_Ag[lastPlayer] = MAX_PLAYERS |
| Character@YSII_Ag[lastPlayer] = MAX_PLAYERS |
| #endif
|
| Player@YSII_Ag[lastPlayer] = MAX_PLAYERS |
| CallLocalFunction(YSI_OnFilterScriptInit, YSI_gsSpecifier@) |
| return 1 |
| }
|
| #if defined _ALS_OnFilterScriptInit
|
| #undef OnFilterScriptInit
|
| #else
|
| #define _ALS_OnFilterScriptInit
|
| #endif
|
| #define OnFilterScriptInit Iter_OnFilterScriptInit
|
| forward OnFilterScriptInit() |
| #endif
|
| #if !defined BOTSYNC_IS_BOT
|
| public OnGameModeInit()
|
| {
|
| Iter_ScriptInit() |
| #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
|
| Bot@YSII_Cg = _Y_ITER_C3:0 |
| Bot@YSII_Ag[MAX_PLAYERS] = MAX_PLAYERS |
| Character@YSII_Ag[MAX_PLAYERS] = MAX_PLAYERS |
| Character@YSII_Cg = _Y_ITER_C3:0 |
| new
|
| lastBot = MAX_PLAYERS,
|
| lastCharacter = MAX_PLAYERS |
| #endif
|
| Player@YSII_Cg = _Y_ITER_C3:0 |
| Player@YSII_Ag[MAX_PLAYERS] = MAX_PLAYERS |
| new
|
| lastPlayer = MAX_PLAYERS |
| for(new i = 0
|
| if(IsPlayerConnected(i)) {
|
| #if defined _FOREACH_BOT
|
| if(!IsPlayerNPC(i)) {
|
| Player@YSII_Ag[lastPlayer] = i |
| ++Player@YSII_Cg |
| lastPlayer = i |
| }
|
| #if !defined FOREACH_NO_BOTS
|
| else {
|
| Bot@YSII_Ag[lastBot] = i |
| ++Bot@YSII_Cg |
| lastBot = i |
| }
|
| #pragma tabsize 4
|
| Character@YSII_Ag[lastCharacter] = i |
| ++Character@YSII_Cg |
| lastCharacter = i |
| #endif
|
| #else
|
| Player@YSII_Ag[lastPlayer] = i |
| ++Player@YSII_Cg |
| lastPlayer = i |
| #endif
|
| } else {
|
| #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
|
| Bot@YSII_Ag[i] = MAX_PLAYERS + 1 |
| Character@YSII_Ag[i] = MAX_PLAYERS + 1 |
| #endif
|
| Player@YSII_Ag[i] = MAX_PLAYERS + 1 |
| }
|
| }
|
| #if defined _FOREACH_BOT && !defined FOREACH_NO_BOTS
|
| Bot@YSII_Ag[lastPlayer] = MAX_PLAYERS |
| Character@YSII_Ag[lastPlayer] = MAX_PLAYERS |
| #endif
|
| Player@YSII_Ag[lastPlayer] = MAX_PLAYERS |
| CallLocalFunction(YSI_gsOnGameModeInit, YSI_gsSpecifier@) |
| return 1 |
| }
|
| #if defined _ALS_OnGameModeInit
|
| #undef OnGameModeInit
|
| #else
|
| #define _ALS_OnGameModeInit
|
| #endif
|
| #define OnGameModeInit Iter_OnGameModeInit
|
| forward OnGameModeInit() |
| #endif
|
| #if !defined BOTSYNC_IS_BOT
|
| public OnPlayerConnect(playerid)
|
| {
|
| #if defined _FOREACH_BOT
|
| if(!IsPlayerNPC(playerid)) {
|
| Iter_Add(Player, playerid) |
| }
|
| #if !defined FOREACH_NO_BOTS
|
| else {
|
| Iter_Add(Bot, playerid) |
| }
|
| #pragma tabsize 4
|
| Iter_Add(Character, playerid) |
| #endif
|
| #else
|
| Iter_Add(Player, playerid) |
| #endif
|
| if(YSI_g_sCallbacks & 2) {
|
| CallLocalFunction(YSI_gsOnPlayerConnect, YSI_gsSpecifier@i, playerid) |
| }
|
| return 1 |
| }
|
| #if defined _ALS_OnPlayerConnect
|
| #undef OnPlayerConnect
|
| #else
|
| #define _ALS_OnPlayerConnect
|
| #endif
|
| #define OnPlayerConnect Iter_OnPlayerConnect
|
| forward OnPlayerConnect(playerid) |
| #endif
|
| #if !defined BOTSYNC_IS_BOT
|
| public OnPlayerDisconnect(playerid, reason)
|
| {
|
| if(YSI_g_sCallbacks & 1) {
|
| CallLocalFunction(YSI_gsOnPlayerDisconnect, "ii", playerid, reason) |
| }
|
| SetTimerEx("Iter_OPDCInternal", 0, false, YSI_gsSpecifier@i, playerid) |
| return 1 |
| }
|
| #if defined _ALS_OnPlayerDisconnect
|
| #undef OnPlayerDisconnect
|
| #else
|
| #define _ALS_OnPlayerDisconnect
|
| #endif
|
| #define OnPlayerDisconnect Iter_OnPlayerDisconnect
|
| forward OnPlayerDisconnect(playerid, reason) |
| #endif
|
| #if !defined BOTSYNC_IS_BOT
|
| public Iter_OPDCInternal(playerid)
|
| {
|
| if(IsPlayerConnected(playerid)) {
|
| return |
| }
|
| #if defined _FOREACH_BOT
|
| if(!IsPlayerNPC(playerid)) {
|
| Iter_Remove(Player, playerid) |
| }
|
| #if !defined FOREACH_NO_BOTS
|
| else {
|
| Iter_Remove(Bot, playerid) |
| }
|
| #pragma tabsize 4
|
| Iter_Remove(Character, playerid) |
| #endif
|
| #else
|
| Iter_Remove(Player, playerid) |
| #endif
|
| }
|
| #endif
|
| #if FOREACH_I_Vehicle
|
| stock Iter_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay, addsiren = 0)
|
| {
|
| new
|
| ret = CreateVehicle(modelid, x, y, z, angle, color1, color2, respawn_delay, !!addsiren) |
| if(ret != INVALID_VEHICLE_ID && ret != 0) {
|
| Iter_Add(Vehicle, ret) |
| }
|
| return ret |
| }
|
| #if defined _ALS_CreateVehicle
|
| #undef CreateVehicle
|
| #else
|
| #define _ALS_CreateVehicle
|
| #endif
|
| #define CreateVehicle Iter_CreateVehicle
|
| stock Iter_AddStaticVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2)
|
| {
|
| new
|
| ret = AddStaticVehicle(modelid, x, y, z, angle, color1, color2) |
| if(ret != INVALID_VEHICLE_ID) {
|
| Iter_Add(Vehicle, ret) |
| }
|
| return ret |
| }
|
| #if defined _ALS_AddStaticVehicle
|
| #undef AddStaticVehicle
|
| #else
|
| #define _ALS_AddStaticVehicle
|
| #endif
|
| #define AddStaticVehicle Iter_AddStaticVehicle
|
| stock Iter_AddStaticVehicleEx(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay, addsiren = 0)
|
| {
|
| new
|
| ret = AddStaticVehicleEx(modelid, x, y, z, angle, color1, color2, respawn_delay, !!addsiren) |
| if(ret != INVALID_VEHICLE_ID) {
|
| Iter_Add(Vehicle, ret) |
| }
|
| return ret |
| }
|
| #if defined _ALS_AddStaticVehicleEx
|
| #undef AddStaticVehicleEx
|
| #else
|
| #define _ALS_AddStaticVehicleEx
|
| #endif
|
| #define AddStaticVehicleEx Iter_AddStaticVehicleEx
|
| stock DestroyVehicleSafe(&vehicleid)
|
| {
|
| new success = DestroyVehicle(vehicleid) |
| Iter_SafeRemove(Vehicle, vehicleid, vehicleid) |
| return success |
| }
|
| stock Iter_DestroyVehicle(vehicleid)
|
| {
|
| Iter_Remove(Vehicle, vehicleid) |
| return DestroyVehicle(vehicleid) |
| }
|
| #if defined _ALS_DestroyVehicle
|
| #undef DestroyVehicle
|
| #else
|
| #define _ALS_DestroyVehicle
|
| #endif
|
| #define DestroyVehicle Iter_DestroyVehicle
|
| #endif
|
| #if !defined BOTSYNC_IS_BOT
|
| stock Iter_CreateActor(modelid, Float:x, Float:y, Float:z, Float:zAngle)
|
| {
|
| new
|
| ret = CreateActor(modelid, x, y, z, zAngle) |
| if(ret != INVALID_ACTOR_ID) {
|
| Iter_Add(Actor, ret) |
| }
|
| return ret |
| }
|
| #if defined _ALS_CreateActor
|
| #undef CreateActor
|
| #else
|
| #define _ALS_CreateActor
|
| #endif
|
| #define CreateActor Iter_CreateActor
|
| stock DestroyActorSafe(&actorid)
|
| {
|
| new success = DestroyActor(actorid) |
| Iter_SafeRemove(Actor, actorid, actorid) |
| return success |
| }
|
| stock Iter_DestroyActor(actorid)
|
| {
|
| Iter_Remove(Actor, actorid) |
| return DestroyActor(actorid) |
| }
|
| #if defined _ALS_DestroyActor
|
| #undef DestroyActor
|
| #else
|
| #define _ALS_DestroyActor
|
| #endif
|
| #define DestroyActor Iter_DestroyActor
|
| #endif
|
| stock Iter_RandomInternal(count, const array[], size)
|
| {
|
| if(count == 0) {
|
| return ITER_NONE |
| }
|
| new
|
| rnd = random(count),
|
| cur = array[size] |
| while(cur != size) {
|
| if(rnd-- == 0) {
|
| return cur |
| }
|
| cur = array[cur] |
| }
|
| return ITER_NONE |
| }
|
| stock Iter_FreeInternal(const array[], size)
|
| {
|
| for(new i = 0
|
| if(array[i] > size) {
|
| return i |
| }
|
| }
|
| return ITER_NONE |
| }
|
| stock Iter_AddInternal(&count, array[], value, size)
|
| {
|
| if(0 <= value < size && array[value] > size) {
|
| new
|
| last = size,
|
| next = array[last] |
| while(next < value) {
|
| last = next |
| next = array[last] |
| }
|
| array[last] = value |
| array[value] = next |
| ++count |
| return 1 |
| }
|
| return 0 |
| }
|
| stock Iter_RemoveInternal(&count, array[], value, size)
|
| {
|
| new
|
| last |
| return Iter_SafeRemoveInternal(count, array, value, last, size) |
| }
|
| stock Iter_SafeRemoveInternal(&count, array[], value, &last, size)
|
| {
|
| if(0 <= value < size && array[value] <= size) {
|
| last = size |
| new
|
| next = array[last] |
| while(next < size) {
|
| if(next == value) {
|
| array[last] = array[value] |
| array[value] = size + 1 |
| --count |
| return 1 |
| }
|
| last = next |
| next = array[last] |
| }
|
| }
|
| return 0 |
| }
|
| stock Iter_ContainsInternal(const array[], value, size)
|
| {
|
| return 0 <= value < size && array[value] <= size |
| }
|
| stock Iter_ClearInternal(&count, array[], size)
|
| {
|
| for(new i = 0, t = size + 1
|
| array[i] = t |
| }
|
| array[size] = size |
| count = 0 |
| }
|
| stock Iter_InitInternal(arr[][], s0, s1)
|
| {
|
| for(new i = 0, t = s1 + 1
|
| for(new j = 0
|
| arr[i][j] = t |
| }
|
| arr[i][s1] = s1 |
| }
|
| }
|
| stock Iter_PrevInternal(array[], size, slot)
|
| {
|
| if(0 <= slot <= size && array[slot] <= size) {
|
| for(new last = slot
|
| if(array[last] == slot) {
|
| return last |
| }
|
| }
|
| }
|
| return size |
| }
|
| #define Iter_Begin(%1) (_Y_ITER_ARRAY_SIZE(%1))
|
| #define Iter_Start Iter_Begin
|
| #define Iter_End(%1) (_Y_ITER_ARRAY_SIZE(%1))
|
| #define Iter_Finish Iter_End
|
| #define Iter_First(%1) (_Y_ITER_ARRAY:%1@YSII_Ag[_Y_ITER_ARRAY_SIZE(%1)])
|
| #define Iter_Last(%1) Iter_PrevInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1),_Y_ITER_ARRAY_SIZE(%1))
|
| #define Iter_Next(%1,%2) (_Y_ITER_ARRAY:%1@YSII_Ag[(%2)])
|
| #define Iter_Prev(%1,%2) Iter_PrevInternal(_Y_ITER_ARRAY:%1@YSII_Ag,_Y_ITER_ARRAY_SIZE(%1),(%2))
|
| #define Iter_Previous Iter_Prev
|
| #define Iter_InternalArray(%1) (_Y_ITER_ARRAY:%1@YSII_Ag)
|
| #define _Y_ITER_INT_SIZE:%0(%2[%1]@YSII_Ag)) %0(%2@YSII_Ag[]))
|
| #define Iter_InternalSize(%1) (_:_Y_ITER_INT_SIZE:sizeof (%1@YSII_Ag)) |