CourtezBoi Posted March 3, 2011 Share Posted March 3, 2011 Alright so I am making a vehicle system for my server that allows you to create vehicles, and each vehicle has its own ID, so that you can delete vehicles, get vehicles, park vehicles, goto vehicles, etc. all by ID. So I created an ID column in my SQLite table, and made the resource. addCommandHandler ( "createveh", function ( thePlayer, commandName, ... ) local message = table.concat( { ... }, " " ) if #message > 0 then local model = getVehicleModelFromName ( message ) local px, py, pz = getElementPosition (thePlayer) local rx, ry, rz = getElementRotation (thePlayer) if not model then outputChatBox ( "That is not a valid car name" ) else vehicle = createVehicle ( model, px + 5, py, pz + 2 ) local health = getElementHealth (vehicle) local color1, color2, color3, color4 = getVehicleColor(vehicle) local tableUpgrades = getVehicleUpgrades(vehicle) local upgrades = table.concat(tableUpgrades, ",") local paintjob = getVehiclePaintjob(vehicle) local vehicles = executeSQLQuery("SELECT * FROM vehicles") local carid = #vehicles + 1 executeSQLInsert ( "vehicles", "'"..model.."','"..px.."','"..py.."','"..pz.."','"..rx.."','"..ry.."','"..rz.."','"..color1.."','"..color2.."','"..health.."','"..upgrades.."','"..paintjob.."','".. carid .."'") outputChatBox ( "[ADM]"..getPlayerName( thePlayer ) .." spawned a " .. message .. "!", getRootElement (), 255,215,0 ) setElementData ( vehicle, "id", carid, true ) end end end ) Theres my code to create a vehicle, now it spawns the vehicle, gives it an ID, etc, but if I delete say vehicle two, then it throws my entire code off, because then the number of rows + 1 isn't the next ID in the set. Any idea how I could fix this? 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