• 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 Text sending twice

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,640
Solutions
559
Reaction score
3,976
TFS 0.3.6
I'm having a problem with this script, I don't get any errors but when I equip the exp ring, it sends the textmessages twice instead of only once and I have absolutely no idea why, can anyone help?
Code:
local rates = {
        [0] = {rate = 1},
        [1] = {rate = 0.94},
        [2] = {rate = 0.88},
        [3] = {rate = 0.82},
        [4] = {rate = 0.76},
        [5] = {rate = 0.70},
        [6] = {rate = 0.65},
        [7] = {rate = 0.60},
        [8] = {rate = 0.55},
        [9] = {rate = 0.50},
        [10] = {rate = 0.45},
        [11] = {rate = 0.41},
        [12] = {rate = 0.37},
        [13] = {rate = 0.33},
        [14] = {rate = 0.29},
        [15] = {rate = 0.25},
        [16] = {rate = 0.23},
        [17] = {rate = 0.19},
        [18] = {rate = 0.15},
        [19] = {rate = 0.11},
        [20] = {rate = 0.07},
        [21] = {rate = 0.06},
        [22] = {rate = 0.05},
        [23] = {rate = 0.04},
        [24] = {rate = 0.03},
        [25] = {rate = 0.02}
    }
function onDeEquip(cid, item, slot)
local pr = getPlayerStorageValue(cid, 85987)
local v = rates[pr]
doPlayerSetRate(cid, SKILL__LEVEL, v.rate)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "EXP Rate set back to ".. v.rate .."")
return true
end

function onEquip(cid, item, slot)
local pr = getPlayerStorageValue(cid, 85987)
local v = rates[pr]
    doPlayerSetRate(cid, SKILL__LEVEL, (v.rate+v.rate*0.50))
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ("Your prestige is [".. pr .."]. EXP Rate increased by: " .. v.rate*0.50 .. ""))
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, ("EXP Rate is now ".. v.rate+v.rate*0.50 ..""))
return true
end
 
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ("Your prestige is [".. pr .."]. EXP Rate increased by: " .. v.rate*0.50 .. ""))
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, ("EXP Rate is now ".. v.rate+v.rate*0.50 ..""))
or did I simply not understand what you meant?
 
It's a well known bug of older tfs version that it fire throws onequip twice, that's why you get the messages twice.
 
Code:
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ("Your prestige is [".. pr .."]. EXP Rate increased by: " .. v.rate*0.50 .. ""))
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, ("EXP Rate is now ".. v.rate+v.rate*0.50 ..""))
or did I simply not understand what you meant?
Yes, that part.

It's a well known bug of older tfs version that it fire throws onequip twice, that's why you get the messages twice.
So is there any way to fix it by source editing?
 
I don't have any 0.3.6 sources here atm can't really tell you how to fix it in sources but there is a trick in lua scripts on how to prevent it
You check item.id and match it with the slot itemid if they are the same just return true, this will do the trick.

This is also part of the bug, should fix that aswell
https://otland.net/threads/onequip-ondeequip-properly-handled-at-login-logout.116948/
Thank you, it only sends once now.
Here's the script if anyone needs it
Code:
local rates = {
        [0] = {rate = 1},
        [1] = {rate = 0.94},
        [2] = {rate = 0.88},
        [3] = {rate = 0.82},
        [4] = {rate = 0.76},
        [5] = {rate = 0.70},
        [6] = {rate = 0.65},
        [7] = {rate = 0.60},
        [8] = {rate = 0.55},
        [9] = {rate = 0.50},
        [10] = {rate = 0.45},
        [11] = {rate = 0.41},
        [12] = {rate = 0.37},
        [13] = {rate = 0.33},
        [14] = {rate = 0.29},
        [15] = {rate = 0.25},
        [16] = {rate = 0.23},
        [17] = {rate = 0.19},
        [18] = {rate = 0.15},
        [19] = {rate = 0.11},
        [20] = {rate = 0.07},
        [21] = {rate = 0.06},
        [22] = {rate = 0.05},
        [23] = {rate = 0.04},
        [24] = {rate = 0.03},
        [25] = {rate = 0.02}
    }
function onDeEquip(cid, item, slot)
local pr = getPlayerStorageValue(cid, 85987)
local v = rates[pr]
doPlayerSetRate(cid, SKILL__LEVEL, v.rate)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "EXP Rate set back to ".. v.rate .."")
return true
end

function onEquip(cid, item, slot)
local pr = getPlayerStorageValue(cid, 85987)
local v = rates[pr]
if item.itemid == 6093 then
    if getPlayerSlotItem(cid, CONST_SLOT_RING).itemid == 6093 then
        doPlayerSetRate(cid, SKILL__LEVEL, (v.rate+v.rate*0.50))
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, ("Your prestige is [".. pr .."]. EXP Rate increased by: " .. v.rate*0.50 .. ""))
          doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, ("EXP Rate is now ".. v.rate+v.rate*0.50 ..""))
    end
end
return true
end
 
Back
Top