Klesh Posted November 21, 2012 Share Posted November 21, 2012 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
Castillo Posted November 21, 2012 Share Posted November 21, 2012 Instead of: setAccountData(acc, wins) It should be: setElementData ( source, "Wins", wins ) Link to comment
Klesh Posted November 21, 2012 Author Share Posted November 21, 2012 Changed, still the same error, the data doesn't set when player login! Link to comment
HunT Posted November 21, 2012 Share Posted November 21, 2012 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
Anderl Posted November 21, 2012 Share Posted November 21, 2012 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
HunT Posted November 21, 2012 Share Posted November 21, 2012 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? This is correct : local count = tonumber ( getAccountData ( account , "Wins" ) ) or 0 setAccountData ( account, "Wins", tonumber(count) + 1) Link to comment
Klesh Posted November 21, 2012 Author Share Posted November 21, 2012 In fact, this resolves something about this? when the player joins show the wins he/she have, its empty. Link to comment
Castillo Posted November 21, 2012 Share Posted November 21, 2012 Changed, still the same error, the data doesn't set when player login! Try adding a debug output to see what 'wins' return when you login. @Hunterix: Is both the same thing, it won't make any difference. Link to comment
Anderl Posted November 21, 2012 Share Posted November 21, 2012 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? 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
HunT Posted November 21, 2012 Share Posted November 21, 2012 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
Castillo Posted November 21, 2012 Share Posted November 21, 2012 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
Klesh Posted November 22, 2012 Author Share Posted November 22, 2012 It works but if the player has 20 wins and he/she login the data is 0 no 20, at least if he wins when the map finish! Link to comment
Castillo Posted November 22, 2012 Share Posted November 22, 2012 Which means the script is not really saving anything. Link to comment
Klesh Posted November 22, 2012 Author Share Posted November 22, 2012 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
Castillo Posted November 22, 2012 Share Posted November 22, 2012 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
Klesh Posted November 22, 2012 Author Share Posted November 22, 2012 Now doesn't work when someone wins, and is the same, onPlayerlogin doesn't show the data, i try to fix it but nothing! Link to comment
Castillo Posted November 22, 2012 Share Posted November 22, 2012 Is not even updating the 'Wins' element data? Link to comment
Klesh Posted November 22, 2012 Author Share Posted November 22, 2012 I fix it by my own, thanks anyways to everyone! Link to comment
Castillo Posted November 22, 2012 Share Posted November 22, 2012 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
Castillo Posted November 22, 2012 Share Posted November 22, 2012 Mind telling us what was it? Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now