• 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!

[TFS 1.4] Demote level command for later version

Joriku

Working in the mines, need something?
Joined
Jul 16, 2016
Messages
1,084
Solutions
15
Reaction score
379
Location
Sweden
YouTube
Joriku
Soo, I could not find anything updated as a command such as /demote player which resets the player's level.
So here it is:
Lua:
local demoteLocation = Position(979, 979, 6) -- location

local downgrade = TalkAction("/demote") -- rev, instead of xml

function downgrade.onSay(player, words, param) -- call upon function onsay
    if not player:getGroup():getAccess() then -- get group access
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then -- account type
        return false
    end

    local split = param:splitTrimmed(",")
    local target = Player(split[1])
    if not target then
        player:sendCancelMessage("A player with that name is not online.") -- player not found
        return false
    end
    target:removeExperience(target:getExperience()*100.00) -- remove 100% of player level
    target:sendTextMessage(MESSAGE_ATTENTION, "Your level has been removed due to level abusing.") -- send message to target/player command used on
    player:sendTextMessage(MESSAGE_ATTENTION, "Command has been executed successfully, Player has been demoted to level 1.") -- send message to command executor
    target:teleportTo(demoteLocation+Position) -- teleport player to location
    return true
end

downgrade:separator(" ")
downgrade:register()

This can be used with something auto that adds the player back to level 8 upon login:
(I found this on Otland somewhere, can't find it again and don't bother where, credits to the guy who made it.)
Lua:
local function getExp(level) return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3 end

local creatureevent = CreatureEvent("add_experience")

function getExpForLevel(level, offsetLevel)
    level       = level - 1
    offsetLevel = offsetLevel and offsetLevel - 1 or nil

    local total = getExp(level)
    local offset = offsetLevel and offsetLevel < level and getExp(offsetLevel) or 0
    return total - offset
end

function Player:addLevel(amount, round, ...)
  local exp    = 0
  local level  = self:getLevel()

  exp = math.abs(getExpForLevel(level + amount) - (round and self:getExperience() or getExpForLevel(level)))
  return amount >= 0 and self:addExperience(exp, ...) or self:removeExperience(exp, ...)
end

function Player:setLevel(level, round, ...)
  return self:addLevel(level - self:getLevel(), round == nil or round, ...)
end

function creatureevent.onLogin(player)
  -- How to use on login
  if player:getLevel() < 8 then
    local level = 8
    local round = true
    local sendText = false
    player:setLevel(level, round, sendText)
  end
  return true
end

creatureevent:register()

ab360ae4860efa3f868d60b4c01884dc.jpg
 
Back
Top