05.02.2016, 23:21
Use the id returned by CreateDynamicRectangle as the index of the array to store the areatype:
This way, you don't have to loop anything, because the streamer callbacks already provide you with the areaid, which is used directly as index of the array to access the data.
And no need to use the set&get functions of the streamer to access the data about your areas.
Default arrays are easier to use and probably faster too.
You can use the same idea for objects (streamer) and vehicles as well (default samp functions): use the id returned by Create... functions as index of an array and have immediate access to your data.
You also won't risk overwriting some data, because those Create... functions are designed to use unique id's.
So each vehicle, object, area, pickup, etc, only points to one unique index of the array.
PHP код:
#define AREA_TYPE_BUSINESS 1;
#define AREA_TYPE_BLAHBLAH 2;
new AreaTypes[MAX_AREAS];
AreasInt()
{
new areaid;
areaid = CreateDynamicRectangle(...);
AreaTypes[areaid] = AREA_TYPE_BUSINESS;
areaid = CreateDynamicRectangle(...);
AreaTypes[areaid] = AREA_TYPE_BUSINESS;
areaid = CreateDynamicRectangle(...);
AreaTypes[areaid] = AREAY_TYPE_BLAHBLAH;
}
OnPlayerEnterDynamicArea(playerid, areaid);
{
If (AreaTypes[areaid] == AREA_TYPE_BUSINESS)
{
// Do something
}
}
And no need to use the set&get functions of the streamer to access the data about your areas.
Default arrays are easier to use and probably faster too.
You can use the same idea for objects (streamer) and vehicles as well (default samp functions): use the id returned by Create... functions as index of an array and have immediate access to your data.
PHP код:
enum vData
{
Fuel,
Color1,
Color2,
Float:x,
Float:y,
Float:z
}
new VehicleData[MAX_VEHICLES][vData];
InitVehicles()
{
new vehicleid;
vehicleid = CreateVehicle(...);
VehicleData[vehicleid][Fuel] = 20;
VehicleData[vehicleid][Color1] = 1;
VehicleData[vehicleid][Color2] = 5;
VehicleData[vehicleid][x] = 100.0;
VehicleData[vehicleid][y] = 1750.0;
VehicleData[vehicleid][z] = 5.9;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if (VehicleData[vehicleid][Fuel] == 0)
// Turn off engine and inform player (or whatever)
return 1;
}
So each vehicle, object, area, pickup, etc, only points to one unique index of the array.