Getting the Id of a vehicle that was just created?
#1

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

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

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

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

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

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

Ahh, thats what I needed.
Thanks for that!
Reply
#8

@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(.......);
Reply
#9

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)