PDA

View Full Version : Easiest way to add huge amount vehicle


princejeet1510
08/02/2017, 06:25 AM
Sup all,Hope you all are alright so....
Here what i wanted to know today.....like for an example:
I want to create a vehicle renting system....so for it i have vehicles by vehicles i mean (AddStaticVehicleEx()bla bla) so the problem is if i create a enum to hold the variable for each vehicle i will have to declare over 59 variables then will again i will have to assign those variables the vehicle info....that is pain in the ass tbh....what would be the easiest way to do it?

X337
08/02/2017, 06:30 AM
You can simply hook AddStaticVehicleEx function.
Example:

enum e_Vehicle {
vehiclecolor,
// ...
}
new Vehicles[MAX_VEHICLES][e_Vehicle];

stock hook_AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:z_angle, color1, color2, respawn_delay, addsiren=0)
{
id = AddStaticVehicleEx(modelid, spawn_x, spawn_y, spawn_z, z_angle, color1, color2, respawn_delay, addsiren);
Vehicles[id][vehiclecolor] = color1;
return id;
}
#if defined _ALS_AddStaticVehicleEx
#undef AddStaticVehicleEx
#else
#define _ALS_AddStaticVehicleEx
#endif

#define AddStaticVehicleEx hook_AddStaticVehicleEx

princejeet1510
08/02/2017, 06:38 AM
So now I would add vehicles only and where btw?....

BroZeus
08/02/2017, 08:24 AM
every heard of arrays and loop?
You don't have to create separate variable for each vehicle, you just have to create one array with enough space to hold all vehicle info.

While creating vehicle, load vehicle detail from db and store it in variable, you don't need to write code to store info for each vehicle separately you just have to write it once and in a loop.

princejeet1510
08/02/2017, 08:37 AM
Good but giving a example won't harm you I think....

princejeet1510
08/02/2017, 02:09 PM
Is that for real?????????
117 views and Noone have confidence enough to reply lol...???

ranme15
08/02/2017, 02:38 PM
You already got X337 example.. here is another one.
enum vehInfoEnum {
vehID,
price,
model
}
new vehInfo[59][vehInfoEnum];

for(new i = 0; i < 59; i ++) {
vehInfo[i][vehID] = CreateVehicle..
vehInfo[i][price] = 10000;
vehInfo[i][model] = 411;
}