• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Method to call player.getSkillLevel (axe, sword, distance, etc.)

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Staff member
Board Moderator
Joined
Dec 17, 2011
Messages
1,776
Solutions
31
Reaction score
1,014
Location
Santiago - Chile
Hi! I use TFS 1.4 8.6 downgrade and opened this thread to ask the following. I use this script made bby @Sarah Wesker
LUA:
local config = {
    topCount = 5,
    messageType = MESSAGE_EVENT_ADVANCE,
    interval = 15 * 60 * 1000 -- 15 minutes for each
}

local currentTopType = 1
local topTypes = {
    { 'Level', Player.getLevel },
    { 'Magic Level', Player.getMagicLevel },
    { 'Sword', Player.getSkillLevel },
    { 'Axe', Player.getSkillLevel },
    { 'Club', Player.getSkillLevel },
    { 'Distance', Player.getSkillLevel },
    { 'Shield', Player.getSkillLevel }
    --{ 'Fish', Player.getSkillLevel },
    --{ 'Fist', Player.getSkillLevel }
}

local globalEvent = GlobalEvent("TopLevelOnline")
function globalEvent.onThink(interval)
    local type = topTypes[currentTopType]
    local getSkill = type[2]
    local types = #topTypes
    currentTopType = math.min(types, currentTopType +1)
    if currentTopType == types then
        currentTopType = 1
    end
    local players = Game.getPlayers()
    local count = math.min(config.topCount, #players)
    if count > 0 then
        if count > 1 then
            table.sort(players, function(a, b) return getSkill(a) > getSkill(b) end)
        end
        local description = string.format("~ Top %d Online / %s ~\n\n", config.topCount, type[1])
        for i = 1, count do
            local p = players[i]
            description = string.format("%s%d) %s - %d%s", description, i, p:getName(), getSkill(p), (i == count and "" or "\n"))
        end
        broadcastMessage(description, config.messageType)
    end
    return true
end
globalEvent:interval(config.interval)
globalEvent:register()

and the trouble is that the highscores shown at sword, axe, club, distance, and shield indicates fist skill instead the corresponding one. I wonder how is the proper method to add the skills, instead of { 'Sword', Player.getSkillLevel }, use something like player.getSwordLevel. Would be nice to have this script working :)

In advance, thanks
Regards!
 
Last edited:
Solution
Ready:
LUA:
local config = {
    topCount = 5,
    messageType = MESSAGE_EVENT_ADVANCE,
    interval = 15 * 60 * 1000 -- 15 minutes for each
}

local currentTopType = 1
local topTypes = {
    { 'Level', Player.getLevel },
    { 'Magic Level', Player.getMagicLevel },
    { 'Sword', Player.getSkillLevel, SKILL_SWORD },
    { 'Axe', Player.getSkillLevel, SKILL_AXE },
    { 'Club', Player.getSkillLevel, SKILL_CLUB },
    { 'Distance', Player.getSkillLevel, SKILL_DISTANCE },
    { 'Shield', Player.getSkillLevel, SKILL_SHIELD }
    --{ 'Fish', Player.getSkillLevel },
    --{ 'Fist', Player.getSkillLevel }
}

local globalEvent = GlobalEvent("TopLevelOnline")
function globalEvent.onThink(interval)
    local type = topTypes[currentTopType]
    local getSkill =...
Ready:
LUA:
local config = {
    topCount = 5,
    messageType = MESSAGE_EVENT_ADVANCE,
    interval = 15 * 60 * 1000 -- 15 minutes for each
}

local currentTopType = 1
local topTypes = {
    { 'Level', Player.getLevel },
    { 'Magic Level', Player.getMagicLevel },
    { 'Sword', Player.getSkillLevel, SKILL_SWORD },
    { 'Axe', Player.getSkillLevel, SKILL_AXE },
    { 'Club', Player.getSkillLevel, SKILL_CLUB },
    { 'Distance', Player.getSkillLevel, SKILL_DISTANCE },
    { 'Shield', Player.getSkillLevel, SKILL_SHIELD }
    --{ 'Fish', Player.getSkillLevel },
    --{ 'Fist', Player.getSkillLevel }
}

local globalEvent = GlobalEvent("TopLevelOnline")
function globalEvent.onThink(interval)
    local type = topTypes[currentTopType]
    local getSkill = type[2]
    local types = #topTypes
    currentTopType = currentTopType+1
    if currentTopType == types+1 then
        currentTopType = 1
    end
    local players = Game.getPlayers()
    local count = math.min(config.topCount, #players)
    if count > 0 then
        if count > 1 then
            table.sort(players, function(a, b) return getSkill(a) > getSkill(b) end)
        end
        local description = string.format("~ Top %d Online / %s ~\n\n", config.topCount, type[1])
        for i = 1, count do
            local p = players[i]
            description = string.format("%s%d) %s - %d%s", description, i, p:getName(), getSkill(p, type[3]), (i == count and "" or "\n"))
        end
        broadcastMessage(description, config.messageType)
    end
    return true
end
globalEvent:interval(config.interval)
globalEvent:register()
 
Solution
I added an option to hide access players, thanks for noticing this @ralke <3
 
@Sarah Wesker after some more tests, saw it still has some bugs
record.png

Level skills are showing properly, but skill ones has a bad order.
Any idea of what can be happening? Ill try to merge more test screenshots, Regards!
 
Back
Top