Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*----------------------------------------------------------------------------*\
- Dynamic Zones - Include
- Description:
- This include contains functions to manage gangzones between teams
- dynamically.
- Version:
- 1.0
- Changelog:
- 02/08/2012:
- * First version.
- Extra Data:
- lines: 405 - length: 16477
- Author:
- RuiGy.
- Thanks to:
- Y_Less,
- SA-MP Team.
- \*----------------------------------------------------------------------------*/
- #include <a_samp>
- #if defined _dzones_included
- #endinput
- #endif
- #define _dzones_included
- /*
- native GetDynamicZoneArea(zoneid, &Float:minx, &Float:miny, &Float:maxx, &Float:maxy);
- native SetDynamicZoneArea(zoneid, Float:minx, Float:miny, Float:maxx, Float:maxy);
- native CreateDynamicZone(Float:minx, Float:miny, Float:maxx, Float:maxy, color);
- native FlashDynamicZoneForPlayer(playerid, zoneid, color);
- native IsDynamicZoneFlashingForPlayer(playerid, zoneid);
- native IsDynamicZoneVisibleForPlayer(playerid, zoneid);
- native StopFlashDynamicZoneForPlayer(playerid, zoneid);
- native ShowDynamicZoneForPlayer(playerid, zoneid);
- native HideDynamicZoneForPlayer(playerid, zoneid);
- native IsPlayerInDynamicZone(playerid, zoneid);
- native FlashDynamicZoneForAll(zoneid, color);
- native SetDynamicZoneColor(zoneid, color);
- native StopFlashDynamicZoneForAll(zoneid);
- native ShowDynamicZoneForAll(zoneid);
- native HideDynamicZoneForAll(zoneid);
- native GetDynamicZoneColor(zoneid);
- native DestroyDynamicZone(zoneid);
- native zexist(zoneid);
- */
- /*----------------------------------------------------------------------------*\
- Global variables of Project.
- \*----------------------------------------------------------------------------*/
- enum g_GANG_ZONE {
- g_GANG_ZONE_ID,
- g_GANG_ZONE_COLOR,
- Float:g_GANG_ZONE_MINX,
- Float:g_GANG_ZONE_MINY,
- Float:g_GANG_ZONE_MAXX,
- Float:g_GANG_ZONE_MAXY
- }
- new
- gZoneData[ MAX_GANG_ZONES ][ g_GANG_ZONE ];
- /*----------------------------------------------------------------------------*\
- Forwards of Project.
- \*----------------------------------------------------------------------------*/
- forward dzones_Check();
- /*----------------------------------------------------------------------------*\
- This function creates a dynamic zone.
- \*----------------------------------------------------------------------------*/
- stock CreateDynamicZone(Float:minx, Float:miny, Float:maxx, Float:maxy, color)
- {
- new int_zone_id = SearchZones();
- if (int_zone_id == INVALID_GANG_ZONE) return print("ERROR: Maximum limit of zones exceeded. (dzones.inc)"), 0;
- gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] = GangZoneCreate(minx, miny, maxx, maxy);
- gZoneData[ int_zone_id ][ g_GANG_ZONE_MINX ] = minx;
- gZoneData[ int_zone_id ][ g_GANG_ZONE_MINY ] = miny;
- gZoneData[ int_zone_id ][ g_GANG_ZONE_MAXX ] = maxx;
- gZoneData[ int_zone_id ][ g_GANG_ZONE_MAXY ] = maxy;
- gZoneData[ int_zone_id ][ g_GANG_ZONE_COLOR ] = color;
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function destroys a dynamic zone.
- \*----------------------------------------------------------------------------*/
- stock DestroyDynamicZone(int_zone_id)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- GangZoneDestroy(gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ]);
- gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] = INVALID_GANG_ZONE;
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function change the zone position.
- \*----------------------------------------------------------------------------*/
- stock SetDynamicZoneArea(int_zone_id, Float:minx, Float:miny, Float:maxx, Float:maxy)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- GangZoneDestroy(gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ]);
- gZoneData[ int_zone_id ][ g_GANG_ZONE_MINX ] = minx;
- gZoneData[ int_zone_id ][ g_GANG_ZONE_MINY ] = miny;
- gZoneData[ int_zone_id ][ g_GANG_ZONE_MAXX ] = maxx;
- gZoneData[ int_zone_id ][ g_GANG_ZONE_MAXY ] = maxy;
- gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] = GangZoneCreate(minx, miny, maxx, maxy);
- for (new i; i < MAX_PLAYERS; i++) {
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- if (GetPVarInt(i, str_zone_id) == 1) {
- GangZoneHideForPlayer(i, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ]);
- GangZoneShowForPlayer(i, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ], gZoneData[ int_zone_id ][ g_GANG_ZONE_COLOR ]);
- }
- }
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function Store the zone position, passed by reference.
- \*----------------------------------------------------------------------------*/
- stock GetDynamicZoneArea(int_zone_id, &Float:minx, &Float:miny, &Float:maxx, &Float:maxy)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- minx = gZoneData[ int_zone_id ][ g_GANG_ZONE_MINX ];
- miny = gZoneData[ int_zone_id ][ g_GANG_ZONE_MINY ];
- maxx = gZoneData[ int_zone_id ][ g_GANG_ZONE_MAXX ];
- maxy = gZoneData[ int_zone_id ][ g_GANG_ZONE_MAXY ];
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function show a dynamic zone for a player.
- \*----------------------------------------------------------------------------*/
- stock ShowDynamicZoneForPlayer(playerid, int_zone_id)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- GangZoneShowForPlayer(playerid, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ], gZoneData[ int_zone_id ][ g_GANG_ZONE_COLOR ]);
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- SetPVarInt(playerid, str_zone_id, 1);
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function hides a dynamic zone for a player.
- \*----------------------------------------------------------------------------*/
- stock HideDynamicZoneForPlayer(playerid, int_zone_id)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- GangZoneHideForPlayer(playerid, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ]);
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- DeletePVar(playerid, str_zone_id);
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function show a dynamic zone for all.
- \*----------------------------------------------------------------------------*/
- stock ShowDynamicZoneForAll(int_zone_id)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- for (new i; i < MAX_PLAYERS; i++) {
- GangZoneShowForPlayer(i, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ], gZoneData[ int_zone_id ][ g_GANG_ZONE_COLOR ]);
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- SetPVarInt(i, str_zone_id, 1);
- }
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function hides a dynamic zone for all.
- \*----------------------------------------------------------------------------*/
- stock HideDynamicZoneForAll(int_zone_id)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- for (new i; i < MAX_PLAYERS; i++) {
- GangZoneHideForPlayer(i, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ]);
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- DeletePVar(i, str_zone_id);
- }
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function flashs a dynamic zone for all.
- \*----------------------------------------------------------------------------*/
- stock FlashDynamicZoneForAll(int_zone_id, color)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- for (new i; i < MAX_PLAYERS; i++) {
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- if (GetPVarInt(i, str_zone_id) == 1) {
- GangZoneFlashForPlayer(i, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ], color);
- new str_zone_id_2[14];
- format(str_zone_id_2, sizeof str_zone_id_2, "fszone_%i", int_zone_id);
- SetPVarInt(i, str_zone_id_2, 1);
- }
- }
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function stop flashing a dynamic zone for all.
- \*----------------------------------------------------------------------------*/
- stock StopFlashDynamicZoneForAll(int_zone_id)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- for (new i; i < MAX_PLAYERS; i++) {
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- if (GetPVarInt(i, str_zone_id) == 1) {
- GangZoneStopFlashForPlayer(i, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ]);
- new str_zone_id_2[14];
- format(str_zone_id_2, sizeof str_zone_id_2, "fszone_%i", int_zone_id);
- DeletePVar(i, str_zone_id_2);
- }
- }
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function flashs a dynamic zone for a player.
- \*----------------------------------------------------------------------------*/
- stock FlashDynamicZoneForPlayer(playerid, int_zone_id, color)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- if (GetPVarInt(playerid, str_zone_id) == 1) {
- GangZoneFlashForPlayer(playerid, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ], color);
- new str_zone_id_2[14];
- format(str_zone_id_2, sizeof str_zone_id_2, "fszone_%i", int_zone_id);
- SetPVarInt(playerid, str_zone_id_2, 1);
- }
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function stop flashing a dynamic zone for a player.
- \*----------------------------------------------------------------------------*/
- stock StopFlashDynamicZoneForPlayer(playerid, int_zone_id)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- if (GetPVarInt(playerid, str_zone_id) == 1) {
- GangZoneStopFlashForPlayer(playerid, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ]);
- new str_zone_id_2[14];
- format(str_zone_id_2, sizeof str_zone_id_2, "fszone_%i", int_zone_id);
- DeletePVar(playerid, str_zone_id_2);
- }
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function sets a dynamic gang zone color.
- \*----------------------------------------------------------------------------*/
- stock SetDynamicZoneColor(int_zone_id, color)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- gZoneData[ int_zone_id ][ g_GANG_ZONE_COLOR ] = color;
- for (new i; i < MAX_PLAYERS; i++) {
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- if (GetPVarInt(i, str_zone_id) == 1) {
- GangZoneHideForPlayer(i, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ]);
- GangZoneShowForPlayer(i, gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ], gZoneData[ int_zone_id ][ g_GANG_ZONE_COLOR ]);
- }
- }
- return int_zone_id;
- }
- /*----------------------------------------------------------------------------*\
- This function gets a dynamic gang zone color.
- \*----------------------------------------------------------------------------*/
- stock GetDynamicZoneColor(int_zone_id)
- {
- if (gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return 0;
- return gZoneData[ int_zone_id ][ g_GANG_ZONE_COLOR ];
- }
- /*----------------------------------------------------------------------------*\
- This function checks if a dynamic zone is visible for a player.
- \*----------------------------------------------------------------------------*/
- stock IsDynamicZoneVisibleForPlayer(playerid, int_zone_id)
- {
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "vszone_%i", int_zone_id);
- return (!GetPVarInt(playerid, str_zone_id)) ? 0 : 1;
- }
- /*----------------------------------------------------------------------------*\
- This function checks if a dynamic zone is flashing for a player.
- \*----------------------------------------------------------------------------*/
- stock IsDynamicZoneFlashingForPlayer(playerid, int_zone_id)
- {
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "fszone_%i", int_zone_id);
- return (!GetPVarInt(playerid, str_zone_id)) ? 0 : 1;
- }
- /*----------------------------------------------------------------------------*\
- This function checks if a player is inside a dynamic zone.
- \*----------------------------------------------------------------------------*/
- stock IsPlayerInDynamicZone(playerid, int_zone_id)
- {
- new
- Float:x,
- Float:y,
- Float:z;
- GetPlayerPos(playerid, x, y, z);
- if (x > gZoneData[ int_zone_id ][ g_GANG_ZONE_MINX ] && x < gZoneData[ int_zone_id ][ g_GANG_ZONE_MAXX ] && y > gZoneData[ int_zone_id ][ g_GANG_ZONE_MINY ] && y < gZoneData[ int_zone_id ][ g_GANG_ZONE_MAXY ]) return 1;
- return 0;
- }
- /*----------------------------------------------------------------------------*\
- This function checks if a zone exist.
- \*----------------------------------------------------------------------------*/
- stock zexist(int_zone_id)
- {
- return (!gZoneData[ int_zone_id ][ g_GANG_ZONE_ID ]) ? 0 : 1;
- }
- /*----------------------------------------------------------------------------*\
- This function searches for existing zones.
- \*----------------------------------------------------------------------------*/
- stock SearchZones()
- {
- for (new z = 0; z < MAX_GANG_ZONES; z++) if (gZoneData[ z ][ g_GANG_ZONE_ID ] == INVALID_GANG_ZONE) return z;
- return INVALID_GANG_ZONE;
- }
- /*----------------------------------------------------------------------------*\
- This callback is called one time each second.
- \*----------------------------------------------------------------------------*/
- public dzones_Check()
- {
- for (new i = 0; i < MAX_PLAYERS; i++) {
- for (new z = 0; z < MAX_GANG_ZONES; z++) {
- new str_zone_id[14];
- format(str_zone_id, sizeof str_zone_id, "etzone_%i", z);
- if (IsPlayerInDynamicZone(i, z) && GetPVarInt(i, str_zone_id) == 0) {
- CallLocalFunction("OnPlayerEnterDynamicZone", "ii", i, str_zone_id);
- SetPVarInt(i, str_zone_id, 1);
- }
- else if (!IsPlayerInDynamicZone(i, z) && GetPVarInt(i, str_zone_id) == 1) {
- CallLocalFunction("OnPlayerExitDynamicZone", "ii", i, str_zone_id);
- DeletePVar(i, str_zone_id);
- }
- }
- }
- return 1;
- }
- /*----------------------------------------------------------------------------*\
- Hooking OnGameMode/FilterScriptInit, Thanks Y_Less.
- \*----------------------------------------------------------------------------*/
- #if defined FILTERSCRIPT
- public OnFilterScriptInit()
- {
- for (new z = 0; z < MAX_GANG_ZONES; z++) { gZoneData[ z ][ g_GANG_ZONE_ID ] = INVALID_GANG_ZONE; }
- SetTimer("dzones_Check", 1000, true);
- return CallLocalFunction("dzones_OnFilterScriptInit", "");
- }
- #if defined _ALS_OnFilterScriptInit
- #undef OnFilterScriptInit
- #else
- #define _ALS_OnFilterScriptInit
- #endif
- #define OnFilterScriptInit dzones_OnFilterScriptInit
- forward dzones_OnFilterScriptInit();
- forward OnPlayerEnterDynamicZone(playerid, zoneid);
- forward OnPlayerExitDynamicZone(playerid, zoneid);
- #else
- public OnGameModeInit()
- {
- for (new z = 0; z < MAX_GANG_ZONES; z++) { gZoneData[ z ][ g_GANG_ZONE_ID ] = INVALID_GANG_ZONE; }
- SetTimer("dzones_Check", 1000, true);
- return CallLocalFunction("dzones_OnGameModeInit", "");
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit dzones_OnGameModeInit
- forward dzones_OnGameModeInit();
- forward OnPlayerEnterDynamicZone(playerid, zoneid);
- forward OnPlayerExitDynamicZone(playerid, zoneid);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement