GanJaRuleZ Posted January 14, 2012 Author Share Posted January 14, 2012 As you see here : http://imageshack.us/photo/my-images/85 ... 50831.png/ I losed , but it still outputs that i didn't losed or won.. Link to comment
Kenix Posted January 14, 2012 Share Posted January 14, 2012 Because source is nil and not output in chat Check it and write in next post what output function DestructionWin( ) local alivePlayers = getAlivePlayers( ) if #alivePlayers == 1 then local account = getPlayerAccount( alivePlayers[1] ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Wins",tostring( getAccountData( account,"Race Wins" ) or 0 ) +1 ) end local playername = getPlayerName( alivePlayers[1] ) outputChatBox ( "#FFA824The player " .. playername .. " won!", root, 255, 255, 255, true ) end end addEventHandler( "onPlayerWasted", root, function( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Loses",tostring( getAccountData( account,"Race Loses" ) or 0 )+1 ) end end ) function ratioCalculator( player ) local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local raceLoses = getAccountData( account,"Race Loses" ) if raceLoses == 0 then setAccountData( account, "Ratio", "-") else local kdr = round( getAccountData( account, "Race Wins" ) / raceLoses, KDR_DECIMAL_PLACES ) setAccountData( account, "Ratio", tostring(kdr)) end end end addEventHandler( "onPlayerQuit",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local timePlayed = getElementData( source, "Time played" ) if not timePlayed then setAccountData( account, "Time played","0:0:0" ) end local hours, mins, secs = unpack( split( timePlayed, ":" ) ) setAccountData( account, "Time played", tostring( hours or 0 ) ..":".. tostring( mins or 0 ) ..":".. tostring( secs or 0 ) ) end end ) addEventHandler( "onPlayerLogin",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local raceWins = getAccountData( account,"Race Wins" ) or 0 local raceLoses = getAccountData( account,"Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 setElementData( source,"Race Wins",tostring( raceWins ) ) setElementData( source,"Race Loses",tostring( raceLoses ) ) setElementData( source,"Ratio",tostring( ratio ) ) end setTimer( function( player ) local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local timePlayed = getAccountData( account, "Time played" ) if not timePlayed then setElementData( player, "Time played","0:0:0" ) end local hours, mins, secs = unpack( split( timePlayed, ":" ) ) local hours = tonumber( hours ) or 0 local mins = tonumber( mins ) or 0 local secs = tonumber( secs ) or 0 local newsec if hours and mins and secs then newsec = secs + 1 if ( newsec >= 60 ) then newsec = 0 mins = mins + 1 end if ( mins >= 60 ) then mins = 0 hours = hours + 1 end setElementData ( player, "Time played", tostring( hours ) ..":".. tostring( mins ) ..":".. tostring( newsec ) ) end end end ,1000,1, source ) 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, "Race Wins" ) or 0 local loses = getAccountData( account, "Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 local timePlayed = getAccountData( account, "Time played" ) local hours, mins, secs = unpack( split( timePlayed, ":" ) ) if loses and wins then outputChatBox("#FFA824*" .. tostring( askdname ) .. " won " .. tostring( wins ) .. " times and he/she lost " ..tostring( loses ).. " times, his/her ratio is " .. tostring( ratio ) .. " and the total time played he/she is: " .. tostring( hours or 0 ) ..":".. tostring( mins or 0 ) ..":".. tostring( secs or 0 ), root, 255, 12, 15, true) else outputChatBox("*You don't losed or won" , root, 255, 12, 15, true) end end else outputChatBox( "Eror source is not player" ) end end addEvent( "stats", true ) addEventHandler( "stats", root, publicstatsinfo ) function checkCommand( message, messageType ) if messageType == 0 then if message == "!stats" then triggerEvent( "stats", source ) cancelEvent( ) end end end addEventHandler( "onPlayerChat", root, checkCommand ) Link to comment
GanJaRuleZ Posted January 14, 2012 Author Share Posted January 14, 2012 *GanJaRulez won 0 times and he/she lost 2 times, his/her ratio is 0 and the total time played he/she is: 0:0:0 *GanJaRulez won 0 times and he/she lost 2 times, his/her ratio is 0 and the total time played he/she is: 0:0:0 First was made when i started the resource The second is after 10 seconds.. , so it doesen't counts... Link to comment
Kenix Posted January 14, 2012 Share Posted January 14, 2012 You need create infinite timer( for update ) https://wiki.multitheftauto.com/wiki/SetTimer See in arguments local timers = { } function DestructionWin( ) local alivePlayers = getAlivePlayers( ) if #alivePlayers == 1 then local account = getPlayerAccount( alivePlayers[1] ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Wins",tostring( getAccountData( account,"Race Wins" ) or 0 ) +1 ) end local playername = getPlayerName( alivePlayers[1] ) outputChatBox ( "#FFA824The player " .. playername .. " won!", root, 255, 255, 255, true ) end end addEventHandler( "onPlayerWasted", root, function( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Loses",tostring( getAccountData( account,"Race Loses" ) or 0 )+1 ) end end ) function ratioCalculator( player ) local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local raceLoses = getAccountData( account,"Race Loses" ) if raceLoses == 0 then setAccountData( account, "Ratio", "-") else local kdr = round( getAccountData( account, "Race Wins" ) / raceLoses, KDR_DECIMAL_PLACES ) setAccountData( account, "Ratio", tostring(kdr)) end end end addEventHandler( "onPlayerQuit",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local timePlayed = getElementData( source, "Time played" ) if not timePlayed then setAccountData( account, "Time played","0:0:0" ) end local hours, mins, secs = unpack( split( timePlayed, ":" ) ) setAccountData( account, "Time played", tostring( hours or 0 ) ..":".. tostring( mins or 0 ) ..":".. tostring( secs or 0 ) ) end if isTimer( timers[ source ] ) then killTimer( timers[ source ] ) timers[ source ] = nil end end ) addEventHandler( "onPlayerLogin",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local raceWins = getAccountData( account,"Race Wins" ) or 0 local raceLoses = getAccountData( account,"Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 setElementData( source,"Race Wins",tostring( raceWins ) ) setElementData( source,"Race Loses",tostring( raceLoses ) ) setElementData( source,"Ratio",tostring( ratio ) ) end timers[ source ] = setTimer( function( player ) local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local timePlayed = getAccountData( account, "Time played" ) if not timePlayed then setElementData( player, "Time played","0:0:0" ) end local hours, mins, secs = unpack( split( timePlayed, ":" ) ) local hours = tonumber( hours ) or 0 local mins = tonumber( mins ) or 0 local secs = tonumber( secs ) or 0 local newsec if hours and mins and secs then newsec = secs + 1 if ( newsec >= 60 ) then newsec = 0 mins = mins + 1 end if ( mins >= 60 ) then mins = 0 hours = hours + 1 end setElementData ( player, "Time played", tostring( hours ) ..":".. tostring( mins ) ..":".. tostring( newsec ) ) end end end ,1000,0, source ) 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, "Race Wins" ) or 0 local loses = getAccountData( account, "Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 local timePlayed = getAccountData( account, "Time played" ) local hours, mins, secs = unpack( split( timePlayed, ":" ) ) if loses and wins then outputChatBox("#FFA824*" .. tostring( askdname ) .. " won " .. tostring( wins ) .. " times and he/she lost " ..tostring( loses ).. " times, his/her ratio is " .. tostring( ratio ) .. " and the total time played he/she is: " .. tostring( hours or 0 ) ..":".. tostring( mins or 0 ) ..":".. tostring( secs or 0 ), root, 255, 12, 15, true) else outputChatBox("*You don't losed or won" , root, 255, 12, 15, true) end end else outputChatBox( "Eror source is not player" ) end end addEvent( "stats", true ) addEventHandler( "stats", root, publicstatsinfo ) function checkCommand( message, messageType ) if messageType == 0 then if message == "!stats" then triggerEvent( "stats", source ) cancelEvent( ) end end end addEventHandler( "onPlayerChat", root, checkCommand ) Link to comment
GanJaRuleZ Posted January 14, 2012 Author Share Posted January 14, 2012 function DestructionWin( ) local alivePlayers = getAlivePlayers( ) if #alivePlayers == 1 then local account = getPlayerAccount( alivePlayers[1] ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Wins",tostring( getAccountData( account,"Race Wins" ) or 0 ) +1 ) end local playername = getPlayerName( alivePlayers[1] ) outputChatBox ( "#FFA824The player " .. playername .. " won!", root, 255, 255, 255, true ) end end addEventHandler( "onPlayerWasted", root, function( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Loses",tostring( getAccountData( account,"Race Loses" ) or 0 )+1 ) end end ) function ratioCalculator( player ) local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local raceLoses = getAccountData( account,"Race Loses" ) if raceLoses == 0 then setAccountData( account, "Ratio", "-") else local kdr = round( getAccountData( account, "Race Wins" ) / raceLoses, KDR_DECIMAL_PLACES ) setAccountData( account, "Ratio", tostring(kdr)) end end end addEventHandler( "onPlayerLogin",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local raceWins = getAccountData( account,"Race Wins" ) or 0 local raceLoses = getAccountData( account,"Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 setElementData( source,"Race Wins",tostring( raceWins ) ) setElementData( source,"Race Loses",tostring( raceLoses ) ) setElementData( source,"Ratio",tostring( ratio ) ) end 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, "Race Wins" ) or 0 local loses = getAccountData( account, "Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 if loses and wins then outputChatBox("#FFA824*" .. tostring( askdname ) .. " won " .. tostring( wins ) .. " times and he lost " ..tostring( loses ).. " times, his ratio is " .. tostring( ratio ) %, root, 255, 12, 15, true) else outputChatBox("#FFA824*" .. tostring( askdname ).. " doesen't losed or won " , root, 255, 12, 15, true) end end else outputChatBox( "Error source is not player" ) end end addEvent( "stats", true ) addEventHandler( "stats", root, publicstatsinfo ) function checkCommand( message, messageType ) if messageType == 0 then if message == "!stats" then triggerEvent( "stats", source ) cancelEvent( ) end end end addEventHandler( "onPlayerChat", root, checkCommand ) I decided to remove time played , but now i have another error : SCRIPT ERROR: stats\stats:66: unexpected symbol near ',' Link to comment
GTX Posted January 14, 2012 Share Posted January 14, 2012 function DestructionWin( ) local alivePlayers = getAlivePlayers( ) if #alivePlayers == 1 then local account = getPlayerAccount( alivePlayers[1] ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Wins",tostring( getAccountData( account,"Race Wins" ) or 0 ) +1 ) end local playername = getPlayerName( alivePlayers[1] ) outputChatBox ( "#FFA824The player " .. playername .. " won!", root, 255, 255, 255, true ) end end addEventHandler( "onPlayerWasted", root, function( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Loses",tostring( getAccountData( account,"Race Loses" ) or 0 )+1 ) end end ) function ratioCalculator( player ) local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local raceLoses = getAccountData( account,"Race Loses" ) if raceLoses == 0 then setAccountData( account, "Ratio", "-") else local kdr = round( getAccountData( account, "Race Wins" ) / raceLoses, KDR_DECIMAL_PLACES ) setAccountData( account, "Ratio", tostring(kdr)) end end end addEventHandler( "onPlayerLogin",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local raceWins = getAccountData( account,"Race Wins" ) or 0 local raceLoses = getAccountData( account,"Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 setElementData( source,"Race Wins",tostring( raceWins ) ) setElementData( source,"Race Loses",tostring( raceLoses ) ) setElementData( source,"Ratio",tostring( ratio ) ) end 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, "Race Wins" ) or 0 local loses = getAccountData( account, "Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 if loses and wins then outputChatBox("#FFA824*" .. tostring( askdname ) .. " won " .. tostring( wins ) .. " times and he lost " ..tostring( loses ).. " times, his ratio is " .. tostring( ratio ) .. "%", root, 255, 12, 15, true) else outputChatBox("#FFA824*" .. tostring( askdname ).. " doesen't losed or won " , root, 255, 12, 15, true) end end else outputChatBox( "Error source is not player" ) end end addEvent( "stats", true ) addEventHandler( "stats", root, publicstatsinfo ) function checkCommand( message, messageType ) if messageType == 0 then if message == "!stats" then triggerEvent( "stats", source ) cancelEvent( ) end end end addEventHandler( "onPlayerChat", root, checkCommand ) 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