Jump to content

Vehicle ID


myonlake

Recommended Posts

Hello,

Okay so, I am not sure what kind of functions I should use for this so I hope you'd help me with this.

So my main idea is to make a script that makes a really own ID for a spawned vehicle. For example. I spawn a banshee, and it will have an ID 9000.

I know this is kinda "copying" from vG, but this is really useful for admins to spawn a specific vehicle again.

So, any idea how to do this? What kind of functions I should use.

Edited by myonlake
Link to comment

Okay well,

Thank you for helping me out with that one function. Tho it just throws me a bunch of bad arguments as I don't know what is that if I want to give every vehicle a ID.

The code I made..

-- Do the vehicle ID 
function idVehicle(theVehicle) 
    setElementID(theVehicle, math.random(1, 9999)) 
end 
addEventHandler("onVehicleRespawn", getRootElement(), idVehicle) 
  
-- Show the entered vehicle's ID 
function showVehicleID(theVehicle, sourcePlayer) 
    local vehicle = getElementID(theVehicle) 
    outputChatBox("* This vehicle's ID is: " .. vehicle, sourcePlayer, 220, 220, 0, true) 
end 
addEventHandler("onVehicleEnter", getRootElement(), showVehicleID) 
  
-- Warp the specified ID to a location (x, y, z) 
function warpVehicle(sourcePlayer, commandName, vehicle, posX, posY, posZ) 
    local veh = getElementID(vehicle) 
    setElementPosition(vehicle, posX, posY, posZ) 
    outputChatBox("* Vehicle ID " .. veh .. " spawned.", sourcePlayer, 0, 255, 0, true) 
end 
addCommandHandler("warpid", warpVehicle) 

Link to comment

This is wrong, first setElementID uses a string.

Your event arguments are wrong.

And at your warpVehicle, what the player types (vehicle) won't be a real vehicle, just a string.

Seriously read the WIKI

-- Do the vehicle ID 
function idVehicle(theVehicle) 
    setElementID(theVehicle, tostring(math.random(1, 9999))) 
end 
addEventHandler("onVehicleRespawn", getRootElement(), idVehicle) 
  
-- Show the entered vehicle's ID 
function showVehicleID(sourcePlayer) 
    local vehicle = getElementID(source) 
    outputChatBox("* This vehicle's ID is: " .. vehicle, sourcePlayer, 220, 220, 0, true) 
end 
addEventHandler("onVehicleEnter", getRootElement(), showVehicleID) 
  
-- Warp the specified ID to a location (x, y, z) 
function warpVehicle(sourcePlayer, commandName, vehicle, posX, posY, posZ) 
    local veh = getElementByID(vehicle) 
    setElementPosition(veh, posX, posY, posZ) 
    outputChatBox("* Vehicle ID " .. getElementID(veh) .. " spawned.", sourcePlayer, 0, 255, 0, true) 
end 
addCommandHandler("warpid", warpVehicle) 

Link to comment

It's not a good idea to literally set the vehicle's ID via setElementID - rather, you should use setElementData(theVehicle, "vehicleID", INSERT_ID_HERE). In this case, you could probably use setElementData(theVehicle, "vehicleID", INSERT_ID_HERE, false) as you probably don't need to sync the vehicle's ID to the client. I'm not sure what your plans for using these IDs are, though.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...