19.02.2012, 19:02
Hey, does something like "OnPlayerEnterGangZone" exists?
#include <a_samp>
#define MAX_GANGZONES (1024)
enum
e_GZ_DATA
{
bool:VALID,
Float:MIN_X,
Float:MIN_Y,
Float:MAX_X,
Float:MAX_Y
};
new
g_GANGZONE[MAX_GANGZONES][e_GZ_DATA],
UPDATE_TIMER,
bool:GZ_COUNT,
g_GANGZONE_CUR[MAX_PLAYERS]
;
main() {}
public OnGameModeInit()
{
UPDATE_TIMER = SetTimer("GangzoneCheck_Tick", 500, true);
return 1;
}
public OnGameModeExit()
{
KillTimer(UPDATE_TIMER);
return 1;
}
stock GangZoneCreateEx(Float:minx, Float:miny, Float:maxx, Float:maxy)
{
new GZ = GangZoneCreate(minx, miny, maxx, maxy);
g_GANGZONE[GZ][VALID] = true;
g_GANGZONE[GZ][MIN_X] = minx;
g_GANGZONE[GZ][MIN_Y] = miny;
g_GANGZONE[GZ][MAX_X] = maxx;
g_GANGZONE[GZ][MAX_Y] = maxy;
return GZ;
}
stock GangZoneDestroyEx(zoneid)
{
if(!g_GANGZONE[VALID) return false;
GangZoneDestroy(zoneid);
g_GANGZONE[zoneid][VALID] = false;
g_GANGZONE[zoneid][MIN_X] = 0;
g_GANGZONE[zoneid][MIN_Y] = 0;
g_GANGZONE[zoneid][MAX_X] = 0;
g_GANGZONE[zoneid][MAX_Y] = 0;
return true;
}
forward GangzoneCheck_Tick();
public GangzoneCheck_Tick()
{
for (new playerid = 0; playerid < MAX_PLAYERS; playerid++)
{
if(!IsPlayerConnected(playerid)) continue;
GZ_COUNT = false;
for (new gangzone = 0; gangzone < MAX_GANGZONES; gangzone++)
{
if(!g_GANGZONE[gangzone][VALID]) continue;
if(IsPlayerInArea
(
playerid,
g_GANGZONE[gangzone][MIN_X],
g_GANGZONE[gangzone][MAX_X],
g_GANGZONE[gangzone][MIN_Y],
g_GANGZONE[gangzone][MAX_Y]
))
{
GZ_COUNT = true;
if(g_GANGZONE_CUR[playerid] != gangzone)
{
g_GANGZONE_CUR[playerid] = gangzone;
CallLocalFunction("OnPlayerEnterGangZone", "dd", playerid, gangzone);
}
}
}
if(!GZ_COUNT)
{
if(g_GANGZONE_CUR[playerid] != 0)
{
g_GANGZONE_CUR[playerid] = 0;
CallLocalFunction("OnPlayerEnterGangZone", "dd", playerid, 0);
}
}
}
return true;
}
stock IsPlayerInArea(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy) //Thanks to it's creator.
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if (x > minx && x < maxx && y > miny && y < maxy) return true;
return false;
}
//The callback:
forward OnPlayerEnterGangZone(playerid, zoneid);
public OnPlayerEnterGangZone(playerid, zoneid)
{
printf("Entered: %i by playerid %i", zoneid, playerid);
return true;
}