Fury Posted June 6, 2012 Share Posted June 6, 2012 function getAliveRacePlayers() local alivePlayers = 0 for index,player in ipairs(getElementsByType("player")) do if getElementData(player,"state") == "alive" then alivePlayers = alivePlayers + 1 end end return alivePlayers end function getDeadRacePlayers() local deadPlayers = 0 for index,player in ipairs(getElementsByType("player")) do if getElementData(player,"state") == "dead" then deadPlayers = deadPlayers + 1 end end return deadPlayers end function loadPlayerData ( player, datatype ) if ( not player or not isElement( player ) ) then return false end local playerIP = getPlayerSerial ( player ) if ( playerIP ) then local root = xmlLoadFile ("users.xml") if ( root ) then local usersNode = xmlFindChild ( root, "user", 0 ) if ( usersNode ) then local playerRootNode = xmlFindChild ( usersNode, "SERIAL_" .. getPlayerSerial(player), 0 ) if not ( playerRootNode == false ) then local playerData = xmlNodeGetAttribute ( playerRootNode, datatype ) if ( playerData ) then xmlUnloadFile ( root ) return playerData else xmlNodeSetAttribute ( playerRootNode, datatype, 0 ) xmlSaveFile ( root ) xmlUnloadFile ( root ) return 0 end else local playerRootNode = xmlCreateChild ( usersNode, "SERIAL_" .. getPlayerSerial(player) ) xmlNodeSetAttribute ( playerRootNode, datatype, 0 ) xmlSaveFile ( root ) xmlUnloadFile ( root ) return 0 end end end end end function savePlayerData ( player, datatype, newvalue ) if ( not player or not isElement( player ) ) then return false end local playerIP = getPlayerSerial (player) if ( playerIP ) then local root = xmlLoadFile ("users.xml") if ( root ) then local usersNode = xmlFindChild ( root, "user", 0 ) if ( usersNode ) then local playerRootNode = xmlFindChild ( usersNode, "SERIAL_" .. getPlayerSerial(player), 0 ) if not ( playerRootNode == false ) then local newNodeValue = xmlNodeSetAttribute ( playerRootNode, datatype, newvalue ) xmlSaveFile ( root ) xmlUnloadFile ( root ) return newNodeValue else local playerRootNode = xmlCreateChild ( usersNode, "SERIAL_" .. getPlayerSerial(player) ) local newNodeValue = xmlNodeSetAttribute ( playerRootNode, datatype, newvalue ) xmlSaveFile ( root ) xmlUnloadFile ( root ) return newNodeValue end end end end end addEvent("onPlayerDestructionDerbyWin",true) addEventHandler("onPlayerDestructionDerbyWin",getRootElement(), function (winnar) if ( getPlayerCount() >= 2 )then local dPlayers = getDeadRacePlayers() local aPlayers = getAliveRacePlayers() local cashToWin = 1 local playerCash = tonumber( loadPlayerData( winnar, "wins" ) ) savePlayerData( winnar, "wins", playerCash + cashToWin ) local pointsToWin = math.floor(100*(dPlayers + aPlayers)) local playerPoints = tonumber ( loadPlayerData( winnar, "points" ) ) savePlayerData( winnar, "points", playerPoints + pointsToWin ) outputChatBox ( "#c0c0c0* #abcdef"..string.gsub(getPlayerName (winnar),"#%x%x%x%x%x%x","").." #c0c0c0has win this round and gets 30 points!", root, 255, 255, 255, true ) else outputChatBox( "#c0c0c0* Not enough players to earn point - #ABCDEF2 players #c0c0c0required.", winnar, 255, 255, 255, true ) scoreboardRefresh ( winnar ) refreshStats ( winnar ) progressBarUpdate ( winnar ) totalMoneyAchievements ( winnar ) end end ) what is wrong with this code? its not working and dont give any error. Link to comment
Kenix Posted June 6, 2012 Share Posted June 6, 2012 Debug by hand. outputChatBox outputDebugString Link to comment
GTX Posted June 7, 2012 Share Posted June 7, 2012 Are you triggering the event "onPlayerDestructionDerbyWin"? Link to comment
Fury Posted June 7, 2012 Author Share Posted June 7, 2012 Are you triggering the event "onPlayerDestructionDerbyWin"? yeah. i solved the problem. its about with rankingboard.lua 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