Stealthy Serval Posted December 6, 2018 Share Posted December 6, 2018 I currently have a command to spawn a vehicle using either the model ID or the vehicle name, and when you spawn the vehicle, it assigns a random plate to the vehicle. This works perfectly if you use the vehicle model ID, but if you use the name (ie "Tampa") it returns an error: WANRING: vehicle-system\vs_server.lua:184: Bad argument @ 'setVehiclePlateText' [Expected string at argument 2, got nil] I've moved my variables around, called the function in and out of the different sections of code, but still don't understand why it's doing this. Here is my command: --Create Vehicle/Spawn Vehicle from ID or name function commandCreateVehicle(thePlayer,command,vehicleModel) if(vehicleModel)then local vehicleToSpawn = tonumber(vehicleModel) local vehicleOwner = getPlayerName(thePlayer) local vehTag = createRandomPlateText() local x,y,z = getElementPosition(thePlayer) x = x+5 z = z+2 if(vehicleToSpawn ~= nil)then if(vehicleToSpawn > 399)then if(vehicleToSpawn < 612)then local theVehicle = createVehicle(vehicleToSpawn,x,y,z) if(theVehicle)then local vehicleName = getVehicleNameFromModel(vehicleToSpawn) vehicleTag = vehicleTag + 1 setElementData(theVehicle,"name",vehicleName) setElementData(theVehicle,"model",vehicleToSpawn) setElementData(theVehicle,"tag",vehTag) setElementData(theVehicle,"id",vehicleTag) setVehicleOverrideLights(theVehicle,1) setVehiclePlateText(theVehicle,vehTag) setElementData(theVehicle,"owner",vehicleOwner) outputChatBox("(#"..vehicleTag..") Enjoy your "..vehicleName..", "..getPlayerName(thePlayer).."!",thePlayer,0,255,0) else outputChatBox("Vehicle failed to spawn. Error: SM01.",thePlayer,255,0,0) end else outputChatBox("Invalid vehicle ID.",thePlayer,255,0,0) end else outputChatBox("Invalid vehicle ID.",thePlayer,255,0,0) end else local theVehicle = createVehicle(getVehicleModelFromName(vehicleModel),x,y,z) if(theVehicle)then local vehicleID = getVehicleModelFromName(vehicleModel) local vehicleName = getVehicleNameFromModel(vehicleID) vehicleTag = vehicleTag + 1 setElementData(theVehicle,"name",vehicleName) setElementData(theVehicle,"model",vehicleID) setElementData(theVehicle,"tag",vehTag) setElementData(theVehicle,"id",vehicleTag) setVehiclePlateText(theVehicle,vehTag) setElementData(theVehicle,"owner",vehicleOwner) setVehicleOverrideLights(theVehicle,1) outputChatBox("(#"..vehicleTag..") Enjoy your "..vehicleName..", "..getPlayerName(thePlayer).."!",thePlayer,0,255,0) else outputChatBox("Invalid vehicle name.",thePlayer,255,0,0) end end else outputChatBox("Invalid syntax. Please use: /createvehicle [vehicle ID/name]",thePlayer,255,0,0) end end addCommandHandler("createvehicle",commandCreateVehicle) addCommandHandler("cv",commandCreateVehicle) and here is the createRandomPlateText() function local characters = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"} function createRandomPlateText() local plate = "" for i = 1, 3 do plate = plate..characters[math.random(1, #characters)] end plate = plate.."-" for i = 1, 3 do plate = plate..math.random(1, 9) end qh = sql:query("SELECT * FROM vehicles WHERE tag=?",plate) local row = qh[1] if row then createRandomPlateText() else return plate end end Link to comment
Stealthy Serval Posted December 6, 2018 Author Share Posted December 6, 2018 Well, I don't know what happened, I didn't change anything, and it just randomly started working.. 1 Link to comment
koragg Posted December 9, 2018 Share Posted December 9, 2018 On 06/12/2018 at 17:06, Stealthy Serval said: Well, I don't know what happened, I didn't change anything, and it just randomly started working.. We've all been like this haha. Things would break on their own and then get fixed on their own. Mystery 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