new WangGangZone2;
WangGangZone2 = GangZoneCreate(-2382.3772, 250.0283, -2549.3816, 42.8198);
CMD:claimturf(playerid) { // Here I want to check what turf the player is in, GangZoneFlashForAll(WangGangZone2, COLOR_YELLOW); // Finding that the player was in this turf, it would begin to flash. SetTimerEx("GangZoneTimer", 300000, false, "i", playerid); // Then it would start a five minute timer. return 1; }
public GangZoneTimer(playerid) { return 1; }
stock IsInArea(playerid, area)
{
new Float:p[3],Float:ap[4];
GetPlayerPos(playerid, p[0], p[1], p[2]);
switch(area)
{
case 0: ap[0] = 1212.34234, ap[1] = 234.123, ap[2] = -111.222, ap[3] = 213.44;//some area coords
case 1: ap[0] = 1212.34234, ap[1] = 234.123, ap[2] = -111.222, ap[3] = 213.44;//some area coords
case 2: ap[0] = 1212.34234, ap[1] = 234.123, ap[2] = -111.222, ap[3] = 213.44;//some area coords
//and so on, add your areas...
}
if(p[0] <= ap[0] && p[0] >= ap[1] && p[1] <= ap[2] && p[1] >= ap[3]) return 1;//if players coords are within the area, return 1 for true
return -1;//if players coords are not within the area, returning 0. But... 0 is an area id too, we'll just go with -1 i guess or either change the switch, starting with 1
}
//just define some areas with numbers... lets say groove st is id 0 for example.
if(IsInArea(playerid,0)) printf("it's Groove st.!");
else printf("where am i?");
#define GangZone1 0
stock IsInArea(playerid, area)
{
new Float:p[3],Float:ap[4];
GetPlayerPos(playerid, p[0], p[1], p[2]);
switch(area)
{
case 0: ap[0] = x, ap[1] = y, ap[2] = x, ap[3] = y;
}
if(pX <= max_x && pX >= min_x && pY <= max_y && pY >= min_y) return 1;//if players coords are within the area, return 1 for true
return 0;
}
CMD:claimturf(playerid)
{
if(IsInArea(playerid,0))
{
GangZoneFlashForAll(GangZone1, COLOR_WHITE);
SetTimerEx("GangZoneTimer", 300000, false, "i", playerid);
}
else if // So on..
return 1;
}
stock GetAreaID(playerid)
{
new Float:p[3],Float:ap[4],areaid;
GetPlayerPos(playerid, p[0], p[1], p[2]);
for(new i=0; i<3; i++)//loop for the areas you've defined, it's 3 here. ( 0.. 1.. 2)
{
switch(i)
{
case 0: ap[0] = 1212.34234, ap[1] = 234.123, ap[2] = -111.222, ap[3] = 213.44;
case 1: ap[0] = 1212.34234, ap[1] = 234.123, ap[2] = -111.222, ap[3] = 213.44;
case 2: ap[0] = 1212.34234, ap[1] = 234.123, ap[2] = -111.222, ap[3] = 213.44;
//and so on, add your areas...
}
if(p[0] <= ap[0] && p[0] >= ap[1] && p[1] <= ap[2] && p[1] >= ap[3]) return i;//return the area-id
}
return -1;//failed, player is not in a area defined by you, returning 0. But... 0 is an area id too, we'll just go with -1 i guess
//or either change the switch + loop, starting with 1
}
//EDIT: forgot to change the params of the control structure from wiki in my first post, sorry! fixed that by now
well, you don't really have to #define it. You can write comments to the area lines in the switch of the function but yeah, that's how it works ![]() also, just coded that, in case you need to get a area id: pawn Код:
|
CMD:claimturf(playerid)
{
if(IsInArea(playerid,0))
{
SendClientMessage(playerid, COLOR_NEWBIE, "This is the Wang Family's home turf, you can not /claimturf here!");
}
else if(IsInArea(playerid,1))
{
GangZoneFlashForAll(GangZone1, COLOR_WHITE);
SetTimerEx("GangZoneTimer", 300000, false, "i", playerid);
}
else if(IsInArea(playerid,2))
{
GangZoneFlashForAll(GangZone2, COLOR_WHITE);
SetTimerEx("GangZoneTimer", 300000, false, "i", playerid);
}
return 1;
}
public GangZoneTimer(playerid)
{
return 1;
}
for (new i; i < MAX_PLAYERS; i++)
if(IsInArea(i, areaid)
new s[70];//idk could be smaller. we'll just go with that for testing :)
for(new i=0;i<GetMaxPlayers();i++)
{
if(Gang[i] != 1) continue;//skip every id which is not in gang 1
if(GetAreaID(i) == -1) continue;//skip the id if it's in the gang but in no defined area
else if(GetAreaID(i) == 2)//lets say area 2 is Los Santos, were checking for id 2 here
{
strcat(s,GetName(i));
strcat(s," | ");//using "\n" here and displaying it in a dialog would look nicer
}
}
if(s[0]==EOS) return SendClientMessage(playerid,-1,"There's noone in that area");
SendClientMessage(playerid,-1,s);//display the list of players who are in Los Santos and in Gang 1
//you could also use a dialog.
//for the name
stock GetName(playerid)
{
new n[MAX_PLAYER_NAME];
GetPlayerName(playerid, n, MAX_PLAYER_NAME);
return n;
}
of course,
you'll have to loop trough all of the players (i'd recommend GetMaxPlayers() instead of MAX_PLAYERS btw) to check their area-id's something like pawn Код:
|