Homer Simpson Posted January 4, 2020 Share Posted January 4, 2020 Well, I explain I am trying to make a system in environments on my server but I have 2 problems and they are the following: Not detecting the ID and the text, the ID is inserted in the database but the text is not. I hope you can help me, thanks. CODE : local elements = { } local function loadText( id, text, x, y, z, interior, dimension ) local element = createElement( "3dtext" ) setElementPosition( element, x, y, z ) setElementInterior( element, interior ) setElementDimension( element, dimension ) setElementData( element, "text", tostring( text ) ) elements[ id ] = element end addEventHandler( "onResourceStart", resourceRoot, function( ) local result = dbPoll(dbQuery(handler, "SELECT * FROM 3dtext ORDER BY textID ASC" ),-1) if result then for key, data in ipairs( result ) do loadText( data.textID, data.text, data.x, data.y, data.z, data.interior, data.dimension ) end end end ) local function createtext(player,cmd,textID,...) if GetElementData(player,"AdminLvl", 5) then local text = table.concat( { ... }, " " ) local x, y, z = getElementPosition( player ) local insertid = dbExec ( handler, "INSERT INTO `3dtext`(`text`, `x`, `y`, `z`, `interior`, `dimension`) VALUES (?,?,?,?,?,?)", text, x, y, z, getElementInterior( player ),getElementDimension( player ) ) if insertid then loadText( insertid, text, x, y, z, getElementInterior( player ), getElementDimension( player ) ) outputChatBox( "Text created. (ID " .. insertid .. ")", player, 0, 255, 0 ) else outputDebugString( e ) outputChatBox( "Error MYSQL.", player, 255, 0, 0 ) end else outputChatBox( "Command: /" .. cmd .. " [text]", player, 255, 255, 255 ) end end addCommandHandler("createtext",createtext) (Sorry for my bad english) In the debugscript show´s me this error : In the line 37 : attempt to concatenate local 'insertid' (a boolean value) And this is how it create : https://imgur.com/2Je5B9T Link to comment
Moderators Patrick Posted January 4, 2020 Moderators Share Posted January 4, 2020 (edited) https://wiki.multitheftauto.com/wiki/DbExec Quote Returns Returns true unless the connection is incorrect, in which case it returns false. You need to use dbQuery with callback. -- Something like this local function createtext(player,cmd,textID,...) if GetElementData(player,"AdminLvl", 5) then local text = table.concat( { ... }, " " ) local x, y, z = getElementPosition( player ) dbQuery(function(qh) -- callback function local result, inserted_rows, lastinsertedid = dbPoll(qh, 0) if lastinsertedid then loadText( lastinsertedid, text, x, y, z, getElementInterior( player ), getElementDimension( player ) ) outputChatBox( "Text created. (ID " .. lastinsertedid .. ")", player, 0, 255, 0 ) else outputDebugString( e ) outputChatBox( "Error MYSQL.", player, 255, 0, 0 ) end end, handler, "INSERT INTO `3dtext`(`text`, `x`, `y`, `z`, `interior`, `dimension`) VALUES (?,?,?,?,?,?)", text, x, y, z, getElementInterior( player ),getElementDimension( player ) ) else outputChatBox( "Command: /" .. cmd .. " [text]", player, 255, 255, 255 ) end end addCommandHandler("createtext",createtext) Edited January 4, 2020 by stPatrick 1 Link to comment
Homer Simpson Posted January 4, 2020 Author Share Posted January 4, 2020 It works now but i need to put : /createtext [Something there] [text] and then it works but the ID all the time it´s 1 and in the DB shows the good ID but IN GAME not. Link to comment
Scripting Moderators ds1-e Posted January 4, 2020 Scripting Moderators Share Posted January 4, 2020 6 minutes ago, Homer Simpson said: It works now but i need to put : /createtext [Something there] [text] and then it works but the ID all the time it´s 1 and in the DB shows the good ID but IN GAME not. Perhaps you use maybe wrapper for element data? if GetElementData(player,"AdminLvl", 5) then Should be: if getElementData(player,"AdminLvl", 5) then Lua is case sensitive. 1 Link to comment
Moderators Patrick Posted January 4, 2020 Moderators Share Posted January 4, 2020 5 minutes ago, Homer Simpson said: It works now but i need to put : /createtext [Something there] [text] and then it works but the ID all the time it´s 1 and in the DB shows the good ID but IN GAME not. Why need textID? Use Auto Increment, it's the easiest and best way. Helps https://www.youtube.com/watch?v=pzGMAkqRtAI https://stackoverflow.com/questions/5665571/auto-increment-in-phpmyadmin 1 Link to comment
Homer Simpson Posted January 4, 2020 Author Share Posted January 4, 2020 Yes, i use that but IN GAME it shows all the time the same ID (1) and i need the textID to delete it more faster Link to comment
Moderators Patrick Posted January 4, 2020 Moderators Share Posted January 4, 2020 6 minutes ago, Homer Simpson said: Yes, i use that but IN GAME it shows all the time the same ID (1) and i need the textID to delete it more faster Its cant be always 1 if you use auto increment in correct way. 1 Link to comment
Homer Simpson Posted January 4, 2020 Author Share Posted January 4, 2020 Solved, thank you Link to comment
Moderators Patrick Posted January 4, 2020 Moderators Share Posted January 4, 2020 Just now, Homer Simpson said: Solved, thank you Welcome 1 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