• 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.X+ Use item and gain exp instantly.

Piifafa

Member
Joined
Apr 16, 2023
Messages
67
Reaction score
16
Hello everyone, thanks for trying to help me!
How could I make a script, for use where the person uses it and gains 150 thousand experience instantly? Without having the stage effects that exist in otserver?

I made a script that adds more capacity for players, but it wasn't as good for the experience as I wanted.

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local additionalCapacity = 50000 -- Aumento de capacidade em 5 kg

    player:setCapacity(player:getCapacity() + additionalCapacity) -- Aumenta a capacidade

    player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You won " .. (additionalCapacity / 100) .. " kg capacity.")
    item:remove(1) -- Remove o item após o uso

    return true
end
 
Solution
You'd have to modify the experience gain script on your server, I think.

So add this into data/lib/core/custom_functions.lua (and in core/core.lua register the custom_functions.lua file)
Lua:
RAW_EXPERIENCE_STORAGE = 45100

function Player.addRawExperience(self, amount)
    self:setStorageValue(RAW_EXPERIENCE_STORAGE, 1)
    self:addRawExperience(amount)
end
Then go to your onGainExperience function
data/scripts/eventcallbacks/player/default_onGainExperience.lua

Add this check directly under the onGainExperience function
onGainExperience(player, source, exp, rawExp, sendText)
Lua:
if not source and player:getStorageValue(RAW_EXPERIENCE_STORAGE) == 1 then
    self:setStorageValue(RAW_EXPERIENCE_STORAGE, -1)...
You'd have to modify the experience gain script on your server, I think.

So add this into data/lib/core/custom_functions.lua (and in core/core.lua register the custom_functions.lua file)
Lua:
RAW_EXPERIENCE_STORAGE = 45100

function Player.addRawExperience(self, amount)
    self:setStorageValue(RAW_EXPERIENCE_STORAGE, 1)
    self:addRawExperience(amount)
end
Then go to your onGainExperience function
data/scripts/eventcallbacks/player/default_onGainExperience.lua

Add this check directly under the onGainExperience function
onGainExperience(player, source, exp, rawExp, sendText)
Lua:
if not source and player:getStorageValue(RAW_EXPERIENCE_STORAGE) == 1 then
    self:setStorageValue(RAW_EXPERIENCE_STORAGE, -1)
    return rawExp -- rawExp is the experience without multipliers.
end

Now if you use the function from before, it should give you the exact experience amount, without modifying it.
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:addRawExperience(150000)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You received 150000 experience.")
    item:remove(1)
    return true
end
 
Solution
I ended up doing it like this, but your solo also works perfectly:

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player then
        player:addExperience(50000)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You received 50000 experience.")
        item:remove(1)
        
        -- Adiciona um efeito visual ao redor do jogador (CONST_ME_MAGIC_BLUE)
        player:getPosition():sendMagicEffect(CONST_ME_HEARTS)
        
        return true
    end
    return false
end
 
Back
Top