get player street name (lighter)
# support-forum
c
I'm using this script to get player street name... But its heavy, there is a way to make the same thing lighter?
Copy code
c++
stock GetPlayer2DZone(playerid, zone[], len) //Credits to Cueball, Betamaster, Mabako, and Simon (for finetuning).
{
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i = 0; i != sizeof(gSAZones); i++ )
    {
        if(x >= gSAZones[i][SAZONE_AREA][0] && x <= gSAZones[i][SAZONE_AREA][3] && y >= gSAZones[i][SAZONE_AREA][1] && y <= gSAZones[i][SAZONE_AREA][4])
        {
            return format(zone, len, gSAZones[i][SAZONE_NAME], 0);
        }
    }
    return 0;
}
https://hastebin.com/tipedizake.yaml
f
This is the common way to determine a zone name. How have you determined that it is "heavy"? Do you have performance issues? You can maybe slightly optimize it by first establishing what part of the map the player is in, and then only looping over the zones in that area.
d
how about streamer areas?
c
crashdetect plugin is helping me showing heavy functions, my server is lagging because of heavy functions mostly are made by me and i'm fixing, but this one i just coppy from the internet and idk how to do better what are u mean with first estabilishing what part of the map the player is in?
how?
@flat-egg-44689 what are u mean with "first establishing what part of the map the player is in"? is it detect first if player is in LS and then search from a list of zones of LS?
@damp-appointment-93881 what u were suggestion with "about streammer areas"?
d
you can create a streamer area for every zone https://github.com/samp-incognito/samp-streamer-plugin/wiki/Natives-(Areas)
use Streamer_SetIntData to assign the zone index to the streamer area
then, when you want to get the player’s zone, use GetPlayerDynamicAreas. Loop through the output and use Streamer_GetIntData to get the zone index
Copy code
hook OnGameModeInit()
{
    for(new i = 0, j = sizeof(s_arrZones); i < j; i++)
    {
        s_arrZones[i][E_ZONE_MIN_X] += 6000.0;
        s_arrZones[i][E_ZONE_MAX_X] += 6000.0;

        s_arrZones[i][E_ZONE_MIN_Y] += 1100.0;
        s_arrZones[i][E_ZONE_MAX_Y] += 1100.0;

        s_arrZones[i][E_ZONE_AREA_ID] = CreateDynamicRectangle(s_arrZones[i][E_ZONE_MIN_X], s_arrZones[i][E_ZONE_MIN_Y], s_arrZones[i][E_ZONE_MAX_X], s_arrZones[i][E_ZONE_MAX_Y]);

        Streamer_SetIntData(STREAMER_TYPE_AREA, s_arrZones[i][E_ZONE_AREA_ID], E_STREAMER_CUSTOM(AREA_TYPE_MAPZONE), i);
    }
}

stock GetMapZoneAtPoint(Float:x, Float:y, Float:z)
{
    new areaid[5];
    new count = GetDynamicAreasForPoint(x, y, z, areaid);

    for(new i; i < count; i++)
    {
        if(Streamer_HasIntData(STREAMER_TYPE_AREA, areaid[i], E_STREAMER_CUSTOM(AREA_TYPE_MAPZONE)))
        {
            return Streamer_GetIntData(STREAMER_TYPE_AREA, areaid[i], E_STREAMER_CUSTOM(AREA_TYPE_MAPZONE));
        }
    }
    return INVALID_ZONE_ID;
}
5 Views