[Help] Gangzones
#1

I am in the works of some gangzones for my roleplay script, and I am wondering if their is a way to check if the player is still in the zone. I'll use a turf to show you.

Код:
new WangGangZone2;
OnGameModeInit
Код:
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;
}
(Another problem)

The next problem I am having is actually seeing if any members of that Gang[playerid] is on that turf. So if the person who started the turf war was part of Gang[playerid] == 1; then even if he/she died the timer would continue, then another person who happened to be on that turf was also in Gang 1 would be standing on the turf when the timer is over, and take over the turf. But I have absolutely no idea where to start. And I don't like asking for people to make something from scratch for me but I really have no idea how to do this:

Код:
public GangZoneTimer(playerid)
{
    return 1;
}
Same thing with that, it would check to see if a gang member of the /claimturf gang was on that turf, and if so it would become their turf.

Enormous thank you and +REP for anyone who can help me figure this out!
Reply
#2

You could probably use this https://sampwiki.blast.hk/wiki/Areacheck to check if the player is in the gangzone.
Reply
#3

you could do something like this

pawn Код:
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
}
usage would be,
PHP код:
//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?"); 
like this, you just have to type the area's id when youre using the function instead
of passing down the coords to the func. like in the wiki example
Reply
#4

Quote:
Originally Posted by CutX
Посмотреть сообщение
-snip-
So it would go a little bit like this:

pawn Код:
#define GangZone1           0
pawn Код:
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;
}

pawn Код:
CMD:claimturf(playerid)
{
if(IsInArea(playerid,0))
{
    GangZoneFlashForAll(GangZone1, COLOR_WHITE);
    SetTimerEx("GangZoneTimer", 300000, false, "i", playerid);
}
else if // So on..
return 1;
}
Reply
#5

//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 Код:
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
}
Reply
#6

Quote:
Originally Posted by CutX
Посмотреть сообщение
//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 Код:
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
}
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;
}
So, after it starts the timer, it needs to finish obviously:

pawn Код:
public GangZoneTimer(playerid)
{
    return 1;
}
What would I use to check if any Gang[playerid] = 1 members were in the area, Would I use
pawn Код:
for (new i; i < MAX_PLAYERS; i++)
if(IsInArea(i, areaid)
or would I use something different?
Reply
#7

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 Код:
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;
}
Reply
#8

Quote:
Originally Posted by CutX
Посмотреть сообщение
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 Код:
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;
}
You're the best!

*passes you an internet cookie*
REP+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)