Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////
- // ** Gang Zones Include. ** //
- // ** By Jayce (PawnHunter). ** //
- // ** ** //
- // ** Credits: - ** //
- // ** Incognito - Streamer. ** //
- // ** Y_Less - Foreach include. ** //
- // ** File: gangzones.inc. ** //
- // ** Make sure you added both callbacks in your ** //
- // ** scripts otherwise you'll get: ** //
- // ** : error 004: function ** //
- // ** "OnPlayerEnterGangZone" is not implemented. ** //
- /////////////////////////////////////////////////////////
- //#define GZ_USE_STREAMER
- #if defined __PawnHunterGangZones__
- #endinput
- #else
- #define __PawnHunterGangZones__
- #endif
- #if !defined _samp_included
- #tryinclude <a_samp>
- #if !defined _samp_included
- #error "Could not find <a_samp.inc> include."
- #endif
- #endif
- #if !defined Iter_Count
- #tryinclude <YSI\y_iterate>
- #if !defined Iter_Count
- #error "Could not find <foreach.inc> include."
- #endif
- #endif
- #if defined GZ_USE_STREAMER
- #tryinclude <streamer>
- #if !defined INVALID_STREAMER_ID
- #error "Could not find <streamer.inc> include."
- #endif
- #endif
- #if !defined GZ_MAX_ZONES
- #define GZ_MAX_ZONES 1024
- #endif
- #if !defined GZ_TIMER_TICKRATE
- #define GZ_TIMER_TICKRATE 700
- #endif
- #define GangZonePlayersCount(%0) Iter_Count(GZ_ZonePlayers[%0])
- forward OnPlayerEnterGangZone(playerid, gangzoneid);
- forward OnPlayerExitGangZone(playerid, gangzoneid);
- forward OnTimerTick();
- enum GZ_ZONE_INFO {
- #if defined GZ_USE_STREAMER
- Z_dynamicID,
- #endif
- Float:Z_MinX,
- Float:Z_MinY,
- Float:Z_MaxX,
- Float:Z_MaxY,
- };
- enum GZ_PLAYER_INFO {
- P_ZoneID,
- P_EnterTick,
- P_ExitTick,
- }
- static
- GZ_Zone[GZ_MAX_ZONES][GZ_ZONE_INFO],
- bool:GZ_PlayerInZone[MAX_PLAYERS],
- GZ_Player[MAX_PLAYERS][GZ_PLAYER_INFO],
- Iterator:GZ_Zones<GZ_MAX_ZONES>
- ;
- #if !defined GZ_USE_STREAMER
- static GZ_Timer = -1;
- #endif
- new stock
- Iterator:GZ_ZonePlayers[GZ_MAX_ZONES]<MAX_PLAYERS>
- ;
- stock GZ_GangZoneCreate(Float:minx, Float:miny, Float:maxx, Float:maxy)
- {
- new id = GangZoneCreate(minx, miny, maxx, maxy);
- #if defined GZ_USE_STREAMER
- GZ_Zone[id][Z_dynamicID] = CreateDynamicRectangle(minx, miny, maxx, maxy);
- #endif
- GZ_Zone[id][Z_MinX] = minx;
- GZ_Zone[id][Z_MinY] = miny;
- GZ_Zone[id][Z_MaxX] = maxx;
- GZ_Zone[id][Z_MaxY] = maxy;
- Iter_Add(GZ_Zones, id);
- return id;
- }
- stock GZ_GangZoneDestroy(zone)
- {
- if (Iter_Contains(GZ_Zones, zone))
- {
- Iter_Remove(GZ_Zones, zone);
- #if defined GZ_USE_STREAMER
- DestroyDynamicArea(GZ_Zone[id][Z_dynamicID]);
- #endif
- GangZoneDestroy(zone);
- return true;
- }
- else return false;
- }
- stock GetSecondsSinceEnter(playerid)
- {
- if( !IsPlayerInAnyGangZone(playerid) || GZ_Player[playerid][P_EnterTick] == 0) return -1;
- return gettime() - GZ_Player[playerid][P_EnterTick];
- }
- stock GetSecondsSinceExit(playerid)
- {
- if( IsPlayerInAnyGangZone(playerid) || GZ_Player[playerid][P_ExitTick] == 0 ) return -1;
- return gettime() - GZ_Player[playerid][P_ExitTick];
- }
- stock IsPlayerInGangZone(playerid, zoneid) return GZ_Player[playerid][P_ZoneID] == zoneid;
- stock IsPlayerInAnyGangZone(playerid) return GZ_PlayerInZone[playerid];
- #if defined GZ_USE_STREAMER
- public OnPlayerEnterDynamicArea(playerid, areaid)
- {
- foreach(new zone : GZ_Zones)
- {
- if( areaid == GZ_Zone[zone][Z_dynamicID] )
- {
- GZ_Player[playerid][P_ZoneID] = zone;
- GZ_Player[playerid][P_EnterTick] = gettime();
- Iter_Add(GZ_ZonePlayers[zone], playerid);
- GZ_PlayerInZone[playerid] = true;
- // CallLocalFunction("OnPlayerEnterGangZone", "ii", playerid, zone);
- OnPlayerEnterGangZone(playerid, zone);
- break;
- }
- }
- return true;
- }
- public OnPlayerLeaveDynamicArea(playerid, areaid)
- {
- foreach(new zone : GZ_Zones)
- {
- if( areaid == GZ_Zone[zone][Z_dynamicID] )
- {
- GZ_Player[playerid][P_ZoneID] = -1;
- GZ_Player[playerid][P_ExitTick] = gettime();
- Iter_Remove(GZ_ZonePlayers[zone], playerid);
- GZ_PlayerInZone[playerid] = false;
- // CallLocalFunction("OnPlayerExitGangZone", "ii", playerid, zone);
- OnPlayerExitGangZone(playerid, zone);
- break;
- }
- }
- return true;
- }
- #else
- public OnTimerTick()
- {
- new Float:x, Float:y, Float:z;
- foreach(new i : Player)
- {
- if(!IsPlayerInAnyGangZone(i))
- {
- GetPlayerPos(i, x, y, z);
- foreach(new zone : GZ_Zones)
- {
- if(x < GZ_Zone[zone][Z_MaxX] && x > GZ_Zone[zone][Z_MinX] && y < GZ_Zone[zone][Z_MaxY] && y > GZ_Zone[zone][Z_MinY])
- {
- GZ_Player[i][P_ZoneID] = zone;
- GZ_Player[i][P_EnterTick] = gettime();
- Iter_Add(GZ_ZonePlayers[zone], i);
- GZ_PlayerInZone[i] = true;
- // CallLocalFunction("OnPlayerEnterGangZone", "ii", i, zone);
- OnPlayerEnterGangZone(i, zone);
- break;
- }
- }
- }
- else
- {
- GetPlayerPos(i, x, y, z);
- foreach(new zone : GZ_Zones)
- {
- if(IsPlayerInGangZone(i, zone))
- {
- if(x < GZ_Zone[zone][Z_MaxX] && x > GZ_Zone[zone][Z_MinX] && y < GZ_Zone[zone][Z_MaxY] && y > GZ_Zone[zone][Z_MinY]) continue;
- else
- {
- GZ_Player[i][P_ZoneID] = -1;
- GZ_Player[i][P_ExitTick] = gettime();
- Iter_Remove(GZ_ZonePlayers[zone], i);
- GZ_PlayerInZone[i] = false;
- // CallLocalFunction("OnPlayerExitGangZone", "ii", i, zone);
- OnPlayerExitGangZone(i, zone);
- break;
- }
- }
- }
- }
- }
- return true;
- }
- #endif
- #if defined FILTERSCRIPT
- public OnFilterScriptInit()
- {
- #else
- public OnGameModeInit()
- {
- #endif
- #if !defined GZ_USE_STREAMER
- GZ_Timer = SetTimer("OnTimerTick", GZ_TIMER_TICKRATE, true);
- #endif
- #if defined FILTERSCRIPT
- #if defined GZ_OnFilterScriptInit
- return GZ_OnFilterScriptInit();
- #else
- return true;
- #endif
- #else
- #if defined GZ_OnGameModeInit
- return GZ_OnGameModeInit();
- #else
- return true;
- #endif
- #endif
- }
- #if defined FILTERSCRIPT
- #if defined _ALS_OnFilterScriptInit
- #undef OnFilterScriptInit
- #else
- #define _ALS_OnFilterScriptInit
- #endif
- #define OnFilterScriptInit GZ_OnFilterScriptInit
- #if defined GZ_OnFilterScriptInit
- forward GZ_OnFilterScriptInit();
- #endif
- #else
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit GZ_OnGameModeInit
- #if defined GZ_OnGameModeInit
- forward GZ_OnGameModeInit();
- #endif
- #endif
- #if defined FILTERSCRIPT
- public OnFilterScriptExit()
- {
- #else
- public OnGameModeExit()
- {
- #endif
- #if !defined GZ_USE_STREAMER
- if(GZ_Timer != -1) KillTimer(GZ_Timer);
- #endif
- #if defined FILTERSCRIPT
- #if defined GZ_OnFilterScriptExit
- return GZ_OnFilterScriptExit();
- #else
- return true;
- #endif
- #else
- #if defined GZ_OnGameModeExit
- return GZ_OnGameModeExit();
- #else
- return true;
- #endif
- #endif
- }
- #if defined FILTERSCRIPT
- #if defined _ALS_OnFilterScriptExit
- #undef OnFilterScriptExit
- #else
- #define _ALS_OnFilterScriptExit
- #endif
- #define OnFilterScriptExit GZ_OnFilterScriptExit
- #if defined GZ_OnFilterScriptExit
- forward GZ_OnFilterScriptExit();
- #endif
- #else
- #if defined _ALS_OnGameModeExit
- #undef OnGameModeExit
- #else
- #define _ALS_OnGameModeExit
- #endif
- #define OnGameModeExit GZ_OnGameModeExit
- #if defined GZ_OnGameModeExit
- forward GZ_OnGameModeExit();
- #endif
- #endif
- public OnPlayerConnect(playerid)
- {
- GZ_Player[playerid][P_ZoneID] = -1;
- GZ_Player[playerid][P_EnterTick] = 0;
- GZ_Player[playerid][P_ExitTick] = 0;
- GZ_PlayerInZone[playerid] = false;
- #if defined GZ_OnPlayerConnect
- return GZ_OnPlayerConnect(playerid);
- #else
- return true;
- #endif
- }
- #if defined _ALS_OnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define _ALS_OnPlayerConnect
- #endif
- #define OnPlayerConnect GZ_OnPlayerConnect
- #if defined GZ_OnPlayerConnect
- forward GZ_OnPlayerConnect(playerid);
- #endif
- public OnPlayerDisconnect(playerid, reason)
- {
- if(IsPlayerInAnyGangZone(playerid))
- {
- new zone = GZ_Player[playerid][P_ZoneID];
- Iter_Remove(GZ_ZonePlayers[zone], playerid);
- }
- #if defined GZ_OnPlayerDisconnect
- return GZ_OnPlayerDisconnect(playerid, reason);
- #else
- return true;
- #endif
- }
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
- #define OnPlayerDisconnect GZ_OnPlayerDisconnect
- #if defined GZ_OnPlayerDisconnect
- forward GZ_OnPlayerDisconnect(playerid, reason);
- #endif
- #if defined _ALS_GangZoneDestroy
- #undef GangZoneDestroy
- #else
- #define _ALS_GangZoneDestroy
- #endif
- #define GangZoneDestroy GZ_GangZoneDestroy
- #if defined _ALS_GangZoneCreate
- #undef GangZoneCreate
- #else
- #define _ALS_GangZoneCreate
- #endif
- #define GangZoneCreate GZ_GangZoneCreate
Advertisement
Add Comment
Please, Sign In to add comment