• 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

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,470
Solutions
27
Reaction score
844
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
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
 
Back
Top