Dimos7 Posted December 13, 2016 Share Posted December 13, 2016 handler = dbConnect("sqlite", " IZDatabase.db") dbExec(handler, "CREATE TABLE IF NOT EXISTS vehicles(id int(11), model int(3), x decimal(10,6), y decimal(10.6), z decimal(10.6), rotx decimal(10.6), roty decimal(10,6), rotz decimal(10.6), engine int(1), locked int(1), lights int(1), hp float, color1 varchar(50), color2 varchar(50), plate text, owner text, interior int(5), dimension int(5), upgrades varchat(150), headLights varchar(30), variant1 int(3), variant2 int(3)") dbExec(handler, "INSERT INTO vehicles VALUES(model='0', x='0.000000', y='0.000000',z='0.000000', rotx='0.000000', roty='0.000000', rotz='0.000000', engine='0', locked='0', lights='0', hp='100', color1='0', color2='0', interior='0', dimension='0', upgades= '[ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ]', headLights=' [ [ 255, 255, 255 ] ]', variant1='NULL', variant2='NULL')") function SmallestID() local query = dbQuery(handler, "SELECT MIN(e1.id+1) AS nextID FROM vehicles AS e1 LEFT JOIN vehicles AS e2 ON e1.id+1 = e2.id WHERE e2.id = NULL") local result = dbPoll(query, -1) if result then local id = tonumber(result["nextID"]) or 1 return id end end function buyTheCar(player, vehicle, price) if isElement(source) and source == player and ( not ( isGuestAccount(getPlayerAccount(source)) ) ) then local money = getPlayerMoney(source) local i = 0 if vehicle and price <= money and ( getAccountData(getPlayerAccount(source),"VS.5") == false ) then local x, y, z = getElementPosition(source) local car = createVehicle(vehicle, x, y-5, z) warpPedIntoVehicle(source,car) outputChatBox("You have successfully bought "..getVehicleNameFromModel(vehicle).."!", source, 0, 255, 0) takePlayerMoney(source, price) local vx, vy, vz = getElementPosition(car) local rx, ry, rz = getElementRotation(car) local col = {getVehicleColor(car)} local color1 = toJSON( col[1], col[2], col[3]) local color2 = toJSON( col[4], col[5], col[6]) local latter1 = string.char(math.random(65, 90)) local latter2 = string.char(math.random(65, 90)) local var1, var2 = getVehicleVariant(car) local plate = latter1..latter2..math.random(0,9).." "..math.random(1000,9999) local smallestid = SmallestID() i = i + 1 setVehiclePlateText(car, plate) dbExec(handler, "INSERT INTO vehicles VALUES(id='"..tostring(smallestid).."', model='"..tostring(vehicle).."', x='"..tostring(vx).."', y='"..tostring(vy).."', z='"..tostring(vz).."', rotx='"..tostring(rx).."',roty='".. tostring(ry).."',rotz='"..tostring(rz).."', color1='"..tostring(color1).."', color2='"..tostring(color2).."', owner='"..getplayerName(source).."', plate='"..tostring(plate).."', variant1='"..var1.."', variant2='"..var2.."')") setElementData(source, "Vehicles", i) setElementData(source, "Vehicles:Name", getVehicleNameFromModel(vehicle)) setElementData(vehicle, "Vehicles:ID", smallestid) setElementData(vehicle, "owner", getPlayerName(source)) local account = getPlayerAccount(source) if ( getAccountData(account,"VS.1") == false ) then setAccountData(account,"VS.1",vehicle) outputChatBox("You own now 1 vehicle!",source,0,255,0) elseif ( getAccountData(account,"VS.2") == false ) then setAccountData(account,"VS.2",vehicle) outputChatBox("You own now 2 vehicles!",source,0,255,0) elseif ( getAccountData(account,"VS.3") == false ) then setAccountData(account,"VS.3",vehicle) outputChatBox("You own now 3 vehicles!",source,0,255,0) elseif ( getAccountData(account,"VS.4") == false ) then setAccountData(account,"VS.4",vehicle) outputChatBox("You own now 4 vehicles!",source,0,255,0) elseif ( getAccountData(account,"VS.5") == false ) then setAccountData(account,"VS.5",vehicle) outputChatBox("You own now 5 vehicles and you can't own more vehicles!",source,0,255,0) end elseif ( price > money ) then outputChatBox("You don't have enough money to buy this vehicle!", source, 255, 0, 0) elseif ( not ( getAccountData(getPlayerAccount(source),"VS.5") == false ) ) then outputChatBox("You can't own more than 5 vehicles!",source,255,0,0) end end end addEvent("VS.buy", true) addEventHandler("VS.buy", root, buyTheCar) function spawnTheCar(vehicle, id) local query = dbQuery(handler, "SELECT * FROM vehicles WHERE id='"..id.."', and model='"..getVehicleModelFromName(vehicle).."'") local result = dbPoll(query, -1) local spawned = true if vehicle and id then if result > 0 and spawned == true then destroyElement(vehicle) spawned = false setElementData(vehicle, "spawned", "#FF0000[INACTIVE]") elseif result > 0 and spawned == false then createVehicle(tonumber(result["model"]), tonumber(result["x"]), tonumber(result["y"]), tonumber(result["z"]), tonumber(result["rotx"]), tonumber(result["roty"]), tonumber(result["rotz"]), result["plate"]) setVehicleVariant(vehicle, tonumber(result["variant1"]), tonumber(result["variant2"])) setVehicleColor(vehicle, tonumber(result["color1"]), tonumber(result["color2"])) addVehicleUpgrade(vehicle, tonumber(result["upgades"])) setElementHealth(vehicle, tonumber(result["hp"])) setElementData(vehicle, "spawned", "#00FF00[ACTIVE]") spawned = true end end end addEvent("VS.spawn", true) addEventHandler("VS.spawn", root, spawnTheCar) function upgradeTheCar(vehicle, id, upgrade, price) local query = dbQuery(handler, "SELECT * FROM vehicles WHERE id='"..id.."', and model='"..getVehicleNameFromModel(vehicle).."'") local result = dbPoll(query, -1) local money = getPlayerMoney(source) if result > 0 then if upgrade and price <= money then addVehicleUpgrade(vehicle, upgrade) local var1, var2 = getVehicleVariant(car) dbExec(handler, "UPDATE vehicles SET upgrades='"..tostring(getVehicleUpgrades(vehicle)).."'and variant1='"..var1.."', and variant2='"..var2.." WHERE id='"..id.."'") takePlayerMoney(source, price) elseif upgrade and getVehicleUpgradeSlot(getVehicleUpgradeSlotName(upgrade)) and price then removeVehicleUpgrade(vehicle, upgrade) givePlayerMoney(source, price) local var1, var2 = getVehicleVariant(car) dbExec(handler, "UPDATE vehicles SET upgrades='"..tostring(getVehicleUpgrades(vehicle)).."'and variant1='"..var1.."', and variant2='"..var2.." WHERE id='"..id.."'") elseif price > money then outputChatBox("You don't have enough money to buy this upgrade!", source, 255, 0, 0) end end end addEvent("VS.upgrade", true) addEventHandler("VS.upgade", root, upgradeTheCar) function setCarColor(vehicle, color1, color2) if getElementData(vehicle, "owner") and getElementData(source,"Vehicles") and getPedInVehicle(source) and getPedOccupiedVehicleSeat(getPedOccupiedVehicle(source))==0 then if not color1 or not color2 then outputChatBox("Put color1 (r, g, b) and color2(r,g, b) to change your vehicle color!", source, 255, 0, 0) return end color1 = tonumber(r), tonumber(g), tonumber(b) color2 = tonumber(r), tonumber(g), tonumber(b) setVehicleColor(getPedOccupiedVehicle(source), color1, color2) takePlayerMoney(source, 300) dbExec(handler, "UPDATE vehicles SET color1="..tostring(color1).."', color2='"..tostring(color2).." WHERE id ='"..getElementData(vehicle, "Vehicles:ID").."'") end end addCommandHandler("setColor", setCarColor) function setVehicleSpawn(vehicle) if getElementData(vehicle, "owner") and getElementData(source,"Vehicles") and getPedInVehicle(source) and getPedOccupiedVehicleSeat(getPedOccupiedVehicle(source))==0 then x, y, z = getElementPosition(vehicle) rx, ry, rz = getElementRotation(vehicle) col = {getVehicleColor(vehicle)} color1 = toJSON(col[1], col[2], col[3]) color2 = toJSON(col[4], col[5], col[6]) hp = getElementHealth(vehicle) dbExec(handler, "UPDATE vehicles SET x='".. tostring(x).."', y='"..tostring(y)"',z='"..tostring(z).."',rotx='"..tostring(rx)"',roty='"..tostring(ry)"', rotz='"..tostring(rz).."', color1='"..color1.."', color2='"..color2.."', and hp='"..tostring(hp).."WHERE id='"..getElementData(source, "Vehicles:ID").."'") end end addCommandHandler("park", setVehicleSpawn) function fixCar(vehicle, id) local query = dbQuery(handler, "SELECT * FROM vehicles WHERE id='"..id.."' and model='"..getVehicleNameFromModel(vehicle).."'") local result = dbPoll(query, -1) if result >0 then fixVehicle(vehicle) end end addEvent("VS.fix", true) addEventHandler("VS.fix", root, fixCar) function selltheCar(vehicle, id, price) if getElementData(vehicle, "owner") and getElementData(source, "Vehicles") and getPedInVehicle(source) then price = buyTheCar(price) destroyElement(vehicle) givePlayerMoney(source, price/2) dbExec(handler, "DELETE vehicles WHERE id ='"..getElementData(vehicle, "Vehicles:ID").."'") end end addCommandHandler("sellcar", selltheCar) 2 dbExec failed(1) Syntax error near ) 3 dbExec failed no such table Link to comment
myonlake Posted December 27, 2016 Share Posted December 27, 2016 The first CREATE TABLE query is invalid, it has a typo "varchat", while it should be "varchar", and it's also missing an ending bracket. CREATE TABLE IF NOT EXISTS vehicles(id int(11), model int(3), x decimal(10,6), y decimal(10.6), z decimal(10.6), rotx decimal(10.6), roty decimal(10,6), rotz decimal(10.6), engine int(1), locked int(1), lights int(1), hp float, color1 varchar(50), color2 varchar(50), plate text, owner text, interior int(5), dimension int(5), upgrades varchar(150), headLights varchar(30), variant1 int(3), variant2 int(3)) That probably sorts it out. 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