Jump to content

Sql error


Dimos7

Recommended Posts

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
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)

dbExec no such column model

Link to comment
22 hours ago, Dimos7 said:
  • 
    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')")
  •  
  •  

Try this one:

function onStart()
    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 (model,x,y,z,rotx,roty,rotz,engine,locked,lights,hp,color1,color2,interior,dimension,upgrades,headLights,variant1,variant2) VALUES (0,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0,0,0,100,0,0,0,0,'[ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ]',' [ [ 255, 255, 255 ] ]','NULL','NULL')");
end
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart)

 

Edited by InfectedZomb
Link to comment
local Vehicles = {{579,60000},{400,60000},{404,28000},{489,65000},{505,65000},{479,45000},{442,45000},{458,45000},{602,100000},{496,42500},{401,41000},{518,60000},{527,75000},{589,75000},{419,45000},{533,75000},{526,50000},{474,55000},{545,50000},{517,45000},{410,41000},{600,50000},{436,41000},{580,50000},{439,75000},{549,75000},{491,45000},{445,45000},{507,45000},{585,45000},{587,100000},{466,55000},{492,50000},{546,45000},{551,45000},{516,45000},{467,45000},{426,47500},{547,45000},{405,55000},{409,75000},{550,45000},{566,45000},{540,45000},{421,50000},{529,45000},{402,250000},{542,65000},{603,150000},{475,75000},{562,175000},{565,95000},{559,125000},{561,50000},{560,125000},{558,100000},{429,150000},{541,150000},{415,150000},{480,95000},{434,100000},{494,200000},{502,200000},{503,200000},{411,300000},{506,150000},{451,300000},{555,95000},{477,95000},{499,25000},{498,25000},{578,50000},{486,70000},{406,500000},{573,250000},{455,75000},{588,50000},{403,75000},{423,1000000},{414,50000},{443,75000},{515,75000},{514,75000},{531,12000},{456,45000},{422,45000},{482,95000},{530,12000},{418,45000},{572,12000},{582,50000},{413,50000},{440,50000},{543,65000},{583,12000},{478,35000},{554,50000},{536,75000},{575,75000},{534,75000},{567,75000},{535,75000},{576,75000},{412,75000},{568,75000},{457,12000},{483,45000},{508,40000},{571,10000},{500,55000},{444,250000},{556,250000},{557,250000},{495,100000},{539,75000},{485,12000},{431,60000},{438,45000},{437,60000},{574,12000},{420,45000},{525,75000},{408,50000},{428,65000}}
local Updates = {{1000}, {1001}, {1002}, {1003}, {1004}, {1005}, {1006}, {1007},{1008}, {1009} , {1010}, {1011}, {1012}, {1013}, {1014}, {1015}, {1016}, {1017}, {1018}, {1019}, {1020}, {1021}, {1022}, {1023}, {1024}, {1025}, {1026}, {1027}, {1028}, {1029}, {1030}, {1031}, {1032}, {1033}, {1034}, {1035}, {1036}, {1037}, {1038}, {1039}, {1040}, {1041}, {1042}, {1043}, {1044}, {1045}, {1046}, {1047}, {1048}, {1049}, {1050}, {1051}, {1052}, {1053}, {1054}, {1055}, {1056}, {1057}, {1058}, {1059},{1060}, {1061}, {1062}, {1063}, {1064}, {1065}, {1066}, {1067}, {1068}, {1069}, {1070}, {1071}, {1072}, {1073}, {1074}, {1075}, {1076}, {1077}, {1078}, {1079}, {1080}, {1081}, {1082}, {1083}, {1084}, {1085}, {1086}, {1087}, {1088}, {1089}, {1090}, {1091}, {1092}, {1093}, {1094}, {1095}, {1096}, {1097}, {1098}, {1099}, {1100}, {1101}, {1102}, {1103}, {1104}, {1105}, {1106}, {1107}, {1108}, {1109}, {1110}, {1111}, {1112}, {1113}, {1114}, {1115}, {1116}, {1117}, {1118}, {1119}, {1120}, {1121}, {1122}, {1123}, {1124}, {1125}, {1126}, {1127}, {1128}, {1129}, {1130}, {1131}, {1132}, {1133}, {1134}, {1135}, {1136}, {1137}, {1138}, {1139}, {1140}, {1141}, {1142}, {1143}, {1144}, {1145}, {1146}, {1147}, {1148}, {1149}, {1150}, {1151}, {1152}, {1153}, {1154}, {1155}, {1156}, {1157}, {1158}, {1159}, {1160}, {1161}, {1162}, {1163}, {1164}, {1165}, {1166}, {1167}, {1168}, {1169}, {1170}, {1171}, {1172}, {1173}, {1174}, {1175}, {1176}, {1177}, {1178}, {1179}, {1180}, {1181}, {1182}, {1183}, {1184}, {1185}, {1186}, {1187}, {1188}, {1189}, {1190}, {1191}, {1192}, {1193}}

GUIEditor = {
    gridlist = {},
    window = {},
    button = {},
	scrollbar = {},
	column = {}
}

function shop()
	local screenWidth , screenHeight = guiGetScreenSize()
	local windowWidth, windowHeight = 457,  491
	local left, top = screenWidth/2 - windowWidth/2 , screenHeight/2 - windowHeight/2
    GUIEditor.window[1] = guiCreateWindow(left, top, windowWidth, windowHeight, "Car Shop", false)
    guiWindowSetMovable(GUIEditor.window[1], false)
    guiWindowSetSizable(GUIEditor.window[1], false)
    guiSetAlpha(GUIEditor.window[1], 1.00)
    guiSetProperty(GUIEditor.window[1], "CaptionColour", "FFFFFEFE")

    GUIEditor.gridlist[1] = guiCreateGridList(20, 30, 410, 332, false, GUIEditor.window[1])
    GUIEditor.column[1] = guiGridListAddColumn(GUIEditor.gridlist[1], "Vehicle name", 0.5)
	GUIEditor.column[2] = guiGridListAddColumn(GUIEditor.gridlist[1], "Price", 0.5)
    GUIEditor.button[1] = guiCreateButton(25, 385, 117, 47, "Buy", false, GUIEditor.window[1])
    guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FF26E513")
    GUIEditor.button[2] = guiCreateButton(303, 385, 117, 47, "Close", false, GUIEditor.window[1])
    guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFF70000")
    GUIEditor.button[3] = guiCreateButton(168, 385, 117, 47, "View Vehicle", false, GUIEditor.window[1])
    guiSetProperty(GUIEditor.button[3], "NormalTextColour", "FFE8DB0E")  
	showCursor(true)
    for ent,v in ipairs(Vehicles) do
	    local row = guiGridListAddRow(GUIEditor.gridlist[1])
		guiGridListSetItemText(GUIEditor.gridlist[1], row, 1, getVehicleNameFromModel(v[1]), false, false)
		guiGridListSetItemData(GUIEditor.gridlist[1], row, 1, v[1])
		guiGridListSetItemText(GUIEditor.gridlist[1], row, 2, "".. v[2] .."$", false, false)
		guiGridListSetItemData(GUIEditor.gridlist[1], row, 2, v[2])
    end	
end
Marker1 =  createMarker(321.04, -1965.3171, 17.9757, "cylinder", 3, 0, 0, 255, 255)
Marker2 = createMarker(193.7826, 1919.5389, 16.64, "cylinder", 3, 0, 0, 255, 255)
addEventHandler("onClientMarkerHit", Marker1, shop)
addEventHandler("onClientMarkerHit", Marker2, shop)

addEventHandler("onClientGUIClick", root, 
function(button,state) 
	if not GUIEditor.window[1] or not guiGetVisible(GUIEditor.window[1]) then return end
	if ( source == GUIEditor.button[1] ) and ( button == "left" ) and ( state == "up" ) then
	    if guiGridListGetSelectedItem(GUIEditor.gridlist[1]) == -1 then outputChatBox("Please select a vehicle to buy!", 255, 0, 0) return end
        local vehicleID = guiGridListGetItemData(GUIEditor.gridlist[1], guiGridListGetSelectedItem(GUIEditor.gridlist[1]), 1)
	    local price = tonumber(guiGridListGetItemData(GUIEditor.gridlist[1], guiGridListGetSelectedItem(GUIEditor.gridlist[1]), 2))
	    triggerServerEvent("VS.buy", localPlayer, getLocalPlayer(), tonumber(vehicleID), price)
	    guiSetVisible(GUIEditor.window[1], false)
		showCursor(false)
		guiSetInputEnabled(false)
	elseif ( source == GUIEditor.button[2] ) and ( button == "left" ) and ( state == "up" ) then
	    guiSetVisible(GUIEditor.window[1], false)
		showCursor(false)
		guiSetInputEnabled(false)
	elseif ( source == GUIEditor.button[3] ) and ( button == "left" ) and ( state == "up" ) then
	    if guiGridListGetSelectedItem(GUIEditor.gridlist[1]) == -1 then outputChatBox("Please select a vehicle to view!", 255, 0, 0) return end
        local vehicleID = guiGridListGetItemData(GUIEditor.gridlist[1], guiGridListGetSelectedItem(GUIEditor.gridlist[1]), 1)
		local x, y, z = getElementPosition(getLocalPlayer())
		local vehicle = createVehicle(vehicleID,x,y-5,z)
		if ( vehicle ) then
		    setTimer(destroyElement,5000,1,vehicle)
		end
		guiSetVisible(GUIEditor.window[1], false)
		showCursor(false)
	end
end)


function close_shop()
    shop()
    showCursor(false)
	guiSetVisible(GUIEditor.window[1], false)
end
addEventHandler("onClientMarkerLeave", Marker1, close_shop)
addEventHandler("onClientMarkerLeave", Marker2, close_shop)

function showVehicles()
    local screenWidth, screenHeight = guiGetScreenSize()
	local windowWidth, windowHeight = 457, 491
	local left, top = screenWidth/2 - windowWidth/2, screenHeight/2 - windowHeight/2
    GUIEditor.window[2] = guiCreateWindow(left, top, windowWidth, windowHeight, "Vehicles", false)
	guiWindowSetMovable(GUIEditor.window[2],false)
	guiWindowSetSizable(GUIEditor.window[2], false)
	showCursor(not isCursorShowing())
	guiSetVisible(GUIEditor.window[2], not guiGetVisible(GUIEditor.window[2]))
	GUIEditor.gridlist[2] = guiCreateGridList(20, 30, 410, 332, false, GUIEditor.window[2])
	GUIEditor.column[3] = guiGridListAddColumn(GUIEditor.gridlist[2], "Vehicles:", 0.5)
	GUIEditor.button[4] = guiCreateButton(25, 385, 117, 47, "Okay", false, GUIEditor.window[2])
	GUIEditor.button[5] = guiCreateButton(303, 385, 117, 47, "Upgrades", false, GUIEditor.window[2])
	GUIEditor.button[6] = guiCreateButton(168, 385, 117, 47, "Fix", false, GUIEditor.window[2])
	   ownVehicles = getElementData(localPlayer, "Vehicles")
	if ownVehicles then
	   for _, v in ipairs(ownVehicles) do
	       local row = guiGridListAddRow(GUIEditor.gridlist[2])
		   guiGridListSetItemText(GUIEditor.gridlist[2], row, 1, getElementData(v, "spawned")..""..getElementData(localPlayer, "Vehicles:Name").."".."("..getElementData(v, "Vehicles:ID")..")", false, false)
           guiGridListSetItemData(GUIEditor.gridlist[2], row, 1, v[1])
	   end	
	end
end		
bindKey("F3", "down", showVehicles)

function createUpdagradeWindow()
    local screenWidth, screenHeight = guiGetScreenSize()
	local windowWidth, windowHeight = 314, 377
	local left, top = screenWidth/2 - windowWidth/2, screenHeight/2- windowHeight/2
	GUIEditor.window[3] = guiCreateWindow(left, top, windowWidth, windowHeight, "Vehicle Upgrades")
    guiWindowSetMovable(GUIEditor.window[3], false)
	guiWindowSetSizable(GUIEditor.window[3], false)
	GUIEditor.gridlist[3] = guiCreateGridList(15, 31, 284, 294, false, GUIEditor.window[3])
	GUIEditor.column[4] = guiGridListAddColumn(GUIEditor.gridlist[3], "Upgrade", 0.5)
	GUIEditor.column[5] = guiGridListAddColumn(GUIEditor.gridlist[3], "Price", 0.5)
	for _ , v in ipairs(Updates) do
	    local row = guiGridListAddRow(GUIEditor.gridlist[3])
		guiGridListSetItemText(GUIEditor.gridlist[3], row, 1 , getVehicleUpgradeSlotName(Updates), false, false)
		guiGridListSetItemText(GUIEditor.gridlist[3], row, 1 , v[1], false, false)
		guiGridListSetItemData(GUIEditor.gridlist[3], row, 1, v[1])
		guiGridListSetItemText(GUIEditor.gridlist[3], row, 2, ""..v[2].."$", false, false)
		guiGridListSetItemData(GUIEditor.gridlist[3], row, 2, v[2])
    end	
	GUIEditor.button[7] = guiCreateButton(25, 342, 56, 25, "add", false, GUIEditor.window[3])
	GUIEditor.button[8] = guiCreateButton(109, 342, 56, 25, "remove", false, GUIEditor.window[3])
	GUIEditor.button[9] = guiCreateButton(200, 342, 56, 25, "close", false, GUIEditor.window[3])
	guiSetVisible(GUIEditor.window[3], false)
end

addEventHandler("onClientGUIClick", root,
function(button, state)
    if not GUIEditor.window[2] or not guiGetVisible(GUIEditor.window[2]) then return end
    if (source == GUIEditor.button[4])  and (button == "left") and (state == "up") then
        if guiGridListGetSelectedItem(GUIEditor.gridlist[2]) == - 1 then outputChatBox("Please select a vehicle to spawn / depsawn!", 255, 0, 0) return end
           local vehicle = guiGridListGetItemData(GUIEditor.gridlist[2], guiGridListGetSelectedItem(GUIEditor.gridlist[1], 1))
		   local dbid = getElementData(localPlayer, "Vehicles:ID")
		   triggerServerEvent("VS.spawn", localPlayer, vehicle, dbid)
    elseif (source == GUIEditor.button[5]) and (button== "left") and (state == "up") then
	       if guiGridListGetSelectedItem(GUIEditor.gridlist[2]) == - 1 then outputChatBox("Please select a vehicle to upgrade!", 255, 0, 0) return end
	       createUpdagradeWindow()
		   guiSetVisible(GUIEditor.window[3], true)
		   showCursor(true)
		   if source == GUIEditor.button[7] then
		      local vehicle = guiGridListGetItemData(GUIEditor.gridlist[2], guiGridListGetSelectedItem(GUIEditor.gridlist[1], 1))
		      local upgrade = tonumber(guiGridListGetItemData(GUIEditor.gridlist[3], guiGridListGetSelectedItem(GUIEditor.gridlist[3]), 1))
			  local price = tonumber(guiGridListGetItemData(GUIEditor.gridlist[3], guiGridListGetSelectedItem(GUIEditor.gridlist[3]), 2))
			  triggerServerEvent("VS.upgrade", localPlayer, vehicle, upgrade, price)
		   elseif source == GUIEditor.button[8] then
		      local vehicle = guiGridListGetItemData(GUIEditor.gridlist[2], guiGridListGetSelectedItem(GUIEditor.gridlist[1], 1))
		      local upgrade = tonumber(guiGridListGetItemData(GUIEditor.gridlist[3], guiGridListGetSelectedItem(GUIEditor.gridlist[3], 1)))
			   local price = tonumber(guiGridListGetItemData(GUIEditor.gridlist[3], guiGridListGetSelectedItem(GUIEditor.gridlist[3]), 2))
			  triggerServerEvent("VS.upgrade", localPlayer, vehicle, upgrade, price/2)
		   elseif source == GUIEditor.button[9] then
		      guiSetVisible(GUIEditor.window[3], false)
		      showCursor(false)
		  end
	elseif (source == GUIEditor.button[6]) and (button=="left") and (state == "up") then
	       if guiGridListGetSelectedItem(GUIEditor.gridlist[2]) == - 1 then outputChatBox("Please select a vehicle to fix!", 255, 0, 0) return end
	       local vehicle = guiGridListGetItemData(GUIEditor.gridlist[2], guiGridListGetSelectedItem(GUIEditor.gridlist[1], 1))
		   local dbid = getElementData(localPlayer, "Vehicles:ID")
		   triggerServerEvent("VS.fix", localPlayer, vehicle, dbid)
	end
end)		

when i press f3 only the cursor work the visible no why not error or warnigns

Edited by Dimos7
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...