Jump to content

Bad Argument @ getPlayerSerial; Pls Help (:


Eistee

Recommended Posts

function getPlayerPoints (player, cmd, target) 
    if saveMethod == "database" then 
        if target then 
            local serial = getPlayerSerial(target) 
            local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'") 
            outputChatBox ( points, target, 255, 0, 0, true ) 
                if points then 
                    return tonumber(points[1]["points"]) 
             
                else 
                    outputDebugString("Pointsystem - getPlayerPoints (Db Problem") 
                end 
        else 
            outputChatBox("Error: /getp [player name]", player, 255, 0, 0) 
        end 
    end 
end 
addCommandHandler("getp", getPlayerPoints) 

I like to get the current Points from a player, if i do /getp xxxx.

But it doesnt work :/

Pls help (:

Full script:

local saveMethod = "database" 
  
function onStart() 
    if saveMethod == "database" then 
        executeSQLCreateTable("Punktesystem", "serial STRING,points INT") 
    end 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart) 
  
function onJoin() 
    local serial = getPlayerSerial(source) 
    getPoints  = executeSQLSelect ( "Punktesystem", "serial", "serial = '" .. serial .. "'" ) 
    if ( type( getPoints ) == "table" and #getPoints == 0 ) or not getPoints then  
        executeSQLInsert ( "Punktesystem", "'"..serial.."','0'" ) 
    end 
end 
addEventHandler("onPlayerJoin", root, onJoin) 
  
function onLogin(prev, acc) 
    if not getAccountData(acc, "points_class") or getAccountData(acc, "points_class") == nil then 
        setAccountData(acc, "points_class", 0) 
    end 
end 
addEventHandler("onPlayerLogin", root, onLogin) 
  
  
function getPlayerPoints (player, cmd, target) 
    if saveMethod == "database" then 
        if target then 
            local serial = getPlayerSerial(target) 
            local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'") 
            outputChatBox ( points, target, 255, 0, 0, true ) 
                if points then 
                    return tonumber(points[1]["points"]) 
             
                else 
                    outputDebugString("Punktesystem - getPlayerPoints (Datenbank Problem - Fehler beim Abfragen der Punkte!)") 
                end 
        else 
            outputChatBox("Error: /gp [player name]", player, 255, 0, 0) 
        end 
    end 
end 
addCommandHandler("getp", getPlayerPoints) 
  
function setPlayerPoints (thePlayer, pointsAmount) 
    if saveMethod == "database" then 
        local serial = getPlayerSerial(thePlayer) 
        executeSQLUpdate ( "Punktesystem", "points = '"..pointsAmount.."'","serial = '" .. serial .. "'") 
    end 
end 
  
function givePlayerPoints (thePlayer, pointsAmount) 
    if saveMethod == "database" then 
        local serial = getPlayerSerial(thePlayer) 
        local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'") 
        executeSQLUpdate ( "Punktesystem", "points = '"..tonumber(points[1]["points"]) + pointsAmount.."'","serial = '" .. serial .. "'") 
    end 
end 
  
function takePlayerPoints (thePlayer, pointsAmount) 
    if saveMethod == "database" then 
        local serial = getPlayerSerial(thePlayer) 
        local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'") 
        executeSQLUpdate ( "Punktesystem", "points = '"..tonumber(points[1]["points"]) - pointsAmount.."'","serial = '" .. serial .. "'") 
    end 
end 
  
  
  
function setpoints ( thePlayer, command, amount ) 
    if tonumber(amount) >= 0 then 
        setPlayerPoints(thePlayer, amount) 
    else 
        outputDebugString("Punktesystem testing: setp command -> Wert muss über 0 sein!") 
    end 
end 
addCommandHandler ( "setp", setpoints ) 
  
function givepoints ( thePlayer, command, amount ) 
    if tonumber(amount) >= 0 then 
        givePlayerPoints(thePlayer, amount) 
    else 
        outputDebugString("Punktesystem testing: givep command -> Wert muss über 0 sein!") 
    end 
end 
addCommandHandler ( "givep", givepoints ) 
  
function setpoints ( thePlayer, command, amount ) 
    if tonumber(amount) >= 0 then 
        takePlayerPoints(thePlayer, amount) 
    else 
        outputDebugString("Punktesystem testing: takep command -> Wert muss über 0 sein!") 
    end 
end 
addCommandHandler ( "takep", setpoints ) 

Edited by Guest
Link to comment

the target is a string follow your command(/getp xxxxx)

which is not a element, if the string is a player name. u need do getPlayerFromName ( string playerName ) first.

  
function getPlayerPoints (player, cmd, target) 
    if saveMethod == "database" then 
        if target then 
            local serial = getPlayerSerial(getPlayerFromName(target)) 
            local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'") 
            outputChatBox ( points, target, 255, 0, 0, true ) 
                if points then 
                    return tonumber(points[1]["points"]) 
            
                else 
                    outputDebugString("Pointsystem - getPlayerPoints (Db Problem") 
                end 
        else 
            outputChatBox("Error: /getp [player name]", player, 255, 0, 0) 
        end 
    end 
end 
addCommandHandler("getp", getPlayerPoints) 
  

Link to comment

[2014-08-20 17:09:54] WARNING: points\core_s.lua:30: Bad argument @ 'getPlayerSerial' [Expected player at argument 1, got boolean] 
[2014-08-20 17:09:54] ERROR: points\core_s.lua:31: attempt to concatenate local 'serial' (a boolean value) 

:/

Link to comment
function getPlayerPoints ( player, cmd, target ) 
    if ( saveMethod == "database" ) then 
        local target = getPlayerFromName ( tostring ( target ) ) 
        if ( target ) then 
            local serial = getPlayerSerial ( target ) 
            local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'") 
            outputChatBox ( points, target, 255, 0, 0, true ) 
            if ( points ) then 
                return tonumber ( points [ 1 ] [ "points" ] ) 
            else 
                outputDebugString ( "Pointsystem - getPlayerPoints (Db Problem" ) 
            end 
        else 
            outputChatBox ( "Error: /getp [player name]", player, 255, 0, 0 ) 
        end 
    end 
end 
addCommandHandler ( "getp", getPlayerPoints ) 

Link to comment

Full Script:

local saveMethod = "database" 
  
function onStart() 
    if saveMethod == "database" then 
        executeSQLCreateTable("Punktesystem", "serial STRING,points INT") 
    end 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), onStart) 
  
function onJoin() 
    local serial = getPlayerSerial(source) 
    getPoints  = executeSQLSelect ( "Punktesystem", "serial", "serial = '" .. serial .. "'" ) 
    if ( type( getPoints ) == "table" and #getPoints == 0 ) or not getPoints then  
        executeSQLInsert ( "Punktesystem", "'"..serial.."','0'" ) 
    end 
end 
addEventHandler("onPlayerJoin", root, onJoin) 
  
function onLogin(prev, acc) 
    if not getAccountData(acc, "points_class") or getAccountData(acc, "points_class") == nil then 
        setAccountData(acc, "points_class", 0) 
    end 
end 
addEventHandler("onPlayerLogin", root, onLogin) 
  
function getPlayerPoints ( player, cmd, target ) 
    if ( saveMethod == "database" ) then 
        local target = getPlayerFromName ( target ) 
        if ( target ) then 
            local serial = getPlayerSerial ( target ) 
            local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'") 
            outputChatBox ( points, target, 255, 0, 0, true ) 
            if ( points ) then 
                return tonumber ( points [ 1 ] [ "points" ] ) 
            else 
                outputDebugString ( "Pointsystem - getPlayerPoints (Db Problem" ) 
            end 
        else 
            outputChatBox ( "Error: /getp [player name]", player, 255, 0, 0 ) 
        end 
    end 
end 
addCommandHandler ( "getp", getPlayerPoints ) 
  
function setPlayerPoints (thePlayer, pointsAmount) 
    if saveMethod == "database" then 
        local serial = getPlayerSerial(thePlayer) 
        executeSQLUpdate ( "Punktesystem", "points = '"..pointsAmount.."'","serial = '" .. serial .. "'") 
    end 
end 
  
function givePlayerPoints (thePlayer, pointsAmount) 
    if saveMethod == "database" then 
        local serial = getPlayerSerial(thePlayer) 
        local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'") 
        executeSQLUpdate ( "Punktesystem", "points = '"..tonumber(points[1]["points"]) + pointsAmount.."'","serial = '" .. serial .. "'") 
    end 
end 
  
function takePlayerPoints (thePlayer, pointsAmount) 
    if saveMethod == "database" then 
        local serial = getPlayerSerial(thePlayer) 
        local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'") 
        executeSQLUpdate ( "Punktesystem", "points = '"..tonumber(points[1]["points"]) - pointsAmount.."'","serial = '" .. serial .. "'") 
    end 
end 
  
-------------------------------- 
----         TESTING        ---- 
-------------------------------- 
  
  
  
  
  
  
  
  
  
  
function setpoints ( thePlayer, command, amount ) 
    if tonumber(amount) >= 0 then 
        setPlayerPoints(thePlayer, amount) 
    else 
        outputDebugString("Punktesystem testing: setp command -> Wert muss über 0 sein!") 
    end 
end 
addCommandHandler ( "setp", setpoints ) 
  
function givepoints ( thePlayer, command, amount ) 
    if tonumber(amount) >= 0 then 
        givePlayerPoints(thePlayer, amount) 
    else 
        outputDebugString("Punktesystem testing: givep command -> Wert muss über 0 sein!") 
    end 
end 
addCommandHandler ( "givep", givepoints ) 
  
function setpoints ( thePlayer, command, amount ) 
    if tonumber(amount) >= 0 then 
        takePlayerPoints(thePlayer, amount) 
    else 
        outputDebugString("Punktesystem testing: takep command -> Wert muss über 0 sein!") 
    end 
end 
addCommandHandler ( "takep", setpoints ) 

Error: WARNING: points\core_s.lua:28: Bad argument @ 'getPlayerFromName' [Expected string at argument 1, got nil]

Link to comment

try this

    function getPlayerPoints ( player, cmd, target ) 
        if ( saveMethod == "database" ) then 
            local target = getPlayerFromName ( tostring ( target ) ) 
            if ( target ) then 
                local serial = getPlayerSerial ( target ) 
                local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'") 
                outputChatBox ( tostring ( points[1].points ), target, 255, 0, 0, true ) 
                if ( points ) then 
                    return tonumber ( points [ 1 ] [ "points" ] ) 
                else 
                    outputDebugString ( "Pointsystem - getPlayerPoints (Db Problem" ) 
                end 
            else 
                outputChatBox ( "Error: /getp [player name]", player, 255, 0, 0 ) 
            end 
        end 
    end 
    addCommandHandler ( "getp", getPlayerPoints ) 

Link to comment
addEvent ("viewGUI", true) 
function showGui ( sourcePlayer, cmd ) 
     
    if ( saveMethod == "database" ) then 
  
                    local serial = getPlayerSerial ( sourcePlayer ) 
                    local points = executeSQLSelect ( "Punktesystem", "points","serial = '" .. serial .. "'")    
                        triggerClientEvent ("viewGUI", sourcePlayer) 
                        triggerClientEvent ( "punk",  sourcePlayer, "" .. tostring ( points[1].points ) .. "") 
                    if ( points ) then 
                        return tonumber ( points [ 1 ] [ "points" ] ) 
                    else 
                        outputDebugString ( "Pointsystem - getPlayerPoints (Db Problem" ) 
                    end 
        end 
end 
addCommandHandler("pshop",showGui) 

    addEvent ("punk", true) 
    function punk (message) 
            guiSetText ( CurrentPoints_editbox , message ) 
    end 
    addEventHandler ("punk", getRootElement(), punk) 
  

did it already thanks for all your help (:

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