Easiest way to add huge amount vehicle
#1

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?
Reply
#2

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
Reply
#3

So now I would add vehicles only and where btw?....
Reply
#4

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.
Reply
#5

Good but giving a example won't harm you I think....
Reply
#6

Is that for real
117 views and Noone have confidence enough to reply lol...
Reply
#7

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)