JkR Posted September 13, 2014 Share Posted September 13, 2014 local root = getRootElement() local scoresRoot = getResourceRootElement(getThisResource()) local scoreColumns = {"kills", "deaths", "self", "ratio", "status"} local isColumnActive = {} local KDR_DECIMAL_PLACES = 2 --http://lua-users.org/wiki/SimpleRound local function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end local function setScoreData (element, column, data) if isColumnActive[column] then setElementData(element, column, data) end end local function resetScores (element) setScoreData(element, "kills", 0) setScoreData(element, "deaths", 0) setScoreData(element, "self", 0) setScoreData(element, "ratio", "-") local status = "" if isPedDead(element) then status = "Dead" end setScoreData(element, "status", status) end local function updateRatio (element) local deaths = getElementData(element, "deaths") if deaths == 0 then setScoreData(element, "ratio", "-") else local kdr = round(getElementData(element, "kills") / deaths, KDR_DECIMAL_PLACES) setScoreData(element, "ratio", tostring(kdr)) end end function updateActiveColumns () for i, column in ipairs(scoreColumns) do if get(column) then isColumnActive[column] = true exports.scoreboard:addScoreboardColumn(column) elseif isColumnActive[column] then isColumnActive[column] = false exports.scoreboard:removeScoreboardColumn(column) end end end addEventHandler("onResourceStart", scoresRoot, function () updateActiveColumns() end ) addEventHandler("onResourceStop", scoresRoot, function () for i, column in ipairs(scoreColumns) do if isColumnActive[column] then exports.scoreboard:removeScoreboardColumn(column) end end end ) addEventHandler("onPlayerJoin", root, function () resetScores(source) end ) addEventHandler("onPlayerWasted", root, function (ammo, killer, weapon) if killer then if killer ~= source then -- killer killed victim setScoreData(killer, "kills", getElementData(killer, "kills") + 1) setScoreData(source, "deaths", getElementData(source, "deaths") + 1) if isColumnActive["ratio"] then updateRatio(killer) updateRatio(source) end else -- victim killed himself setScoreData(source, "self", getElementData(source, "self") + 1) end else -- victim died setScoreData(source, "deaths", getElementData(source, "deaths") + 1) if isColumnActive["ratio"] then updateRatio(source) end end setScoreData(source, "status", "Dead") end ) addEventHandler("onPlayerSpawn", root, function () setScoreData(source, "status", "") end ) addCommandHandler("score", function (player) if player then for i, column in ipairs(scoreColumns) do if column == "status" then break end if isColumnActive[column] then exports.scoreboard:addScoreboardColumn(column) outputConsole(column .. ": " .. getElementData(player, column), player) end end end end ) function onQuit () local account = getPlayerAccount(source) if account and not (isGuestAccount (account)) then local kills = getElementData(source, "kills") local deaths = getElementData(source,"deaths") local self = getElementData(source,"self") local ratio = getElementData(source,"ratio") setAccountData (account, "kills", kills ) setAccountData (account, "deaths", deaths ) setAccountData (account, "self", self ) setAccountData (account, "ratio", ratio ) end end addEventHandler ("onPlayerQuit", getRootElement(), onQuit) function onLogin () local acc = getPlayerAccount(source) local kills = getAccountData(acc, "kills") local deaths = getAccountData(acc, "deaths") local self = getAccountData(acc, "self") local ratio = getAccountData(acc, "ratio") if ( kills ) and (deaths ) and ( ratio ) then setElementData(source, "kills", kills) setElementData(source, "deaths", deaths) setElementData(source, "self", self) setElementData(source, "ratio", ratio) else setElementData(source, "kills", 0) setElementData(source, "deaths", 0) setElementData(source, "ratio", 0) end end addEventHandler("onPlayerLogin", getRootElement(), onLogin) --Guardado de kills, deaths y ratio function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local deaths = getElementData(source,"deaths") setAccountData ( playeraccount, "deaths", deaths ) end end local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local kills = getElementData(source,"kills") setAccountData ( playeraccount, "kills", kills ) end end local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local ratio = getElementData(source,"ratio") setAccountData ( playeraccount, "ratio", ratio ) end end function onPlayerLogin ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local deaths = getAccountData ( playeraccount, "deaths" ) if ( deaths ) then setElementData ( source, "deaths", deaths ) end end end local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local kills = getAccountData ( playeraccount, "kills" ) if ( kills ) then setElementData ( source, "kills", kills ) end end end local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local ratio = getAccountData ( playeraccount, "ratio" ) if ( ratio ) then setElementData ( source, "ratio", ratio ) end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogout", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) Me sale el error scores.lua:175 '(eof)' expected near 'end', no sé que falla alguien me ayuda por favor? The error is scores.lua:175 '(eof)' expected near 'end', i don't know the fail can you help me please? Link to comment
JkR Posted September 13, 2014 Author Share Posted September 13, 2014 English please? The error is scores.lua:175 '(eof)' expected near 'end', i don't know the fail can you help me please? Link to comment
xeon17 Posted September 13, 2014 Share Posted September 13, 2014 English please? The error is scores.lua:175 '(eof)' expected near 'end', i don't know the fail can you help me please? Remove one end. Link to comment
JkR Posted September 13, 2014 Author Share Posted September 13, 2014 English please? The error is scores.lua:175 '(eof)' expected near 'end', i don't know the fail can you help me please? Remove one end. Wich? Link to comment
JkR Posted September 13, 2014 Author Share Posted September 13, 2014 The end on line 175 Thanks Link to comment
xeon17 Posted September 13, 2014 Share Posted September 13, 2014 The end on line 175 Thanks You're welcome Link to comment
JkR Posted September 14, 2014 Author Share Posted September 14, 2014 The end on line 175 Thanks You're welcome I have a new problem local root = getRootElement() local scoresRoot = getResourceRootElement(getThisResource()) local scoreColumns = {"Kills", "Deaths", "eu", "Ratio", "estado"} local isColumnActive = {} local KDR_DECIMAL_PLACES = 2 --http://lua-users.org/wiki/SimpleRound local function round(num, idp) local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end local function setScoreData (element, column, data) if isColumnActive[column] then setElementData(element, column, data) end end local function resetScores (element) setScoreData(element, "Kills", 0) setScoreData(element, "Deaths", 0) setScoreData(element, "eu", 0) setScoreData(element, "Ratio", "-") local estado = "" if isPedDead(element) then estado = "Dead" end setScoreData(element, "estado", estado) end local function updateRatio (element) local Deaths = getElementData(element, "Deaths") if Deaths == 0 then setScoreData(element, "Ratio", "-") else local kdr = round(getElementData(element, "Kills") / Deaths, KDR_DECIMAL_PLACES) setScoreData(element, "Ratio", tostring(kdr)) end end function updateActiveColumns () for i, column in ipairs(scoreColumns) do if get(column) then isColumnActive[column] = true exports.scoreboard:addScoreboardColumn(column) elseif isColumnActive[column] then isColumnActive[column] = false exports.scoreboard:removeScoreboardColumn(column) end end end addEventHandler("onResourceStart", scoresRoot, function () updateActiveColumns() for i, player in ipairs(getElementsByType("player")) do resetScores(player) end end ) addEventHandler("onResourceStop", scoresRoot, function () for i, column in ipairs(scoreColumns) do if isColumnActive[column] then exports.scoreboard:removeScoreboardColumn(column) end end end ) addEventHandler("onPlayerJoin", root, function () resetScores(source) end ) addEventHandler("onPlayerWasted", root, function (ammo, killer, weapon) if killer then if killer ~= source then -- killer killed victim setScoreData(killer, "Kills", getElementData(killer, "Kills") + 1) setScoreData(source, "Deaths", getElementData(source, "Deaths") + 1) if isColumnActive["Ratio"] then updateRatio(killer) updateRatio(source) end else -- victim killed himeu setScoreData(source, "eu", getElementData(source, "eu") + 1) end else -- victim died setScoreData(source, "Deaths", getElementData(source, "Deaths") + 1) if isColumnActive["Ratio"] then updateRatio(source) end end setScoreData(source, "estado", "Dead") end ) addEventHandler("onPlayerSpawn", root, function () setScoreData(source, "estado", "") end ) addCommandHandler("score", function (player) if player then for i, column in ipairs(scoreColumns) do if column == "estado" then break end if isColumnActive[column] then exports.scoreboard:addScoreboardColumn(column) outputConsole(column .. ": " .. getElementData(player, column), player) end end end end ) --Guardado de Kills Deaths y Ratio function onPlayerQuit ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local Deaths = getElementData(source,"Deaths") setAccountData ( playeraccount, "Deaths", Deaths ) end end local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local Kills = getElementData(source,"Kills") setAccountData ( playeraccount, "Kills", Kills ) end local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local Ratio = getElementData(source,"Ratio") setAccountData ( playeraccount, "Ratio", Ratio ) end function onPlayerLogin ( ) local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local Deaths = getAccountData ( playeraccount, "Deaths" ) if ( Deaths ) then setElementData ( source, "Deaths", Deaths ) end end end local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local Kills = getAccountData ( playeraccount, "Kills" ) if ( Kills ) then setElementData ( source, "Kills", Kills ) end end local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) then local Ratio = getAccountData ( playeraccount, "Ratio" ) if ( Ratio ) then setElementData ( source, "Ratio", Ratio ) end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogout", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) addEventHandler ( "onResourceStop", getRootElement ( ), onPlayerQuit ) addEventHandler ( "onResourceStart", getRootElement ( ), onPlayerLogin ) When I restart the resource, kills deaths and ratio comes to 0 Link to comment
Et-win Posted September 14, 2014 Share Posted September 14, 2014 This isn't your script, isn't it? Link to comment
JkR Posted September 14, 2014 Author Share Posted September 14, 2014 This isn't your script, isn't it? No, is a default script, I did only the saved of the kills ratio and deaths Link to comment
xeon17 Posted September 14, 2014 Share Posted September 14, 2014 This isn't your script, isn't it? It's the defualt MTA Scores script mixed with my script viewtopic.php?f=91&t=75488&p=695566&hilit=scores#p695566 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