MR.Kingos Posted May 24, 2019 Share Posted May 24, 2019 Alguém poderia me ajudar pra salvar Kill, Deaths etc? Procurei pela net mas nenhum totalmente funcional... 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() 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 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 ) Link to comment
DNL291 Posted May 24, 2019 Share Posted May 24, 2019 addEventHandler "onPlayerQuit" "onResourceStop" "onPlayerLogout" getElementData getPlayerAccount setAccountData "onPlayerLogin" getAccountData setElementData Você vai precisar dessas funções/evento. 1 Link to comment
MR.Kingos Posted May 24, 2019 Author Share Posted May 24, 2019 1 minute ago, DNL291 said: addEventHandler"onPlayerQuit""onResourceStop""onPlayerLogout"getElementDatagetPlayerAccountsetAccountData"onPlayerLogin"getAccountDatasetElementData Você vai precisar dessas funções/evento. Como usaria essas funções? Link to comment
Jonas^ Posted May 24, 2019 Share Posted May 24, 2019 (edited) Pelo visto não foi você que fez esse resource, nem se quer pelo visto abriu os links que o @DNL291 lhe forneceu, tentar então nem pensar, vou te dar o código pronto só desta vez, próxima vez tente fazer com os links que te fornecerem e poste o código assim você mostra interesse em aprender. Código: ----------------------------- -- Salvamento/Carregamento -- ----------------------------- function savePlayerKills (thePlayer, acc) local acc = acc or getPlayerAccount (thePlayer) if not isGuestAccount(acc) and thePlayer then local setkills = getElementData (thePlayer, "kills") or 0 local setdeaths = getElementData (thePlayer, "deaths") or 0 setAccountData (acc, "kills", tostring(setkills)) setAccountData (acc, "deaths", tostring(setdeaths)) end end function loadPlayerKills (thePlayer) local acc = getPlayerAccount (thePlayer) if not isGuestAccount(acc) then local getKills = tonumber(getAccountData(acc, "kills")) or 0 local getDeaths = tonumber(getAccountData(acc, "deaths")) or 0 setElementData (thePlayer, "kills", getKills) setElementData (thePlayer, "deaths", getDeaths) end end addEventHandler ("onResourceStop", resourceRoot, function () for i, p in pairs (getElementsByType("player")) do savePlayerKills (p) end end) addEventHandler ("onResourceStart", resourceRoot, function () for i, p in pairs (getElementsByType("player")) do loadPlayerKills (p) end end) addEventHandler ("onPlayerQuit", root, function () savePlayerKills (source) end) addEventHandler ("onPlayerLogout", root, function (acc) savePlayerKills (source, acc) end) addEventHandler ("onPlayerLogin", root, function () loadPlayerKills (source) end) Adicione no final do seu código. @MR.Kingos Edited May 24, 2019 by Jonas^ 1 Link to comment
MR.Kingos Posted May 24, 2019 Author Share Posted May 24, 2019 41 minutes ago, Jonas^ said: Pelo visto não foi você que fez esse resource, nem se quer pelo visto abriu os links que o @DNL291 lhe forneceu, tentar então nem pensar, vou te dar o código pronto só desta vez, próxima vez tente fazer com os links que te fornecerem e poste o código assim você mostra interesse em aprender. Código: ------------------------------- Salvamento/Carregamento -------------------------------function savePlayerKills (thePlayer, acc) local acc = acc or getPlayerAccount (thePlayer) if not isGuestAccount(acc) and thePlayer then local setkills = getElementData (thePlayer, "kills") or 0 local setdeaths = getElementData (thePlayer, "deaths") or 0 setAccountData (acc, "kills", tostring(setkills)) setAccountData (acc, "deaths", tostring(setdeaths)) endendfunction loadPlayerKills (thePlayer) local acc = getPlayerAccount (thePlayer) if not isGuestAccount(acc) then local getKills = tonumber(getAccountData(acc, "kills")) or 0 local getDeaths = tonumber(getAccountData(acc, "deaths")) or 0 setElementData (thePlayer, "kills", getKills) setElementData (thePlayer, "deaths", getDeaths) endendaddEventHandler ("onResourceStop", resourceRoot, function () for i, p in pairs (getElementsByType("player")) do savePlayerKills (p) endend) addEventHandler ("onResourceStart", resourceRoot, function () for i, p in pairs (getElementsByType("player")) do loadPlayerKills (p) endend) addEventHandler ("onPlayerQuit", root, function () savePlayerKills (source)end)addEventHandler ("onPlayerLogout", root, function (acc) savePlayerKills (source, acc)end) addEventHandler ("onPlayerLogin", root, function () loadPlayerKills (source)end) Adicione no final do seu código. @MR.Kingos Sim, é o resource padrão do jogo. Estou tentando até agora tirar alguns avisos Deu certo aqui... estava só com alguns 'symbol near'. Obrigado novamente, @Jonas^ Outra duvida é, consigo usar as mesma funções no PlayTime? Link to comment
DNL291 Posted May 24, 2019 Share Posted May 24, 2019 Você vai precisar do element-data do playtime, de resto é só aplicar o getElementData + setAccountData para o salvamento seguindo a mesma ideia do código do Jonas. 1 Link to comment
Jonas^ Posted May 24, 2019 Share Posted May 24, 2019 Esses símbolos são do fórum, é só formatar o código pra ANSI e tira-los e colocar em UTF-8 (sem bom) novamente. Se o playTime for um timer que soma quantos segundos o jogador estiver logado em cada sessão, tem um código pronto aqui: 1 Link to comment
MR.Kingos Posted May 24, 2019 Author Share Posted May 24, 2019 Grato @DNL291 e @Jonas^ 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