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

RevScripts !reset

vitorelias1

New Member
Joined
Sep 27, 2022
Messages
27
Reaction score
2
Hi guys, good morning, I have this script, but when the player uses the !reset command, it works, but the CAP of the player resets the tmb, how can I put it to not reset the CAP?

Lua:
local resetSys = TalkAction("!resetar")

local config = {
    backToLevel = 8,
    redskull = false, -- need to be without redskull to reset?
    battle = true, -- need to be without battle to reset?
    pz = false, -- need to be in protect zone to reset?
    stages = {
        {resets = 4, level = 350, premium = 330},
        {resets = 9, level = 355, premium = 340},
        {resets = 14, level = 360, premium = 355},
        {resets = 19, level = 365, premium = 360},
        {resets = 24, level = 380, premium = 370},
        {resets = 29, level = 390, premium = 380},
        {resets = 34, level = 410, premium = 400},
        {resets = 39, level = 430, premium = 420},
        {resets = 44, level = 450, premium = 440},
        {resets = 49, level = 480, premium = 470},
        {resets = 54, level = 510, premium = 500},
        {resets = 59, level = 550, premium = 540},
        {resets = 64, level = 590, premium = 580},
        {resets = 69, level = 630, premium = 620},
        {resets = 74, level = 680, premium = 670},
        {resets = 79, level = 730, premium = 720},
        {resets = 84, level = 780, premium = 770},
        {resets = 89, level = 860, premium = 840},
        {resets = 94, level = 930, premium = 910},
        {resets = 2^1024, level = 1010, premium = 990}
    }
}

function resetSys.onSay(player, words, param)
    local function getExperienceForLevel(lv)
        lv = lv - 1
        return ((50 * lv * lv * lv) - (150 * lv * lv) + (400 * lv)) / 3
    end
    local function getPlayerResets()
        local resets = player:getStorageValue(500)
        return resets < 0 and 0 or resets
    end
  
    local function doPlayerAddResets(count)
        player:setStorageValue(500, getPlayerResets() + count)
    end
  
    if config.redskull and player:getSkull() == 4 then
        player:sendCancelMessage("Você precisa estar sem red skull para resetar.")
        return false
    elseif config.pz and not getTilePzInfo(player:getPosition()) then
        player:sendCancelMessage("Você precisa estar em protection zone para resetar.")
        return false
    elseif config.battle and player:getCondition(CONDITION_INFIGHT) then
        player:sendCancelMessage("Você precisa estar sem battle para resetar.")
        return false
    end
  
    local resetLevel = 0
    for x, y in ipairs(config.stages) do
        if getPlayerResets() <= y.resets then
            resetLevel = player:isPremium() and y.premium or y.level
            break
        end
    end
  
    if getPlayerLevel(player) < resetLevel then
        player:sendCancelMessage("Você precisa do level " .. resetLevel .. " ou mais para resetar.")
        return false
    end
  
    doPlayerAddResets(1)
    local healthMax, manaMax, health, mana = player:getMaxHealth(), player:getMaxMana(), player:getHealth(), player:getMana()
    player:removeExperience(getExperienceForLevel(player:getLevel()) - getExperienceForLevel(config.backToLevel))
    player:setMaxHealth(healthMax)
    player:setMaxMana(manaMax)
    player:addHealth(health)
    player:addMana(mana)
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Now you have " .. getPlayerResets() .. " " .. (getPlayerResets() == 1 and "reset" or "resets") .. ".")
    return false
end

resetSys:register()
 
You can add this function:
Lua:
local function getPlayerCapacity()
    return player:getCapacity()
end

Add to: resetSys.onSay before the reset
Lua:
local currentCapacity = getPlayerCapacity()

Add this after the reset:
Lua:
local newCapacity = getPlayerCapacity()
player:setCapacity(math.min(currentCapacity, newCapacity))
 
local newCapacity = getPlayerCapacity() player:setCapacity(math.min(currentCapacity, newCapacity))

You can add this function:
Lua:
local function getPlayerCapacity()
    return player:getCapacity()
end

Add to: resetSys.onSay before the reset
Lua:
local currentCapacity = getPlayerCapacity()

Add this after the reset:
Lua:
local newCapacity = getPlayerCapacity()
player:setCapacity(math.min(currentCapacity, newCapacity))
1682790901493.png
when I enter the otserv the player is literally with cap 0 and when I level the char it remains 0 and even if I give the !reset command it remains 0
 
O código que eu coloquei é pra quando resetar, manter o cap atual quando o player usar o !reset
The code i sent here, is to keep the current CAP when the player use !reset
 
O código que eu coloquei é pra quando resetar, manter o cap atual quando o player usar o !reset
The code i sent here, is to keep the current CAP when the player use !reset
então eu fiz do jeito que você me disse quando eu entrei na conta o player já estava com 0 de CAP, vou fazer mais um teste
level 8.PNGlevel 358.PNGSem título.png
when I gave the !reset command, the dog came back as if I were level 8
 
Last edited:
show us how is the script now
Lua:
local resetSys = TalkAction("!resetar")

local config = {
    backToLevel = 8,
    redskull = false, -- need to be without redskull to reset?
    battle = true, -- need to be without battle to reset?
    pz = false, -- need to be in protect zone to reset?
    stages = {
        {resets = 4, level = 350, premium = 330},
        {resets = 9, level = 355, premium = 340},
        {resets = 14, level = 360, premium = 355},
        {resets = 19, level = 365, premium = 360},
        {resets = 24, level = 380, premium = 370},
        {resets = 29, level = 390, premium = 380},
        {resets = 34, level = 410, premium = 400},
        {resets = 39, level = 430, premium = 420},
        {resets = 44, level = 450, premium = 440},
        {resets = 49, level = 480, premium = 470},
        {resets = 54, level = 510, premium = 500},
        {resets = 59, level = 550, premium = 540},
        {resets = 64, level = 590, premium = 580},
        {resets = 69, level = 630, premium = 620},
        {resets = 74, level = 680, premium = 670},
        {resets = 79, level = 730, premium = 720},
        {resets = 84, level = 780, premium = 770},
        {resets = 89, level = 860, premium = 840},
        {resets = 94, level = 930, premium = 910},
        {resets = 2^1024, level = 1010, premium = 990}
    }
}


function resetSys.onSay(player, words, param)

    local function getExperienceForLevel(lv)
        lv = lv - 1
        return ((50 * lv * lv * lv) - (150 * lv * lv) + (400 * lv)) / 3
    end

    local function getPlayerResets()
        local resets = player:getStorageValue(500)
        return resets < 0 and 0 or resets
    end
  
    local function doPlayerAddResets(count)
        player:setStorageValue(500, getPlayerResets() + count)
    end
  
    if config.redskull and player:getSkull() == 4 then
        player:sendCancelMessage("Você precisa estar sem red skull para resetar.")
        return false
    elseif config.pz and not getTilePzInfo(player:getPosition()) then
        player:sendCancelMessage("Você precisa estar em protection zone para resetar.")
        return false
    elseif config.battle and player:getCondition(CONDITION_INFIGHT) then
        player:sendCancelMessage("Você precisa estar sem battle para resetar.")
        return false
    end

    local resetLevel = 0
    for x, y in ipairs(config.stages) do
        if getPlayerResets() <= y.resets then
            resetLevel = player:isPremium() and y.premium or y.level
            break
        end
    end

  
    if getPlayerLevel(player) < resetLevel then
        player:sendCancelMessage("Você precisa do level " .. resetLevel .. " ou mais para resetar.")
        return false
    end
    
  
    doPlayerAddResets(1)
    player:removeExperience(getExperienceForLevel(player:getLevel()) - getExperienceForLevel(config.backToLevel))
    player:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Now you have " .. getPlayerResets() .. " " .. (getPlayerResets() == 1 and "reset" or "resets") .. ".")
    return false
end

resetSys:register()
 
@vitorelias1
Before:
Lua:
doPlayerAddResets(1)

Add:
Lua:
local sameCap = player:getCapacity()

After:
Lua:
player:removeExperience(getExperienceForLevel(player:getLevel()) - getExperienceForLevel(config.backToLevel))

Add:
Lua:
player:setCapacity(sameCap)
 
Last edited:
excellent script.
I have a question, so that the resets appear on the look? I tried to add this to player.lua, but without success.
base canary 3.1.1

data\events\scripts\player.lua

Lua:
function Player:onLook(thing, position, distance)
    local description = "You see " .. thing:getDescription(distance)
    if thing:isPlayer() then
        description = string.format("%s\nResets: %d", description, thing:getStorageValue(500))
    end
    if self:getGroup():getAccess() then
 
excellent script.
I have a question, so that the resets appear on the look? I tried to add this to player.lua, but without success.
base canary 3.1.1

data\events\scripts\player.lua

Lua:
function Player:onLook(thing, position, distance)
    local description = "You see " .. thing:getDescription(distance)
    if thing:isPlayer() then
        description = string.format("%s\nResets: %d", description, thing:getStorageValue(500))
    end
    if self:getGroup():getAccess() then
Isn't onLook defined in data/scripts/eventcallbacks/player/on_look.lua in 3.1.1?
In C++ it first executes events from events.xml and then Lua event callbacks.
function Player:onLook(thing, position, distance) does not exist in data\events\scripts\player.lua in 3.1.1
There is also no <event class="Player" method="onLook" enabled="1" /> in events.xml. If you only added onLook to player.lua, it won't be executed by server.
 
excellent script.
I have a question, so that the resets appear on the look? I tried to add this to player.lua, but without success.
base canary 3.1.1

data\events\scripts\player.lua

Lua:
function Player:onLook(thing, position, distance)
    local description = "You see " .. thing:getDescription(distance)
    if thing:isPlayer() then
        description = string.format("%s\nResets: %d", description, thing:getStorageValue(500))
    end
    if self:getGroup():getAccess() then
Test the script on a data/script that is revscripts. Try it first; if it doesn't work, try the second one. And if the second one doesn't work either, then, as Gesior mentioned earlier... Because onLook and onLookInBattleList are the same thing. I tested with onLookInBattleList and the "reset" look appeared normally. I believe it should work, but I'm not sure if it will work with canary. It's important to test to find out. I hope you understand.

data/scripts
1. onLook.

Lua:
local resetLook = EventCallback()

function resetLook.onLook(player, thing, position, distance, description)
    if thing:isItem() then
        local resets = thing:getStorageValue(500)
        if resets ~= nil then
            if resets < 0 then
                description = string.format("%s\nResets: 0.", description)
            else
                description = string.format("%s\nResets: %d.", description, resets)
            end
        end
    end
    return description
end

resetLook:register(2)

2.onLookInBattleList.
Lua:
local resetLook = EventCallback()

function resetLook.onLookInBattleList(player, thing, position, distance, description)
    if thing:isItem() then
        local resets = thing:getStorageValue(500)
        if resets ~= nil then
            if resets < 0 then
                description = string.format("%s\nResets: 0.", description)
            else
                description = string.format("%s\nResets: %d.", description, resets)
            end
        end
    end
    return description
end

resetLook:register(2)
I noticed that in the data/events/events.xml file there is no line "<event class="Player" method="onLook" enabled="1" />", but I found another line "<event class="Player" method ="onLookInBattleList" enabled="1" />". I can't guarantee it will work perfectly, but it's important to test to see if it works correctly.
 
Back
Top