Ir para conteúdo

Ranking diferente in-game


Mudrock

Posts Recomendados

E4GsaUhs.png

Comando para utilizar

!highscores

TUTORIAL

/globalevents/globalevents.xml

<globalevent type="startup" name="Highscore" script="highscores.lua"/>
<globalevent interval="10800000" name="Highscores" script="highscores.lua"/>

/globalevents/scripts/highscores.lua

local QueryList = {
['Level'] = {'`name`, `level` AS `score` FROM `players`', 'ORDER BY `experience` DESC'},
['Magic Level'] = {'`name`, `maglevel` AS `score` FROM `players`', 'ORDER BY `maglevel` DESC, `manaspent` DESC'},
--['Storage'] = {'`players`.`name` AS `name`, `value` AS `score` FROM `player_storage` LEFT JOIN `players` ON `player_storage`.`player_id` = `players`.`id`', 'AND `key` = 1550 ORDER BY `value` DESC'}
}

for i, skill in ipairs({'fist','club','sword','axe','dist','shielding','fishing'}) do
local index = (skill == 'dist' and 'Distance' or skill:gsub('^%l',string.upper)) .. (i < 6 and ' Fighting' or '')
QueryList[index] = {'`name`, `skill_' .. skill .. '` AS `score` FROM `players`','ORDER BY `skill_' .. skill .. '` DESC, `skill_' .. skill .. '_tries` DESC'}
end

function updateHighscores()
for skill, query in pairs(QueryList) do
local t, Query = {}, db.storeQuery('SELECT ' .. query[1] .. ' WHERE `deletion` = 0 AND `group_id` < 3 ' .. query[2] .. ' LIMIT 30;')
if Query ~= false then
repeat
table.insert(t, {result.getDataString(Query, 'name'), result.getDataInt(Query, 'score')})
until not result.next(Query)
result.free(Query)
setGlobalStorageValue(skill, t)
end
end
setGlobalStorageValue('highscores', os.time())
end

function onStartup()
updateHighscores()
end

function onThink(interval)
updateHighscores()
return true
end/creaturescripts/creaturescripts.xml<event type="modalwindow" name="Highscores" script="highscores.lua"/>/creaturescripts/scripts/highscores.luaSkillWindow = {
[1337] = 'Local highscores at ' .. getConfigInfo('serverName'),
[1338] = 'Level', [1339] = 'Magic Level', [1340] = 'Shielding',
[1341] = 'Distance Fighting', [1342] = 'Sword Fighting', [1343] = 'Club Fighting',
[1344] = 'Axe Fighting', [1345] = 'Fist Fighting', [1346] = 'Fishing',
--[1347] = 'Storage'
}

highscores = ModalWindow(1337, SkillWindow[1337], 'Choose a category:')
for i, skill in ipairs({'Level','Magic','Shielding','Distance','Sword','Club','Axe','Fist','Fishing'}) do
highscores:addChoice(i, skill)
end
--highscores:addChoice(10, 'Storage')
highscores:addButton(1, 'Show')
highscores:addButton(2, 'Close')
highscores:addButton(3, 'Info')
highscores:setDefaultEnterButton(1)
highscores:setDefaultEscapeButton(2)
highscores:setPriority(true)

function string.diff(diff) --by Colandus and fixed by Cykotitan
local format = {
{'day', diff / 60 / 60 / 24},
{'hour', diff / 60 / 60 % 24},
{'minute', diff / 60 % 60},
{'second', diff % 60}
}

local out = {}
for k, t in ipairs(format) do
local v = math.floor(t[2])
if(v > 0) then
table.insert(out, (k < #format and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
end
end
local ret = table.concat(out)
if ret:len() < 16 and ret:find('second') then
local a, b = ret:find(' and ')
ret = ret:sub(b+1)
end
return ret
end

function string.abbr(first, final, limit)
local str = first .. final
if str:len() > limit then
str = first:sub(1, limit-(final:len())) .. final
end
return str
end

function sendSkillWindow(cid, windowId)
local highscore = ModalWindow(windowId, 'Ranking for ' .. SkillWindow[windowId], 'Scroll down for entire list')
for rank, score in ipairs(getGlobalStorageValue(SkillWindow[windowId])) do
highscore:addChoice(rank, string.abbr(rank .. '. ' .. score[1], '... ' .. score[2], 30))
end
highscore:addButton(1, 'Back')
highscore:addButton(2, 'Close')
highscore:addButton(3, 'Info')
highscore:setDefaultEscapeButton(2)
highscore:setPriority(true)
highscore:sendToPlayer(cid)
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId)

if not SkillWindow[modalWindowId] then
return
end

if buttonId == 3 then
doPlayerPopupFYI(cid, 'Local highscores were last updated ' .. string.diff(os.time()-getGlobalStorageValue('highscores')) .. ' ago.')
elseif buttonId == 1 then
if modalWindowId == 1337 then
sendSkillWindow(cid, 1337+choiceId)
else
highscores:sendToPlayer(cid)
end
return
end

return unregisterCreatureEvent(cid, 'Highscores')
end

/talkactions/talkactions.xml

<talkaction words="!highscores" script="highscores.lua" />

/talkactions/scripts/highscores.lua

function onSay(cid, words, param)
registerCreatureEvent(cid, 'Highscores')
highscores:sendToPlayer(cid)
return false
end

Créditos :

  • cbrm
Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...