Jump to content

First SQL Script, Help Please =P


12p

Recommended Posts

Thanks to all scripters that have patience to help all noobish scripters, like me :P

OK, I'm trying to create my own "Top Scores" system with GUI.

Everythings works but 1 thing... Rows aren't added.

I don't know what is happening, no debug errors, even from mine.

The thing I noticed with custom debugging is that normally when a row is added, there should be a "+1 row" message; that one doesn't shows, anytime.

SERVER SIDE:

function updateSQLRowForPlayer(p) 
    local name = getPlayerName(p) 
    local acc = getPlayerAccount (p) 
    if not isGuestAccount (acc) then 
        local kills = getAccountData (acc,"zombieKills") 
        local level = getAccountData (acc,"rankLvl") 
        local test = executeSQLSelect ("levelling","player_name","player_name = '"..name.."'") 
        if test == false then 
            local acc = getPlayerAccount (p) 
            if executeSQLInsert ("levelling","'"..name.."', "..kills..", "..level) then 
                outputDebugString ("SQL Database has created a row for "..name.."!") 
            else 
                outputDebugString ("SQL Database got error when creating a row for "..name.."!") 
            end 
        else 
            if executeSQLUpdate ("levelling","player_name = '"..name.."', kills = '"..kills.."', level = '"..level.."'", "player_name = '"..name.."'") then 
                outputDebugString ("SQL Database has updated "..name.." row!") 
            else 
                outputDebugString ("SQL Database got error when updating "..name.." row!") 
            end 
        end 
    end 
end 
  
function getHighScores () 
    local highScores = executeSQLQuery ("SELECT player_name, kills, level FROM levelling") 
    if highScores then 
        return highScores 
    else 
        outputDebugString ("Error when trying to get high scores!") 
        return false 
    end 
end 
  
setTimer(triggerClientEvent,1500,1,"onClientHighScoresUpdate",getRootElement(),getHighScores()) 
  

CLIENT SIDE:

addEventHandler ("onClientHighScoresUpdate",getRootElement(), 
function (scores) 
    if type(scores) == "table" then 
      for i,s in ipairs (scores) do 
        outputDebugString ("+1 Row!") --THIS DOESNT APPEAR! WHAT THE...? IF "scores" IS A TABLE, WHY DOESNT GET SHOWED ANY DEBUG MESSAGE LIKE THIS? 
        local row = guiGridListAddRow (scoresGrid) 
        guiGridListSetItemText (scoresGrid,row,1,s[1],false,false) 
        guiGridListSetItemText (scoresGrid,row,2,tostring(s[2]),false,true) 
        guiGridListSetItemText (scoresGrid,row,3,tostring(s[3]),false,true) 
      end 
    else 
      outputDebugString ("Problem with the high scores table, looks like isn't processed!") --THIS DOESNT APPEARS TOO! 
    end 
end) 

Why aren't rows added? Maybe tables can't be synced with events?

Link to comment
Thanks to all scripters that have patience to help all noobish scripters, like me :P

OK, I'm trying to create my own "Top Scores" system with GUI.

Everythings works but 1 thing... Rows aren't added.

I don't know what is happening, no debug errors, even from mine.

The thing I noticed with custom debugging is that normally when a row is added, there should be a "+1 row" message; that one doesn't shows, anytime.

SERVER SIDE:

function updateSQLRowForPlayer(p) 
    local name = getPlayerName(p) 
    local acc = getPlayerAccount (p) 
    if not isGuestAccount (acc) then 
        local kills = getAccountData (acc,"zombieKills") 
        local level = getAccountData (acc,"rankLvl") 
        local test = executeSQLSelect ("levelling","player_name","player_name = '"..name.."'") 
        if test == false then 
            local acc = getPlayerAccount (p) 
            if executeSQLInsert ("levelling","'"..name.."', "..kills..", "..level) then 
                outputDebugString ("SQL Database has created a row for "..name.."!") 
            else 
                outputDebugString ("SQL Database got error when creating a row for "..name.."!") 
            end 
        else 
            if executeSQLUpdate ("levelling","player_name = '"..name.."', kills = '"..kills.."', level = '"..level.."'", "player_name = '"..name.."'") then 
                outputDebugString ("SQL Database has updated "..name.." row!") 
            else 
                outputDebugString ("SQL Database got error when updating "..name.." row!") 
            end 
        end 
    end 
end 
  
function getHighScores () 
    local highScores = executeSQLQuery ("SELECT player_name, kills, level FROM levelling") 
    if highScores then 
        return highScores 
    else 
        outputDebugString ("Error when trying to get high scores!") 
        return false 
    end 
end 
  
setTimer(triggerClientEvent,1500,1,"onClientHighScoresUpdate",getRootElement(),getHighScores()) 
  

CLIENT SIDE:

addEventHandler ("onClientHighScoresUpdate",getRootElement(), 
function (scores) 
    if type(scores) == "table" then 
      for i,s in ipairs (scores) do 
        outputDebugString ("+1 Row!") --THIS DOESNT APPEAR! WHAT THE...? IF "scores" IS A TABLE, WHY DOESNT GET SHOWED ANY DEBUG MESSAGE LIKE THIS? 
        local row = guiGridListAddRow (scoresGrid) 
        guiGridListSetItemText (scoresGrid,row,1,s[1],false,false) 
        guiGridListSetItemText (scoresGrid,row,2,tostring(s[2]),false,true) 
        guiGridListSetItemText (scoresGrid,row,3,tostring(s[3]),false,true) 
      end 
    else 
      outputDebugString ("Problem with the high scores table, looks like isn't processed!") --THIS DOESNT APPEARS TOO! 
    end 
end) 

Why aren't rows added? Maybe tables can't be synced with events?

the problem might be opening event will likely need to be getLocal Player ()

server

  
setTimer(triggerClientEvent,1500,1,"onClientHighScoresUpdate",source,getHighScores())   
  

client

  
addEvent ( "onClientHighScoresUpdate", true )  -- lol you forgot to add Event. 
addEventHandler ("onClientHighScoresUpdate",getLocalPlayer(), 
function (scores) 
  

I'm not sure what is right.

P.s and yet I doubt setTimer ()

Link to comment

ok... volk, you aren't right. That event hasn't a player as source, because I don't want to, and it

  
setTimer(triggerClientEvent,1500,1,"onClientHighScoresUpdate",source,getHighScores())   
  

What source? LOL there is no source -.-

  
addEvent ( "onClientHighScoresUpdate", true )  -- I did this in my source code, just I forgot to add it to the code I passed here. 
addEventHandler ("onClientHighScoresUpdate",getLocalPlayer(), --As the event source ISNT A PLAYER, then that event won't work, ever. 
function (scores) 
  

Link to comment

it was returning nil for me, seems that i fixed it :P

addEvent("onClientHighScoresUpdate",true) 
addEventHandler ("onClientHighScoresUpdate",getRootElement(), 
function (scores) 
    if type(scores) == "table" then 
      for i,s in ipairs (scores) do 
        outputDebugString ("+1 Row!") 
        local row = guiGridListAddRow (scoresGrid) 
        guiGridListSetItemText (scoresGrid,row,1,tostring(s["player_name"]),false,false) 
        guiGridListSetItemText (scoresGrid,row,2,tostring(s["kills"]),false,true) 
        guiGridListSetItemText (scoresGrid,row,3,tostring(s["level"]),false,true) 
      end 
    else 
      outputDebugString ("Problem with the high scores table, looks like isn't processed!") 
    end 
end) 

now it adds a row with:

[MM]Castillo 100 500 

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