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

Lua EXP potion should effect 2 hours, but its over so fast

eyez

Member
Joined
Oct 11, 2016
Messages
129
Reaction score
19
I have this action
Code:
function ExpBackNormal_EndVoucher(cid, bonus)
    local rates = getPlayerRates(cid)[8] - bonus
    doPlayerSetExperienceRate(cid, rates)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can not use this item in fight!")
        return true
    end
    local exhaustedvoucher = 3024775
    if(os.time() < getCreatureStorage(cid, exhaustedvoucher)) then
        doPlayerSendCancel(cid, "You can only use it once every 20 hours! You will be able to use this item again on: " .. os.date("%B", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%d", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%Y", getPlayerStorageValue(cid, exhaustedvoucher)) .. "  " .. os.date("%X", getPlayerStorageValue(cid, exhaustedvoucher)) .. ".")
        return true
    end
    -- add 50% exp bonus for 1 hour
    local bonus
    if(item.itemid == 11402) then
        bonus = 0.5
    elseif(item.itemid == 11401) then
        bonus = 0.3
    end
    local rates = getPlayerRates(cid)[8] + bonus
    doPlayerSetExperienceRate(cid, rates)
    addEvent(ExpBackNormal_EndVoucher, 2*60*60*1000, cid, bonus) -- 2 hours
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Now you have your EXP bonus for 2 hours.")
    doRemoveItem(item.uid)
    doCreatureSetStorage(cid, exhaustedvoucher, os.time() + (20*60*60*1000)) -- 24 hours
    doSendMagicEffect(getCreaturePosition(cid), 14)
    return true
end

And it should add a bonus for player for 2 hours, but instead its over after kill the first monster, i mean, in few seconds.

Anybody know what is wrong?
 
Solution
as @miszczbobek said, the script seems fine.

I made some changes to it and will give you a check on your login.lua so that if the player gets offline during the timout ot the exp bonus he will lose it when he logs in.

Code:
function ExpBackNormal_EndVoucher(cid, bonus)
    local rates = math.abs(getPlayerRates(cid)[8] - bonus)
    doPlayerSetExperienceRate(cid, rates)
    doCreatureSetStorage(cid, 3024776, -1)
    doCreatureSetStorage(cid, 3024777, -1)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can not use this item in fight!")
        return true
    end
    local...
Not related with your problem, but if player log outs when the expbacknormal event runs, he will have the bonus permanetly, and will be able to keep stacking it.
 
Not related with your problem, but if player log outs when the expbacknormal event runs, he will have the bonus permanetly, and will be able to keep stacking it.

I know, thank you, but its not a problem, its just a boost to use in 2 hours, to hunt on hands

Is that so hard to do? Because a member @Sarah Wesker is trying to to sell me this fix for 5 dollars...


friend I sell you this experience system for 5 dollars.
I have seen that you have enough time trying to create a 100% functional system without problems.
fixing all bugs
 
I know, thank you, but its not a problem, its just a boost to use in 2 hours, to hunt on hands

Is that so hard to do? Because a member @Sarah Wesker is trying to to sell me this fix for 5 dollars...
It is not difficult, but I do not give my free time ;)
other people have more free time
 
Is that so hard to do?
For you to do, yes apparently.
Because a member @Sarah Wesker is trying to to sell me this fix for 5 dollars...
This script you are going to use on your server.. you are going to charge real money for it in the game, whats wrong with spending a little money to have someone fix it for you?
 
Last edited:
It's not like I was asking to make for me, i just stuck in a point and don't know how to keep moving on.

I also don't make OT to earn money or to sell items overpower for real money, and even if i was sell stuff, on my OT the only one who deserve some money is the one who create the TFS for all community for free, to guys like you ask for money to make a "simple" script.
Anyways, i don't want your help not @Sarah Wesker i don't agree with your position and not even you @bayview who i only see posts about your problems with ego

If anyone else know what I'm doing wrong, please tell me
 
It's not like I was asking to make for me, i just stuck in a point and don't know how to keep moving on.

I also don't make OT to earn money or to sell items overpower for real money, and even if i was sell stuff, on my OT the only one who deserve some money is the one who create the TFS for all community for free, to guys like you ask for money to make a "simple" script.
Anyways, i don't want your help not @Sarah Wesker i don't agree with your position and not even you @bayview who i only see posts about your problems with ego

If anyone else know what I'm doing wrong, please tell me
1) If I did not want to pay, you only had to tell me by private.
2) I work with this in my spare time.
3) It was just a question, I was not forcing you.
THANK!
I will not say anything more about it. BYE
 
as @miszczbobek said, the script seems fine.

I made some changes to it and will give you a check on your login.lua so that if the player gets offline during the timout ot the exp bonus he will lose it when he logs in.

Code:
function ExpBackNormal_EndVoucher(cid, bonus)
    local rates = math.abs(getPlayerRates(cid)[8] - bonus)
    doPlayerSetExperienceRate(cid, rates)
    doCreatureSetStorage(cid, 3024776, -1)
    doCreatureSetStorage(cid, 3024777, -1)
    return true
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You can not use this item in fight!")
        return true
    end
    local exhaustedvoucher = 3024775
    local time = 3024776
    local bonusMultiplier = 3024777
    if(os.time() < getCreatureStorage(cid, exhaustedvoucher)) then
        doPlayerSendCancel(cid, "You can only use it once every 20 hours! You will be able to use this item again on: " .. os.date("%B", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%d", getPlayerStorageValue(cid, exhaustedvoucher)) .. "-" .. os.date("%Y", getPlayerStorageValue(cid, exhaustedvoucher)) .. "  " .. os.date("%X", getPlayerStorageValue(cid, exhaustedvoucher)) .. ".")
        return true
    end

    -- add 50% exp bonus for 1 hour
    local bonus
    if(item.itemid == 11402) then
        bonus = 0.5
    elseif(item.itemid == 11401) then
        bonus = 0.3
    end
    local rates = getPlayerRates(cid)[8] + bonus
    doPlayerSetExperienceRate(cid, rates)
    addEvent(ExpBackNormal_EndVoucher, 7200000, cid, bonus) -- 2 hours
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Now you have your EXP bonus for 2 hours.")
    doRemoveItem(item.uid)
    doCreatureSetStorage(cid, exhaustedvoucher, os.time() + (20*60*60*1000)) -- 24 hours
    doCreatureSetStorage(cid, time, os.time() + 7200000)
    doCreatureSetStorage(cid, bonusMultiplier, bonus)
    doSendMagicEffect(getCreaturePosition(cid), 14)
    return true
end


if getCreatureStorage(cid, 3024776) > 1 and getCreatureStorage(cid, 3024776) < os.time()
    and getCreatureStorage(cid, 3024777) > 0 then
    doPlayerSetExperienceRate(cid, (getPlayerRates(cid)[8] - getCreatureStorage(cid, 3024777)))
    doCreatureSetStorage(cid, 3024776, -1)
    doCreatureSetStorage(cid, 3024777, -1)
end

on your login.lua add:
Code:
if getCreatureStorage(cid, 3024776) > 1 and getCreatureStorage(cid, 3024776) < os.time()
    and getCreatureStorage(cid, 3024777) > 0 then
    doPlayerSetExperienceRate(cid, math.abs(getPlayerRates(cid)[8] - getCreatureStorage(cid, 3024777))) 
--[[add math abs because idk if you have extreme low rates but that could cause a negative exp rate and that wouldn't be cool xd ]]
    doCreatureSetStorage(cid, 3024776, -1)
    doCreatureSetStorage(cid, 3024777, -1)
end


This is probably not the best way to be doing this but it's what I could come up with in a couple minutes.

The changes I made:
save on 2 new storages the bonus multiplier he has going on and the time left so that we can keep track of that even if he logs out xD
 
Last edited:
Solution
Back
Top