Jump to content

SQL set nick


Memory

Recommended Posts

Hello, please, help me add "nick" to Points Table. I can't set name of player to "nick", have error - Database query failed: no such column "nick".

function onResStart () 
executeSQLQuery ("CREATE TABLE IF NOT EXISTS Points ( serial TEXT, nick TEXT, points INTEGER DEFAULT 0 )" ); 
end 
addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource ( ) ), onResStart ) 
-------------------------------- 
function onJoin ( ) 
    local serial = getPlayerSerial ( source ); 
    local getPoints = executeSQLQuery ( "SELECT points FROM Points WHERE serial=?", serial ); 
    if type ( getPoints ) == "table" and #getPoints > 0 and getPoints[1] and getPoints[1].points then 
        setElementData ( source, "Points", tonumber ( getPoints[1].points ) ); 
    else 
        executeSQLQuery ( "INSERT INTO Points VALUES ( ?, ? )", serial, 0 ); 
        setElementData ( source, "Points", 0 ); 
    end 
end 
addEventHandler ( "onPlayerJoin", root, onJoin) 
---------------------------------------- 
function onPlayerQuit ( ) 
    local getActualPoints = tonumber ( getElementData ( source, "Points" ) ); 
    local getNickPlayer = getPlayerName(source); 
    local serial = getPlayerSerial ( source ); 
    local sql = executeSQLQuery ( "SELECT points FROM Points WHERE serial=?", serial ); 
    executeSQLQuery ( "UPDATE Points SET points=? WHERE serial=?", getActualPoints, serial ); 
    local sqlnick = executeSQLQuery ( "SELECT nick FROM Points WHERE serial=?", serial ); 
    executeSQLQuery ( "UPDATE Points SET nick=? WHERE serial=?", getNickPlayer, serial ); 
end 
addEventHandler("onPlayerQuit", root, onPlayerQuit) 

Link to comment

Thank you, but it don't work

ERROR: [gameplay]\points\points.lua:19: Database query failed: Cannot add a NOT NULL column with default value NULL 

Can be you mean FULL, but it too don't work

ERROR: [gameplay]\points\points.lua:19: Database query failed: near "FULL": syntax error 

Link to comment

I have anyway any problem. Fix, please.

Create table and save.

function onResStart ()

executeSQLQuery ( "CREATE TABLE IF NOT EXISTS Points ( serial TEXT, points INTEGER DEFAULT 0 )" );

executeSQLQuery ( "ALTER TABLE Points ADD nick VARCHAR(22)" );

end

addEventHandler ( "onResourceStart", getResourceRootElement ( getThisResource ( ) ), onResStart )

--------------------------------

function onJoin ( )

local serial = getPlayerSerial ( source );

local getPoints = executeSQLQuery ( "SELECT points FROM Points WHERE serial=?", serial );

if type ( getPoints ) == "table" and #getPoints > 0 and getPoints[1] and getPoints[1].points then

setElementData ( source, "Points", tonumber ( getPoints[1].points ) or 0);

else

executeSQLQuery ( "INSERT INTO Points VALUES ( ?, ? )", serial, 0 );

setElementData ( source, "Points", 0 );

end

end

addEventHandler ( "onPlayerJoin", root, onJoin)

----------------------------------------

function onPlayerQuit ( )

local getActualPoints = tonumber ( getElementData ( source, "Points" ) );

local getNickPlayer = getPlayerName(source);

local serial = getPlayerSerial ( source );

local sql = executeSQLQuery ( "SELECT points FROM Points WHERE serial=?", serial );

executeSQLQuery ( "UPDATE Points SET points=? WHERE serial=?", getActualPoints, serial );

local sqlnick = executeSQLQuery ( "SELECT nick FROM Points WHERE serial=?", serial );

executeSQLQuery ( "UPDATE Points SET nick=? WHERE serial=?", getNickPlayer, serial );

end

addEventHandler("onPlayerQuit", root, onPlayerQuit)

I would like add "nick" for top of players.

addCommandHandler( 'top', 
    function( pPlayer ) 
        outputChatBox( 'TOP 10 PLAYERS', pPlayer ) 
        local aQuery = executeSQLQuery( 'SELECT points, nick FROM `Points` ORDER BY `points` DESC LIMIT 10' ) 
        if type( aQuery ) == 'table' and #aQuery > 0 then 
            for _, v in ipairs( aQuery ) do 
                outputChatBox( 'Player:' .. v[ 'nick' ] .. ', points:' .. v[ 'points' ], pPlayer ) 
            end 
        end 
    end 
) 

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