myonlake Posted August 9, 2011 Share Posted August 9, 2011 (edited) 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 May 30, 2019 by myonlake Link to comment
qaisjp Posted August 9, 2011 Share Posted August 9, 2011 What do you exactly want, I don't really understand. Link to comment
myonlake Posted August 9, 2011 Author Share Posted August 9, 2011 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
JR10 Posted August 9, 2011 Share Posted August 9, 2011 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
AGENT_STEELMEAT Posted August 10, 2011 Share Posted August 10, 2011 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
JR10 Posted August 10, 2011 Share Posted August 10, 2011 And another problem is duplicates , you can have two elements with the same ID. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now