Create vehicles ingame -
jop9888 - 13.05.2012
hey all,
Could anyone explain me how a integer is saved when i use:
TaxiCar = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
because when i spawn vehicles like this in game, they sometimes get mixed up and it brings huge bugs to my code
thanks in advance!
Jop9888
Re: Create vehicles ingame -
Jonny5 - 13.05.2012
pawn Code:
TaxiCar = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
TaxiCar will hold the id of the created vehicle
so if this is the first vehicle to be created TaxiCar will = 1
so doing something like
pawn Code:
TaxiCar = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
TaxiCar = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
TaxiCar = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
TaxiCar = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
will alter the value each time
pawn Code:
TaxiCar = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
TaxiCar2 = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
TaxiCar3 = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
TaxiCar4 = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
this is more how it will be done.
or even use an array
pawn Code:
new TaxiCar[4];
TaxiCar[0] = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
TaxiCar[1] = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
TaxiCar[2] = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
TaxiCar[3] = AddStaticVehicleEx(420,2044.8854,1473.2106,10.4494 ,181.3339,6,1,-1);
Re: Create vehicles ingame -
jop9888 - 13.05.2012
But how does this explain they can get mixed up?
i often destroy one and create another and so on, is there any way to prevent them from mixing up?
i use for example:
pInfo[i][PlayerCar] = CreateVehicle(pInfo[i][CarModel], pInfo[i][CarX], pInfo[i][CarY], pInfo[i][CarZ], pInfo[i][AngX], pInf [i][CarColor1], pInfo[i][CarColor2], 60);
and define them to players, that they are only accesable for them, at first everything works fine,
but after a few times destroying and creating the script mixes them up
Re: Create vehicles ingame -
Jonny5 - 13.05.2012
when you destroy the vehicle then set
pInfo[i][PlayerCar] = 0;
Re: Create vehicles ingame -
jop9888 - 13.05.2012
Gonna try that one out
Re: Create vehicles ingame -
Jonny5 - 13.05.2012
i should have explained it like
say you create 4 cars
car1 = id 1
car2 = id 2
car3 = id 3
car4 = id 4
and then you delete car3
now you create another car
its id will = 3 not 5.
thats the first free slot between 1 & MAX_VEHICLES
Re: Create vehicles ingame -
Yuryfury - 13.05.2012
CreateVehicle return the vehicleid. Thus, in the examples above, you save the vehicleid to a variable (car1,car2 etc).
To delete a vehicle, simply use DestroyVehicle (under OnVehicleDeath for example):
pawn Code:
#include <a_samp>
new car;
public OnGameModeInit()
{
car = CreateVehicle(411,.......);
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
if(vehicleid == car) // if the vehicle that blew up is "car"
{
DestroyVehicle(vehicleid); //delete the vehicle (so it won't respawn)
}
return 1;
}
Re: Create vehicles ingame -
jop9888 - 20.05.2012
i tried this:
pInfo[i][PlayerCar] = 0;
when i destroy the vehicle, but still sometimes they get mixed up
could it be anything else??