2023-10-26, 09:29 AM
Glad to hear!
A neat approach would be to perhaps store the data into a ZoneData enum, and instead of using GangZoneCreate, you use a new function called CreateZone;
Then you can create the zones without having to worry about getting the zone coordinates every time you want to get the center of it. Instead you can do something like:
And then you can use it like this (for example)
A neat approach would be to perhaps store the data into a ZoneData enum, and instead of using GangZoneCreate, you use a new function called CreateZone;
PHP Code:
#define MAX_GANG_ZONES 100 //adjust as necessary
enum gangZoneProperties
{
Float:center_x,
Float:center_y,
Float:min_x,
Float:min_y,
Float:max_x,
Float:max_y,
Float:min_z,
Float:max_z,
name[35]
};
new zoneData[MAX_GANG_ZONES][gangZoneProperties];
forward GetZoneName(zoneid);
forward CreateZone(Float:minx, Float:miny, Float:maxx, Float:maxy, Float:minz = 0.0, Float:maxz = 0.0);
public CreateZone(const name[], Float:minx, Float:miny, Float:maxx, Float:maxy, Float:minz = 0.0, Float:maxz = 0.0)
{
new zoneid = GangZoneCreate(minx, miny, maxx, maxy);
if (zoneid != INVALID_GANG_ZONE && zoneid < MAX_GANG_ZONES)
{
zoneData[zoneid][center_x] = (minx + maxx) / 2.0;
zoneData[zoneid][center_y] = (miny + maxy) / 2.0;
zoneData[zoneid][min_x] = minx;
zoneData[zoneid][min_y] = miny;
zoneData[zoneid][max_x] = maxx;
zoneData[zoneid][max_y] = maxy;
zoneData[zoneid][min_z] = minz;
zoneData[zoneid][max_z] = maxz;
format(zoneData[zoneid][name], 35, "%s", name);
}
return zoneid;
}
public GetZoneName(zoneid)
{
if (zoneid >= 0 && zoneid < MAX_GANG_ZONES)
{
return zoneData[zoneid][name];
}
return "";
}
Then you can create the zones without having to worry about getting the zone coordinates every time you want to get the center of it. Instead you can do something like:
PHP Code:
forward GetZoneCenterXY(zoneid, &Float:center_x, &Float:center_y)
public GetZoneCenterXY(zoneid, &Float:center_x, &Float:center_y)
{
if (zoneid >= 0 && zoneid < MAX_GANG_ZONES)
{
center_x = zoneData[zoneid][center_x];
center_y = zoneData[zoneid][center_y];
}
}
And then you can use it like this (for example)
PHP Code:
new Float:x, Float:y;
GetZoneCenter(the_zone_id, x, y);