Jump to content

expected element


Resto

Recommended Posts

I don't know what is with this but i get warning expected element.. can anyone help me?

function WTF(_, acc)
local owner = getAccountName(acc)
local result = dbQuery(database,"SELECT * FROM SpawnCar ORDER BY Owner DESC LIMIT 1")
local poll = dbPoll(result, -1)
for i,v in ipairs(poll) do
vehicle = createVehicle(v["carID"], v["X"], v["Y"], v["Z"], 0, 0, 0, v["text"])
spawnVehicle(vehicle, v["X"], v["Y"], v["Z"])
setElementData(vehicle, "Owner", v["Owner"])
--setVehiclePlateText(vehicle, text)
setVehicleColor(vehicle, v["Color1"], v["Color2"], v["Color3"])
setVehicleHeadLightColor(vehicle, v["R"], v["G"], v["B"])
setVehicleRespawnPosition(vehicle, v["X"], v["Y"], v["Z"])
	end
end
addCommandHandler("spawnvehicle", WTF)

 

Edited by Resto
Link to comment

Where do you get the error, what's the point of your script? Please give additional information in order to us be able to help.

 

Btw... it should look SOMEHOW this.

-- You need a dbConnection here named database

database = dbConnect()

function WTF(_, player)
local acc = getPlayerAccount(player)
local owner = getAccountName(acc)
local result = dbQuery(database,"SELECT * FROM SpawnCar WHERE owner=?", owner)
local poll = dbPoll(result, 500) -- Never EVER use -1 at poll
for i,v in ipairs(poll) do
vehicle = createVehicle(v["carID"], v["X"], v["Y"], v["Z"], 0, 0, 0, v["text"])
spawnVehicle(vehicle, v["X"], v["Y"], v["Z"])
setElementData(vehicle, "Owner", v["Owner"])
--setVehiclePlateText(vehicle, text)
setVehicleColor(vehicle, v["Color1"], v["Color2"], v["Color3"])
setVehicleHeadLightColor(vehicle, v["R"], v["G"], v["B"])
setVehicleRespawnPosition(vehicle, v["X"], v["Y"], v["Z"])
	end
end
addCommandHandler("spawnvehicle", WTF)

 

Edited by StormFighter
Extension
Link to comment
22 minutes ago, Resto said:

why never use -1 ? at poll

Because it will freeze your server if result needs some time to retrieve. Although, it's not often but still you should check if the result has been successfully retrieved from dbPoll like this:

local QueryHandle = dbQuery(database,"SELECT * FROM SpawnCar WHERE owner=?", owner)
local PollResult = dbPoll(QueryHandle, 500) -- 0.5 seconds timeout, taking from @StormFighter

if ( PollResult == false ) then 
   -- try again or simply log it 
  
  return false -- exit the function
else 
  -- continue the function
end

 

Edited by Saml1er
Link to comment

but must be if (PollResult == false) then ? or this is only for check? i need only local PollResult = dbPoll(QueryHandle, 500)

or what do you mean with (try again or silmpy log it) ?

can you show me please in my code what do you mean with this?

Edited by Resto
Link to comment
5 hours ago, Resto said:

but must be if (PollResult == false) then ? or this is only for check? i need only local PollResult = dbPoll(QueryHandle, 500)

or what do you mean with (try again or silmpy log it) ?

can you show me please in my code what do you mean with this?

It is a VERY useful check. It simply prevents your server from breaking down, if somehow you did not get a result from sql.

How to use it? Simple. All you have to do is, that you make that if and put everything in it which directly uses the data from result. ( Basically you put the for loop in the if )

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