-
Posts
642 -
Joined
-
Last visited
Posts posted by Lloyd Logan
-
-
Thanks alot guys!
-
Why you do update the serial if it already the same in the database?
You should only insert it if it doesn't exists.
function getSerial() local serialz = getPlayerSerial(source) local database = dbPoll(dbQuery(server, "SELECT serial FROM accounts WHERE serial = ?", serialz), -1) if database and type(database) == "table" and #database == 0 then dbExec ( server, "INSERT INTO accounts (serial) VALUES (?)", serialz) end end addEventHandler("onPlayerJoin", root, getSerial)
There also another way, but i am not sure if it right or not, you can try it.
The first on works! Thank you!
function getSerial() local serialz = getPlayerSerial(source) dbExec(server, "INSERT INTO accounts (serial) VALUES (serialz) WHERE NOT EXISTS (SELECT serial FROM accounts WHERE serial = '"..serialz.."'") end addEventHandler("onPlayerJoin", root, getSerial)
-
So;
function getSerial() local serialz = getPlayerSerial(source) local queryResult = dbQuery ( server, "SELECT serial FROM accounts WHERE serial = ?", serialz ) local database = dbPoll(queryResult, -1) if #database > 0 then dbExec ( server, "UPDATE accounts SET serial = ? WHERE serial = ?", serial, tostring (serialz)) else dbExec ( server, "INSERT INTO accounts (serial) VALUES (?)", tostring (serialz)) end end addEventHandler("onPlayerJoin", getRootElement(), getSerial)
-
Try This:
local data = dbQuery ( server, "SELECT serial FROM accounts WHERE serial = ?", serial ) if #data > 0 then dbExec ( server, "UPDATE accounts SET serial = ? WHERE serial = ?", serial, tostring (serialz)) else dbExec ( server, "INSERT INTO accounts (serial) VALUES (?)", tostring (serialz)) end
It gives me the error; attempt to get length of local 'data' a userdata value
-
function spawnVeh() local serialz = getPlayerSerial(source) carid = dbQuery(server, "SELECT carid FROM accounts WHERE serial = ?", serialz) local cx = dbQuery(server, "SELECT cx FROM accounts WHERE serial = ?", serialz) local cy = dbQuery(server, "SELECT cy FROM accounts WHERE serial = ?", serialz) local cz = dbQuery(server, "SELECT cz FROM accounts WHERE serial = ?", serialz) veh = createVehicle(carid, cx, cy, cz) end addEventHandler("onPlayerJoin", getRootElement(), spawnVeh)
Expected number for the createvehicle, but the returned should be a number from the table.
-
Why does this keep INSERTING even if there is already the same serial in the table?
local data = dbPoll(dbQuery(server, "SELECT serial FROM accounts WHERE serial = ?", serial), -1) if data and type (data) == "table" and #data > 0 then dbExec (server, "UPDATE accounts SET serial = ?, WHERE serial = '"..serial.."'", tostring (serialz)) else dbExec (server, "INSERT INTO accounts (serial) VALUES (?)", tostring (serialz)) end
-
Thank you for taking the time to write that. I understand it much more. Also I have fixed those errors!
Thanks again
-
local data = dbPoll(dbQuery(server, "SELECT money FROM accounts WHERE serial = ?", serial), -1) if data and type (data) == "table" and #data > 0 then dbExec (server, "UPDATE accounts SET x = ?, y = ?, z = ?, cx = ?, cy = ?, cz = ?, carid = ? WHERE serial = '"..serial.."'", tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z), tostring (vehname),) else dbExec (server, "INSERT INTO accounts VALUES (x, y, z, cx, cy, cz, carid) VALUES (?, ?, ?, ?, ?, ?, ?)", tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z), tostring (vehname)) end
It now gives me the error of unexpected symbol near ) at line 15
-
Thank you, also those websites you refer me to, I don't fully understand it;
In MTA It would equal to = dbExec(server, "INSERT INTO accounts blah)
Whereas
On that website it says = UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
It's different, how do I apply the website syntax into the MTA one.
-
Why doesn't this INSERT a new value?
if data and type (data) == "table" and #data > 0 then dbExec (server, "UPDATE accounts SET (x, y, z, cx, cy, cz, carid) VALUES (?, ?, ?, ?, ?, ?, ?)", tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z), tostring (vehname) "WHERE serial ='"..serial.."'") else dbQuery (server, "INSERT INTO accounts VALUES (x, y, z, cx, cy, cz, carid) VALUES (?, ?, ?, ?, ?, ?, ?)", tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z), tostring (vehname))
-
That doesn't make any sense, why do you even use "WHERE" in a insert query?
serial = getPlayerSerial(source) x, y, z = getElementPosition(newveh) a, b, c = getElementPosition(source) dbExec ( server, "INSERT INTO accounts (serial, x, y, z, cx, cy, cz) VALUES (?, ?, ?, ?, ?, ?, ?)", serial, tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z) )
Infact, what the hell am I thinking, disregard this!
-
Why doesn't this work, it tells me I am returning a string value?
serial = getPlayerSerial(source) x, y, z = getElementPosition(newveh) a, b, c = getElementPosition(source) dbQuery ( server, "INSERT INTO accounts (x, y, z, cx, cy, cz) VALUES (?, ?, ?, ?, ?, ?)", tostring (a), tostring (b), tostring (c), tostring (x), tostring (y), tostring (z)" WHERE serial = '".. serial .."'")--THIS BIT HERE!
-
Line 13: addEventHandler should be removeEventHandler to stop rendering the text.
Yeah, I only used his example as a guideline, so all is good, thanks though!
-
function renderMyText ( ) dxDrawText ( arguments ) end addCommandHandler ( "render", function ( ) addEventHandler ( "onClientRender", root, renderMyText ) -- Begin rendering our text end ) addCommandHandler ( "stoprender", function ( ) removeEventHandler ( "onClientRender", root, renderMyText ) -- Stop rendering our text end )
That's an example.
Thank you! All is working.
-
Well, I thought that was obvious.
I never thought of it to be honest! Thanks!
-
If you add the event only when you need to, then no.
Wait so I don't need to use addEventHandler within a function until I want to?
-
You add the event handler to render it.
But if I were to do onClientRender wouldn't it show as soon as the player joins? Instead of when I trigger it?
-
You can't use dxDrawText without onClientRender/onClientPreRender/onClientHUDRender.
So how could I trigger it at a specific time?
-
dxDraw functions are only drawn for ONE frame, thus needing to work in conjunction with an event such as onClientRender or onClientPreRender in order to draw them every frame.
Check the wiki for an example @ https://wiki.multitheftauto.com/wiki/DxDrawText
Ah, I understand! So how would I trigger them (not using the render?)
-
What do you mean?
As soon as the it draws the text, it disappears almost extremely quickly (like .5 seconds).
-
Why does this instantly delete the text?
function drawText() dxDrawText("You have successfully bought a vehicle!", 92, 158, 720, 195, tocolor(65, 205, 4, 255), 1.40, "pricedown", "left", "top", false, false, true, false, false) setTimer ( function() triggerEvent("destroy") end, 5000, 1 ) end addEvent("drawSuccess", true) addEventHandler("drawSuccess", root, drawText) function destroyText() removeEventHandler("drawSuccess", getRootElement(), drawText) end addEvent("destroy", true) addEventHandler("destroy", root, destroyText)
-
I just realised that! My bad, thanks guys!
-
Why is nothing happening with this script?
function buyVeh() local money = getPlayerMoney(source) if (money < 10000) then ("You do not have enough money to purchase this car", 255, 0, 0) else newveh = createVehicle(589, 558.748046875, -1265.380859375, 17.2421875 ) warpPedIntoVehicle(source, newveh) takePlayerMoney (source, 10000) outputChatBox("You have successfully bought a club!", 0, 255, 0) end end addCommandHandler("buyvehclub", getRootElement(), buyVeh)
-
setElementData ( veh, "vehiclePrice", 50000 )
I didn't even realise it was that easy, thank you!
Marker problem
in Scripting
Posted
Can you provide us with your code?