Resto Posted September 1, 2017 Share Posted September 1, 2017 (edited) 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 September 1, 2017 by Resto Link to comment
WorthlessCynomys Posted September 2, 2017 Share Posted September 2, 2017 (edited) 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 September 2, 2017 by StormFighter Extension Link to comment
Resto Posted September 2, 2017 Author Share Posted September 2, 2017 why never use -1 ? at poll Link to comment
Saml1er Posted September 2, 2017 Share Posted September 2, 2017 (edited) 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 September 2, 2017 by Saml1er Link to comment
Resto Posted September 2, 2017 Author Share Posted September 2, 2017 (edited) 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 September 2, 2017 by Resto Link to comment
WorthlessCynomys Posted September 3, 2017 Share Posted September 3, 2017 (edited) 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 September 3, 2017 by Randomly Link to comment
Resto Posted September 3, 2017 Author Share Posted September 3, 2017 Its simple for you.. But i again dont understand how to use in my code.. When you put in my code its easy learn.. 1 Link to comment
ViRuZGamiing Posted September 4, 2017 Share Posted September 4, 2017 On 9/3/2017 at 03:42, Randomly said: 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 ) easier than this it wont get @Resto 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