Jump to content

Check data


Klesh

Recommended Posts

Im trying to get the data when the player is login, doesnt show it!

    addEvent( 'onPlayerRaceWasted',true ) 
    addEvent( "stats", true ) 
      
    exports[ 'scoreboard' ]:addScoreboardColumn( 'Wins' ) 
    --exports[ 'scoreboard' ]:addScoreboardColumn( 'Deaths' ) 
    --exports[ 'scoreboard' ]:addScoreboardColumn( 'ratio' ) 
      
    local restriction = { } 
      
    function restrictionEnd( playerName ) 
        restriction[ playerName ] = nil 
    end 
      
      
    function publicstatsinfo( ) 
        if isElement( source ) then 
            local account = getPlayerAccount( source ) 
            if account then 
                if isGuestAccount( account ) then return end 
                local askdname = getPlayerName( source ) 
                local wins = getAccountData( account, "Wins" ) or 0 
                local loses = getAccountData( account, "Deaths" ) or 0 
                if loses and wins then 
                    --outputChatBox("#FFA824*" .. askdname .. " won " .. tostring( wins ) .. " times and he lost " ..tostring( loses ).. " times, his ratio is " .. tostring( ratio ) .. "%", root, 255, 12, 15, true) 
                end 
            end 
        else 
            outputChatBox( "Error source is not player" ) 
        end 
    end 
      
    
      
    function DestructionWin( vehicle ) 
        local alivePlayers = getAlivePlayers( ) 
        if #alivePlayers == 1 then 
            if isElement( alivePlayers[1] ) then 
                local account = getPlayerAccount( alivePlayers[1] ) 
                if isGuestAccount( account ) then return end 
                local count = tonumber( getAccountData( account,"Wins" ) or 0 ) + 1 
                setAccountData( account,"Wins",count ) 
                setElementData( alivePlayers[1],'Wins', count ) 
                --outputChatBox ( "#FFA824The player " .. getPlayerName( alivePlayers[1] ) .. " won!", root, 255, 255, 255, true ) 
            end 
        else 
            local account = getPlayerAccount( source ) 
            if isGuestAccount( account ) then return end 
            local loses = tonumber( getAccountData( account,"Deaths" ) or 0 ) + 1 
            setAccountData( account,"Deaths", loses ) 
            setElementData( source,'Deaths', loses ) 
        end 
    end 
     
        function onPlayerLogin ( _, acc ) 
        if acc then 
            local acc = getPlayerAccount ( source ) 
            local wins = getAccountData( account, "Wins" ) 
            if wins then 
               setAccountData(acc, wins) 
            end 
        end 
    end 
    addEventHandler ( "onPlayerLogin",root, onPlayerLogin ) 
      
      
    addEventHandler( "stats", root, publicstatsinfo ) 
    addEventHandler( "onPlayerRaceWasted", root,DestructionWin ) 
     
     

Link to comment
  
  local count = tonumber( getAccountData( account,"Wins" ) or 0 ) + 1 -- ????? 
                                      setAccountData( account,"Wins",count ) 
  

Why Not

  
local count = tonumber ( getAccountData ( account , "Wins" ) ) or 0 
     setAccountData ( account, "Wins",  tonumber(count) + 1) 
  

Link to comment
  
  local count = tonumber( getAccountData( account,"Wins" ) or 0 ) + 1 -- ????? 
                                      setAccountData( account,"Wins",count ) 
  

Why Not

  
local count = tonumber ( getAccountData ( account , "Wins" ) ) or 0 
     setAccountData ( account, "Wins",  tonumber(count) + 1) 
  

It makes no sense changing it because it's exactly the same.

Link to comment
  
  local count = tonumber( getAccountData( account,"Wins" ) or 0 ) + 1 -- ????? 
                                      setAccountData( account,"Wins",count ) 
  

Why Not

  
local count = tonumber ( getAccountData ( account , "Wins" ) ) or 0 
     setAccountData ( account, "Wins",  tonumber(count) + 1) 
  

It makes no sense changing it because it's exactly the same.

But why u reply everytimes negative in my post ? What is u problem? :lol:

This is correct :

  
local count = tonumber ( getAccountData ( account , "Wins" ) ) or 0 
     setAccountData ( account, "Wins",  tonumber(count) + 1) 
  

Link to comment
  
  local count = tonumber( getAccountData( account,"Wins" ) or 0 ) + 1 -- ????? 
                                      setAccountData( account,"Wins",count ) 
  

Why Not

  
local count = tonumber ( getAccountData ( account , "Wins" ) ) or 0 
     setAccountData ( account, "Wins",  tonumber(count) + 1) 
  

It makes no sense changing it because it's exactly the same.

But why u reply everytimes negative in my post ? What is u problem? :lol:

This is correct :

  
local count = tonumber ( getAccountData ( account , "Wins" ) ) or 0 
     setAccountData ( account, "Wins",  tonumber(count) + 1) 
  

It's not negative, I just said the truth. And as I said already before, it is correct just like the code he had before.

Link to comment
  
exports.scoreboard:addScoreboardColumn('Wins') 
function winScore () 
local sourceAccount = getPlayerAccount ( source ) 
local count = tonumber ( getAccountData ( sourceAccount , "Wins" ) ) or 0 
if count == false then 
setElementData ( source, "Wins", "0" ) 
else 
setElementData ( source, "Wins", count ) 
end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), winScore ) 
addEventHandler ( "onPlayerLogin", getRootElement(), winScore ) 
  

Tested with other Data

Link to comment
function onPlayerLogin ( _, acc ) 
    if ( acc ) then 
        local wins = tonumber ( getAccountData ( account, "Wins" ) ) or 0 
        setElementData ( source, "Wins", wins ) 
    end 
end 
addEventHandler ( "onPlayerLogin",root, onPlayerLogin ) 

That's easier.

Link to comment

How i can save this data ?

    addEvent( 'onPlayerRaceWasted',true ) 
    addEvent( "stats", true ) 
      
    exports[ 'scoreboard' ]:addScoreboardColumn( 'Wins' ) 
    --exports[ 'scoreboard' ]:addScoreboardColumn( 'Deaths' ) 
    --exports[ 'scoreboard' ]:addScoreboardColumn( 'ratio' ) 
      
    local restriction = { } 
      
    function restrictionEnd( playerName ) 
        restriction[ playerName ] = nil 
    end 
      
      
    function publicstatsinfo( ) 
        if isElement( source ) then 
            local account = getPlayerAccount( source ) 
            if account then 
                if isGuestAccount( account ) then return end 
                local askdname = getPlayerName( source ) 
                local wins = getAccountData( account, "Wins" ) or 0 
                local loses = getAccountData( account, "Deaths" ) or 0 
                if loses and wins then 
                    --outputChatBox("#FFA824*" .. askdname .. " won " .. tostring( wins ) .. " times and he lost " ..tostring( loses ).. " times, his ratio is " .. tostring( ratio ) .. "%", root, 255, 12, 15, true) 
                end 
            end 
        else 
            outputChatBox( "Error source is not player" ) 
        end 
    end 
      
    
      
    function DestructionWin( vehicle ) 
        local alivePlayers = getAlivePlayers( ) 
        if #alivePlayers == 1 then 
            if isElement( alivePlayers[1] ) then 
                local account = getPlayerAccount( alivePlayers[1] ) 
                if isGuestAccount( account ) then return end 
                local count = tonumber( getAccountData( account,"Wins" ) ) or 0  
                setAccountData( account,"Wins",count ) 
                setElementData( alivePlayers[1],'Wins', count ) 
                --outputChatBox ( "#FFA824The player " .. getPlayerName( alivePlayers[1] ) .. " won!", root, 255, 255, 255, true ) 
            end 
        else 
            local account = getPlayerAccount( source ) 
            if isGuestAccount( account ) then return end 
            local loses = tonumber( getAccountData( account,"Deaths" ) or 0 ) + 1 
            setAccountData( account,"Deaths", loses ) 
            setElementData( source,'Deaths', loses ) 
        end 
    end 
     
    function onPlayerLogin ( _, acc ) 
        if ( acc ) then 
            local wins = tonumber ( getAccountData ( account, "Wins" ) ) or 0 
            setElementData ( source, "Wins", wins ) 
        end 
    end 
    addEventHandler ( "onPlayerLogin",root, onPlayerLogin ) 
      
      
    addEventHandler( "stats", root, publicstatsinfo ) 
    addEventHandler( "onPlayerRaceWasted", root,DestructionWin ) 
     
     

Link to comment
function DestructionWin ( vehicle ) 
    local alivePlayers = getAlivePlayers ( ) 
    if ( #alivePlayers == 1 ) then 
        if isElement ( alivePlayers[1] ) then 
            local account = getPlayerAccount ( alivePlayers[1] ) 
            if isGuestAccount ( account ) then 
                return 
            end 
  
            local count = ( tonumber ( getAccountData ( account, "Wins" ) ) or 0 ) + 1 
            setAccountData ( account, "Wins", count ) 
            setElementData ( alivePlayers[1], 'Wins', count ) 
            --outputChatBox ( "#FFA824The player " .. getPlayerName( alivePlayers[1] ) .. " won!", root, 255, 255, 255, true ) 
        end 
    else 
        local account = getPlayerAccount ( source ) 
        if isGuestAccount ( account ) then 
            return 
        end 
  
        local loses = ( tonumber ( getAccountData( account,"Deaths" ) or 0 ) ) + 1 
        setAccountData ( account, "Deaths", loses ) 
        setElementData ( source, 'Deaths', loses ) 
    end 
end 

Link to comment
function DestructionWin ( vehicle ) 
    local alivePlayers = getAlivePlayers ( ) 
    if ( #alivePlayers == 1 ) then 
        outputChatBox ( "Passed check #1" ) 
        if isElement ( alivePlayers[1] ) then 
            outputChatBox ( "Passed check #2" ) 
            local account = getPlayerAccount ( alivePlayers[1] ) 
            if isGuestAccount ( account ) then 
                return 
            end 
            outputChatBox ( "Passed check #3" ) 
  
            local count = ( tonumber ( getAccountData ( account, "Wins" ) ) or 0 ) + 1 
            setAccountData ( account, "Wins", count ) 
            setElementData ( alivePlayers[1], 'Wins', count ) 
            --outputChatBox ( "#FFA824The player " .. getPlayerName( alivePlayers[1] ) .. " won!", root, 255, 255, 255, true ) 
        end 
    else 
        local account = getPlayerAccount ( source ) 
        if isGuestAccount ( account ) then 
            return 
        end 
  
        local loses = ( tonumber ( getAccountData( account,"Deaths" ) or 0 ) ) + 1 
        setAccountData ( account, "Deaths", loses ) 
        setElementData ( source, 'Deaths', loses ) 
    end 
end 

Post here what does it output to chat.

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