SA-MP Forums Archive
Getting the Id of a vehicle that was just created? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Getting the Id of a vehicle that was just created? (/showthread.php?tid=516517)



Getting the Id of a vehicle that was just created? - Jacksta21 - 31.05.2014

Okay, so I want to create an admin car system, /veh for example.
I'm using AddStaticVehicleEx to add the vehicle, according to the wiki (https://sampwiki.blast.hk/wiki/AddStaticVehicleEx)
It returns the vehicle ID, but how do I get that?
Something like..
pawn Код:
new vehicle;
vehicle = AddStaticVehicleEx...
Sorry if this is a really obvious question.
Thanks for any help given.


Re: Getting the Id of a vehicle that was just created? - eXeDev - 31.05.2014

Код:
GetPlayerVehicleID(playerid);
https://sampwiki.blast.hk/wiki/GetPlayerVehicleID


Re: Getting the Id of a vehicle that was just created? - NaClchemistryK - 31.05.2014

there is this function
https://sampwiki.blast.hk/wiki/GetPlayerVehicleID
And sorry if it is a really obvious answer

EDIT::
Just sayin', this func. gets the id of the behicle the palyer is inside. So when he is not inside it, the script can't check, it will return something UNHEARD OF.


Re: Getting the Id of a vehicle that was just created? - Aerotactics - 31.05.2014

Another thing you could do (although more technical) is create a loop to check if the player is in range of the car's coordinates.


Re: Getting the Id of a vehicle that was just created? - Jacksta21 - 31.05.2014

Yeah I got the GetPlayerVehicleID, but if I just created the car (Via a command) I want to know the vehicle ID after its created.

From SAMP Wiki: AddStaticVehicleEx
Return Values:
The vehicle ID of the vehicle created (between 1 and MAX_VEHICLES).
INVALID_VEHICLE_ID (65535) if vehicle was not created (vehicle limit reached or invalid vehicle model ID passed).

How would I get the returned value of the AddStaticVehicleEx?
If this is not possible I may have to go with Aerotactics suggestion.


Re: Getting the Id of a vehicle that was just created? - Aerotactics - 31.05.2014

Are you assigning a variable to each car created in that command? Example:
pawn Код:
Car[playerid] = CreateVehicle(...);
If so, your vehicleid is
pawn Код:
Car[playerid]



Re: Getting the Id of a vehicle that was just created? - Jacksta21 - 31.05.2014

Ahh, thats what I needed.
Thanks for that!


Re: Getting the Id of a vehicle that was just created? - NaClchemistryK - 31.05.2014

@Aerostatic
I'd rather say that you should use MAX_VEHICLES instead of MAX_PLAYERS. I don't exactly know what'll happen if you use MAX_PLAYERS.
If you have a MAX_PLAYERS, change it to MAX_VEHICLES.
pawn Код:
new Car[MAX_VEHICLES] = AddStaticVehicleEx(.......);



Re: Getting the Id of a vehicle that was just created? - Aerotactics - 31.05.2014

Quote:
Originally Posted by NaClchemistryK
Посмотреть сообщение
@Aerostatic
I'd rather say that you should use MAX_VEHICLES instead of MAX_PLAYERS. I don't exactly know what'll happen if you use MAX_PLAYERS.
If you have a MAX_PLAYERS, change it to MAX_VEHICLES.
pawn Код:
new Car[MAX_VEHICLES] = AddStaticVehicleEx(.......);
You're correct, my bad. If you use MAX_PLAYERS, you can only have 1 car per player, which is a good setup for admin spawned vehicles.


Re: Getting the Id of a vehicle that was just created? - Threshold - 01.06.2014

I think MAX_PLAYERS is more appropriate for this kind of command. That way, you can track who spawned the vehicle without introducing a new variable. For admin vehicles, normally you would delete the old admin vehicle before creating the new one, but just by changing it from MAX_VEHICLES to MAX_PLAYERS, that doesn't mean you can't spawn more than one, it just means the variable will change value, and it will save as the last vehicle id that you spawned. This won't limit the amount of vehicles you can create unless you code it to do otherwise.