OnPlayerEnterGangzone
#1

Hey, does something like "OnPlayerEnterGangZone" exists?
Reply
#2

Use IsPlayerInArea, same sort of thing
Reply
#3

Quote:
Originally Posted by iTorran
Посмотреть сообщение
Use IsPlayerInArea, same sort of thing
Isn't that called on command/script command and not on update?

I mean something like OnPlayerEnterCheckPoint
Reply
#4

No, it isn't. You can use IsPlayerInArea in a timer or OnPlayerUpdate.
Reply
#5

Yes but that would execute the script every time the player is INSIDE a gangzone, I wan't it only to be executed when a player leaves a checkpoint,.

Ofcourse, I could make this with variables but isn't there a simpler way?
Reply
#6

Here is something I made in 15 minutes:
pawn Код:
#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;
}
Not really tested at extreme level, tweak it...

Remember to replace normal ones with GangZoneCreateEx and DestroyEx etc.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)