Jump to content

MYSQL Error Loading Infopoints


Recommended Posts

Well Here Is The Error mysqlerror.png

Everything Else Works

Serverside:

mysql = exports.mysql 
  
local pInfo = createPickup ( -204.19921875, 1116.7587890625, 19.7421875, 3, 1239 ); -- create marker 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        addEventHandler ( "onPickupHit", pInfo, fnShow ); -- add handler of event 'onPickupHit' to fn 'fnShow' 
        addCommandHandler ( "createinfo", fnCreateInfo ); -- add command 'createinfo' to fn 'fnCreateInfo' 
    end 
) 
  
function fnShow ( pPlayer ) 
    outputChatBox ( "Welcome to Fort Carson Roleplay Server!", pPlayer ); -- output on chat some text 
    outputChatBox ( "Our Forums Address Is mtafcrp.freeforums.org", pPlayer ); 
    cancelEvent(); 
end 
  
function fnCreateInfo ( pPlayer, chCommand, ... ) 
    if ( ... ) then 
        if ( exports['global']:isPlayerAdmin ( pPlayer ) ) then 
            local nX, nY, nZ = getElementPosition ( pPlayer ); 
            local chText = table.concat ( { ... }, " " ); 
            pInfoPickup = createPickup ( nX, nY, nZ, 3, 1239, 0.1 ); 
            setElementData ( pInfoPickup, "Message", chText ); 
            setElementData ( pInfoPickup, "PosX", nX  ); 
            setElementData ( pInfoPickup, "PosY", nY ); 
            setElementData ( pInfoPickup, "PosZ", nZ ); 
            addEventHandler ( "onPickupHit", pInfoPickup, infohit ); 
            fnSaveInfo(); 
        end 
    else 
        outputChatBox ( "SYNTAX: /" .. chCommand .. " [iNFO]", pPlayer, 255, 194, 14 ); 
    end 
end 
  
function fnSaveInfo ( ) 
    local message       = getElementData ( pInfoPickup, "Message" ); 
    local posx      = getElementData ( pInfoPickup, "PosX" ); 
    local posy     = getElementData ( pInfoPickup, "PosY" ); 
    local posz      = getElementData ( pInfoPickup, "PosZ" ); 
    exports['mysql']:query_free ( "INSERT INTO `infopoints` ( posx, posy, posz, message ) VALUES ( '" .. exports.mysql:escape_string(posx) .. "', '" .. exports.mysql:escape_string(posy) .. "', '" .. exports.mysql:escape_string(posz) .. "', '" .. exports.mysql:escape_string(message) .. "' )" ); 
end 
  
function infohit(thePlayer) 
    local message = getElementData( infopointpickup,"Message") 
    outputChatBox("" .. message .."",thePlayer) 
end 
  
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, infopointpickup in pairs do exports['mysql']:query_free("SELECT * FROM infopoints") do 
        fnCreateInfo(infopointpickup["posx"], infopointpickup["posy"], infopointpickup["posz"], infopointpickup["message"]) 
    end 
    end 
end) 
  

Link to comment

This might work:

addEventHandler("onResourceStart",resourceRoot, 
function () 
    local infopointpickup = getElementsByType("pickup") 
    for index, infopointpickup in pairs do  
        local result = mysql:query_free("SELECT * FROM infopoints")  
        if (result) then 
        fnCreateInfo(infopointpickup["posx"], infopointpickup["posy"], infopointpickup["posz"], infopointpickup["message"]) 
        end 
    end 
    end 
end) 

(if it doesn't tell me the error)

Link to comment
This might work:
addEventHandler("onResourceStart",resourceRoot, 
function () 
    local infopointpickup = getElementsByType("pickup") 
    for index, infopointpickup in pairs do  
        local result = mysql:query_free("SELECT * FROM infopoints")  
        if (result) then 
        fnCreateInfo(infopointpickup["posx"], infopointpickup["posy"], infopointpickup["posz"], infopointpickup["message"]) 
        end 
    end 
    end 
end) 

(if it doesn't tell me the error)

expected ")" @ Line 67 To Close "(" @ Line 57 Near 'end'

Link to comment
This might work:
addEventHandler("onResourceStart",resourceRoot, 
function () 
    local infopointpickup = getElementsByType("pickup") 
    for index, infopointpickup in pairs do  
        local result = mysql:query_free("SELECT * FROM infopoints")  
        if (result) then 
        fnCreateInfo(infopointpickup["posx"], infopointpickup["posy"], infopointpickup["posz"], infopointpickup["message"]) 
        end 
    end 
    end 
end) 

(if it doesn't tell me the error)

I removed the extra end but you still get the (generator) expected table got nill error but at like 60 instead

Link to comment

Yes, Lua is a C++ extension...

  
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
  local result = mysql_query(host,"SELECT * FROM infopoints") -- U need to put the host 
    for index, infopointpickup in ipairs(result ) do 
         
  
        fnCreateInfo(infopointpickup ["posx"], infopointpickup ["posy"], infopointpickup["posz"], infopointpickup["message"]) 
        end 
     
     
end) 
  

Wait, mysql:query_free, lol...

Link to comment
mysql = exports.mysql 
  
function createInfoPoints( ) 
    local result = mysql:mysql_query("SELECT * FROM infopoints") 
    for index, infopointpickup in ipairs(result ) do 
     
      fnCreateInfo(infopointpickup ["posx"], infopointpickup ["posy"], infopointpickup["posz"], infopointpickup["message"]) 
    end 
end 
addEventHandler("onResourceStart",resourceRoot, createInfoPoints) 

Try that.

Link to comment

In his code, it appears the

  
  
mysql = exports.mysql 
  
  

The problem might be that there is no table.

You can check it, doing this

  
mysql = exports.mysql 
  
function createInfoPoints( ) 
    local result = mysql:mysql_query("SELECT * FROM infopoints") 
    if #result ~= 0 then 
    for index, infopointpickup in ipairs(result ) do 
    
      fnCreateInfo(infopointpickup ["posx"], infopointpickup ["posy"], infopointpickup["posz"], infopointpickup["message"]) 
end 
    end 
end 
addEventHandler("onResourceStart",resourceRoot, createInfoPoints) 
  

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