• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

EXP Scroll tfs 1.1

Geekbuddys

Member
Joined
Mar 15, 2014
Messages
164
Reaction score
19
Code:
local config = {
        rate = 2.0, -- 4x More Experience
        time = 3, -- Hours of Exp Time
        storage = 200011
    }
    local function endExpRate(player, cid)
        player:setExperienceRate(cid, SKILL__LEVEL, 3.0)
        player:setStorageValue(cid, config.storage, -1)
        player:sendTextMessage(cid, MESSAGE_INFO_DESCR, "Your extra experience time has ended.")
    end
 
    function onUse(player, item, fromPosition, itemEx, toPosition)
        if(player:getStorageValue(cid, config.storage) == -1) then
            player:sendTextMessage(cid, MESSAGE_INFO_DESCR, "Your extra experience rate is now: " .. config.rate .. ". It will last for ".. config.time .." hours.")
            player:setExperienceRate(cid, SKILL__LEVEL, config.rate)
            player:setStorageValue(cid, config.storage, os.time() + config.time * 3600 * 1000)
            addEvent(endExpRate, config.time * 3600 * 1000, cid)
            player:removeItem(item.uid, 1)
        else
            player:sendTextMessage(cid, MESSAGE_INFO_DESCR, "You still have extra experience time left.")
        end
   return true
end

Can't get it work.. i dosent give any error in console. Any one knows whats wrong?
 
try that

LUA:
local cfg = {
      amount = 1 -- here how many levels you want
     }
     function onUse(cid, item, fromPosition, itemEx, toPosition)
     doPlayerAddLevel(cid, cfg.amount)
     doPlayerSendTextMessage(cid, 28, "You have gained 1 level!")
     doSendMagicEffect(getCreaturePosition(cid), 28)
      doRemoveItem(item.uid,1)
     return true
     end
 
try that

LUA:
local cfg = {
      amount = 1 -- here how many levels you want
     }
     function onUse(cid, item, fromPosition, itemEx, toPosition)
     doPlayerAddLevel(cid, cfg.amount)
     doPlayerSendTextMessage(cid, 28, "You have gained 1 level!")
     doSendMagicEffect(getCreaturePosition(cid), 28)
      doRemoveItem(item.uid,1)
     return true
     end

Thats not event that script i want to get help with. Your script its not for TFS 1.1 and its has no time or exp rate at all. Its just gives levels.[/QUOTE]
 
You can use Player:onGainExperience for double experience.

Code:
function Player:onGainExperience(source, exp, rawExp)
    if self:getStorageValue(200011) > os.time() then
        return exp * 2
    end

    return exp
end
 
Code:
local config = {
        rate = 2.0, -- 4x More Experience
        time = 3, -- Hours of Exp Time
        storage = 200011
    }
    local function endExpRate(player, cid)
        player:setExperienceRate(cid, SKILL__LEVEL, 3.0)
        player:setStorageValue(cid, config.storage, -1)
        player:sendTextMessage(cid, MESSAGE_INFO_DESCR, "Your extra experience time has ended.")
    end

    function onUse(player, item, fromPosition, itemEx, toPosition)
        if(player:getStorageValue(cid, config.storage) == -1) then
            player:sendTextMessage(cid, MESSAGE_INFO_DESCR, "Your extra experience rate is now: " .. config.rate .. ". It will last for ".. config.time .." hours.")
            player:setExperienceRate(cid, SKILL__LEVEL, config.rate)
            player:setStorageValue(cid, config.storage, os.time() + config.time * 3600 * 1000)
            addEvent(endExpRate, config.time * 3600 * 1000, cid)
            player:removeItem(item.uid, 1)
        else
            player:sendTextMessage(cid, MESSAGE_INFO_DESCR, "You still have extra experience time left.")
        end
   return true
end

Can't get it work.. i dosent give any error in console. Any one knows whats wrong?

What does it not do? It doesn't give extra exp? I just took a quick glance over it and noticed you used addevent and tried to pass user data for a function that ends it hours afterwards. This you cannot do and if it's not working and no error in console u probably have the config.Lua setting for the warning for unsafe scripts turned off, if you turn it on should show you that problem. Ninja is right about the event to use for exp gain, would be better to use that event. Should be less work too. Anyways you can't pass this with addevent, and if you could, then it wouldn't matter because the user data and objects are all unique anyway, different ever time it's constructed. For safe way to use addevent, please use cid, not the userdata, example "local cid = player:getId ()".

EDIT: noticed you do pass cid, but then still use player userdata from onuse, you need to create a new object from cid so Player (cid), also remove cid from all the functions you have it in, except addevent
and just below onuse, you need to make cid a variable, local cid = player:getId ()
 
Last edited:
What does it not do? It doesn't give extra exp? I just took a quick glance over it and noticed you used addevent and tried to pass user data for a function that ends it hours afterwards. This you cannot do and if it's not working and no error in console u probably have the config.Lua setting for the warning for unsafe scripts turned off, if you turn it on should show you that problem. Ninja is right about the event to use for exp gain, would be better to use that event. Should be less work too. Anyways you can't pass this with addevent, and if you could, then it wouldn't matter because the user data and objects are all unique anyway, different ever time it's constructed. For safe way to use addevent, please use cid, not the userdata, example "local cid = player:getId ()".

EDIT: noticed you do pass cid, but then still use player userdata from onuse, you need to create a new object from cid so Player (cid), also remove cid from all the functions you have it in, except addevent
and just below onuse, you need to make cid a variable, local cid = player:getId ()

I want to make by using this item it gives player 2x exprate of that exprate that player have in stages at moment and the player will have it in XX hours and then it will end.

What it dosent do for now, i cant use it at all. No errors in console either.
 
Code:
function Player:setExperienceRate(rate)
    return rate * configManager.getNumber(configKeys.RATE_EXPERIENCE)
end

function Player:onGainExperience(source, exp, rawExp, rate)
    if self:getStorageValue(200011) > os.time() then
        return exp * self:setExperienceRate(rate)
    end
    return exp
end
 
Code:
function Player:setExperienceRate(rate)
    return rate * configManager.getNumber(configKeys.RATE_EXPERIENCE)
end

function Player:onGainExperience(source, exp, rawExp, rate)
    if self:getStorageValue(200011) > os.time() then
        return exp * self:setExperienceRate(rate)
    end
    return exp
end

Hello, i get this error:

unknown player method: onGainExperiencie
 
@Codinablack
I compile with
https://github.com/otland/forgottenserver/pull/910/files
and i not got errors.

Now, when I use it works, but when I go back to using allows me to continue using it, and I need to send a message that still has experiencie time left.

What can be wrong?
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local player = Player(cid)
  if(player:getStorageValue(cid, 80000) < 1) then
       player:setStorageValue(80000, os.time() + 2 * 60 * 60)
       Item(item.uid):remove(1)
       player:say("You have just activated 2 hours of Double Experience!", TALKTYPE_MONSTER_SAY)
  else
  player:sendTextMessage(cid, MESSAGE_INFO_DESCR, "You still have extra experience time left.")
  end
return true
end
 
Try to change:
Code:
if(player:getStorageValue(cid, 80000) < 1) then
to:
Code:
if(player:getStorageValue(cid, 80000) <= os.time()) then
 
Back
Top