Ir para conteúdo
  • Cadastre-se

(Resolvido)To Frags Online


Ir para solução Resolvido por Vodkart,

Posts Recomendados

Alguém poderia arrumar esse mod pra mim ? Ele aparece o top frags normal mais quando o player desloga ele continua la, queria que no top frags online só ficasse os player que estão realmente online...

 

Script do @Vodkart

 

Spoiler

<?xml version="1.0" encoding="ISO-8859-1"?>
<mod name="rank frag" version="1.0" author="Vodkart" contact="xtibia.com" enabled="yes">  
<config name="rankf_func"><![CDATA[
storage = 824544
function getPlayerFrags(cid)
    local time = os.time()
    local times = {today = (time - 86400), week = (time - (7 * 86400))}
    local contents, result = {day = {}, week = {}, month = {}}, db.getResult("SELECT `pd`.`date`, `pd`.`level`, `p`.`name` FROM `player_killers` pk LEFT JOIN `killers` k ON `pk`.`kill_id` = `k`.`id` LEFT JOIN `player_deaths` pd ON `k`.`death_id` = `pd`.`id` LEFT JOIN `players` p ON `pd`.`player_id` = `p`.`id` WHERE `pk`.`player_id` = " .. getPlayerGUID(cid) .. " AND `k`.`unjustified` = 1 AND `pd`.`date` >= " .. (time - (30 * 86400)) .. " ORDER BY `pd`.`date` DESC")
    if(result:getID() ~= -1) then
        repeat
            local content = {date = result:getDataInt("date")}
            if(content.date > times.today) then
                table.insert(contents.day, content)
            elseif(content.date > times.week) then
                table.insert(contents.week, content)
            else
                table.insert(contents.month, content)
            end
        until not result:next()
        result:free()
    end
    local size = {day = table.maxn(contents.day),week = table.maxn(contents.week),month = table.maxn(contents.month)} 
    return size.day + size.week + size.month
end
function setFrags(cid)
if not isCreature(cid) then return LUA_ERROR end
setPlayerStorageValue(cid, storage, getPlayerFrags(cid))
doPlayerSave(cid)
end
function getRankStorage(value, max, RankName)
local str = "".. (RankName == nil and "RANK STORAGE" or ""..RankName.."") .."\n"
local query = db.getResult("SELECT `player_id`, `value` FROM `player_storage` WHERE `key` = "..value.." ORDER BY cast(value as INTEGER) DESC;")
if (query:getID() ~= -1) then 
k = 1 
repeat 
str = str .. "\n " .. k .. ". "..getPlayerNameByGUID(query:getDataString("player_id")).." - " .. query:getDataInt("value") .. ""
k = k + 1 
until k > max  or not query:next() 
end 
return str
end
]]></config>
<globalevent name="RankFrags_Broad" interval="120" event="script"><![CDATA[
domodlib('rankf_func')
function onThink(interval, lastExecution)
doBroadcastMessage(getRankStorage(storage, 5, "Top 5 Fraggers Online!"), 21)
return true
end]]></globalevent>
<event type="login" name="RankfLogin" event="script"><![CDATA[
domodlib('rankf_func')
function onLogin(cid)
registerCreatureEvent(cid, "RankfKill")
setFrags(cid)
return true
end]]></event>      
<event type="kill" name="RankfKill" event="script"><![CDATA[
domodlib('rankf_func')
function onKill(cid, target, lastHit)
if (isPlayer(cid) == true) and (isPlayer(target) == true) then
addEvent(setFrags, 1000, cid)
end
return true
end]]></event>
</mod>

 

Editado por Tchukixx (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
<?xml version="1.0" encoding="ISO-8859-1"?>
<mod name="rank frag" version="1.0" author="Vodkart" contact="xtibia.com" enabled="yes">  
<config name="rankf_func"><![CDATA[
storage = 824544
function getPlayerFrags(cid)
    local time = os.time()
    local times = {today = (time - 86400), week = (time - (7 * 86400))}
    local contents, result = {day = {}, week = {}, month = {}}, db.getResult("SELECT `pd`.`date`, `pd`.`level`, `p`.`name` FROM `player_killers` pk LEFT JOIN `killers` k ON `pk`.`kill_id` = `k`.`id` LEFT JOIN `player_deaths` pd ON `k`.`death_id` = `pd`.`id` LEFT JOIN `players` p ON `pd`.`player_id` = `p`.`id` WHERE `pk`.`player_id` = " .. getPlayerGUID(cid) .. " AND `k`.`unjustified` = 1 AND `pd`.`date` >= " .. (time - (30 * 86400)) .. " ORDER BY `pd`.`date` DESC")
    if(result:getID() ~= -1) then
        repeat
            local content = {date = result:getDataInt("date")}
            if(content.date > times.today) then
                table.insert(contents.day, content)
            elseif(content.date > times.week) then
                table.insert(contents.week, content)
            else
                table.insert(contents.month, content)
            end
        until not result:next()
        result:free()
    end
    local size = {day = table.maxn(contents.day),week = table.maxn(contents.week),month = table.maxn(contents.month)} 
    return size.day + size.week + size.month
end
function setFrags(cid)
	if not isCreature(cid) then return LUA_ERROR end
	setPlayerStorageValue(cid, storage, getPlayerFrags(cid))
	doPlayerSave(cid)
end
function RemovePlayerFromRank(p)
	db.executeQuery("DELETE FROM `player_storage` WHERE `player_id` = ".. p .." AND `key` = "..storage)
end
function getRankStorage(value, max, RankName)
	local str = "".. (RankName == nil and "RANK STORAGE" or ""..RankName.."") .."\n"
	local query = db.getResult("SELECT `player_id`, `value` FROM `player_storage` WHERE `key` = "..value.." ORDER BY cast(value as INTEGER) DESC;")
	if (query:getID() ~= -1) then 
		k = 1 
		repeat 
			str = str .. "\n " .. k .. ". "..getPlayerNameByGUID(query:getDataString("player_id")).." - " .. query:getDataInt("value") .. ""
			k = k + 1 
		until k > max or not query:next() 
	end 
	return str
end
]]></config>
<globalevent name="RankFrags_Broad" interval="120" event="script"><![CDATA[
domodlib('rankf_func')
function onThink(interval, lastExecution)
doBroadcastMessage(getRankStorage(storage, 5, "Top 5 Fraggers Online!"), 21)
return true
end]]></globalevent>
<event type="login" name="RankfLogin" event="script"><![CDATA[
domodlib('rankf_func')
function onLogin(cid)
registerCreatureEvent(cid, "RankfKill")
setFrags(cid)
return true
end]]></event>
<event type="logout" name="RankfLogout" event="script"><![CDATA[
domodlib('rankf_func')
function onLogout(cid)
local player = getPlayerGUID(cid)
      addEvent(RemovePlayerFromRank, 1000, player)   
	return true
end]]></event>   
<event type="kill" name="RankfKill" event="script"><![CDATA[
domodlib('rankf_func')
function onKill(cid, target, lastHit)
if (isPlayer(cid) == true) and (isPlayer(target) == true) then
addEvent(setFrags, 1000, cid)
end
return true
end]]></event>
</mod>

 

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Link para o post
Compartilhar em outros sites

@Vodkart Obrigado, também achei um mais simples pelo globalevents e funciona só que da o seguinte erro no console:

 

Spoiler

Error during getDataInt(frags).
> Broadcasted message: " RookWar 
Top 1 fraggers online!

1. GOD - 0 frags".

 

Script:

Spoiler

local config = {
 limit = 5
}
function onThink(interval, lastExecution)
 local t, ret, tmp = {}, "Top " .. math.min(config.limit, getWorldCreatures(0)) .. " fraggers online! \n"
 for _, cid in ipairs(getPlayersOnline()) do
 tmp =  db.getResult("SELECT `frags` FROM `players` WHERE `name` = '"..getCreatureName(cid).."';")
 table.insert(t, {cid, tmp:getDataInt("frags")})
 tmp:free()
 end
 table.sort(t, function(a,b) return a[2] > b[2] end)
 for i = 1, math.min(#t, config.limit) do
 ret = ret .. "\n" .. i .. ". " .. getPlayerName(t[1]) .. " - " .. t[2] .. " frags"
 end
 return doBroadcastMessage(ret)
end

 

Sabe como resolve-lo?

Editado por Tchukixx (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
  • Solução
<?xml version="1.0" encoding="ISO-8859-1"?>
<mod name="rank frag" version="1.0" author="Vodkart" contact="xtibia.com" enabled="yes">  
<config name="rankf_func"><![CDATA[
storage = 824544
function getPlayerFrags(cid)
    local time = os.time()
    local times = {today = (time - 86400), week = (time - (7 * 86400))}
    local contents, result = {day = {}, week = {}, month = {}}, db.getResult("SELECT `pd`.`date`, `pd`.`level`, `p`.`name` FROM `player_killers` pk LEFT JOIN `killers` k ON `pk`.`kill_id` = `k`.`id` LEFT JOIN `player_deaths` pd ON `k`.`death_id` = `pd`.`id` LEFT JOIN `players` p ON `pd`.`player_id` = `p`.`id` WHERE `pk`.`player_id` = " .. getPlayerGUID(cid) .. " AND `k`.`unjustified` = 1 AND `pd`.`date` >= " .. (time - (30 * 86400)) .. " ORDER BY `pd`.`date` DESC")
    if(result:getID() ~= -1) then
        repeat
            local content = {date = result:getDataInt("date")}
            if(content.date > times.today) then
                table.insert(contents.day, content)
            elseif(content.date > times.week) then
                table.insert(contents.week, content)
            else
                table.insert(contents.month, content)
            end
        until not result:next()
        result:free()
    end
    local size = {day = table.maxn(contents.day),week = table.maxn(contents.week),month = table.maxn(contents.month)} 
    return size.day + size.week + size.month
end
function setFrags(cid)
if not isCreature(cid) then return LUA_ERROR end
setPlayerStorageValue(cid, storage, getPlayerFrags(cid))
doPlayerSave(cid)
end
function getRankStorage(value, max, RankName)
    local str = "".. (RankName == nil and "RANK STORAGE" or ""..RankName.."") .."\n"
     local players = getPlayersOnline()
    table.sort(players, function(a, b) return getPlayerStorageValue(a, value) > getPlayerStorageValue(b,value) end)
    k = 0
    for x = 1, table.maxn(players) do
        k = k + 1 
        str = str .. "\n " .. k .. ". "..getCreatureName(players[x]).." - " .. getPlayerStorageValue(players[x], value) .. " frags"
        if k == max then break end 
    end
    return str
end
]]></config>
<globalevent name="RankFrags_Broad" interval="120" event="script"><![CDATA[
domodlib('rankf_func')
function onThink(interval, lastExecution)
doBroadcastMessage(getRankStorage(storage, 5, "Top 5 Fraggers Online!"), 21)
return true
end]]></globalevent>
<event type="login" name="RankfLogin" event="script"><![CDATA[
domodlib('rankf_func')
function onLogin(cid)
registerCreatureEvent(cid, "RankfKill")
setFrags(cid)
return true
end]]></event>      
<event type="kill" name="RankfKill" event="script"><![CDATA[
domodlib('rankf_func')
function onKill(cid, target, lastHit)
if (isPlayer(cid) == true) and (isPlayer(target) == true) then
addEvent(setFrags, 1000, cid)
end
return true
end]]></event>
</mod>

 

Editado por Vodkart (veja o histórico de edições)

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Link para o post
Compartilhar em outros sites

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo