• 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 [TFS 0.4] Multiple messages bug

elnelson

Lunaria World Dev
Joined
Jun 20, 2009
Messages
583
Solutions
2
Reaction score
60
Location
México
Hello, otlanders. I have this script but when player doesnt have enough soul it spams the message several times.
17:32 You need more soul.
17:32 You need more soul.
17:32 You need more soul.
17:32 You need more soul.
17:32 You need more soul.
17:32 You need more soul.

How can i fix that annoying bug?

here is the script
Lua:
local cfg = {
soul = 5,
level = 1
}
local t = {
[{4006}] = {fruit = 2675, NFTree = 4008, amount = 3, fName = "oranges"},
[{5094}] = {fruit = 2676, NFTree = 5093, amount = 3, fName = "bananas"},
[{5096}] = {fruit = 2678, NFTree = 2726, amount = 3, fName = "coconuts"},
[{5157}] = {fruit = 5097, NFTree = 5156, amount = 3, fName = "mangoes"},
[{2785}] = {fruit = 2677, NFTree = 2786, amount = 3, fName = "blueberries"},
[{4012}] = {fruit = 2684, NFTree = 6218, amount = 3, fName = "carrots"}
}
function onUse(cid, item, frompos, item2, topos)
local S = getPlayerSoul(cid)
local L = getPlayerLevel(cid)
for i, k in pairs(t) do
if (isInArray(i, item.itemid) == true) and (S >= cfg.soul) and (L >= cfg.level) then
doTransformItem(item.uid, k.NFTree)
doPlayerAddItem(cid, k.fruit, k.amount)
doPlayerAddSoul(cid, -cfg.soul)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You got some "..k.fName..".")
elseif (S < cfg.soul) then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need more soul.")
elseif (L < cfg.level) then
doPlayerSendCancel(cid, "You need more level.")
end
end
end
 
Solution
try this?

Lua:
local cfg = {
   soul = 5,
   level = 1
}
local t = {
   [{4006}] = {fruit = 2675, NFTree = 4008, amount = 3, fName = "oranges"},
   [{5094}] = {fruit = 2676, NFTree = 5093, amount = 3, fName = "bananas"},
   [{5096}] = {fruit = 2678, NFTree = 2726, amount = 3, fName = "coconuts"},
   [{5157}] = {fruit = 5097, NFTree = 5156, amount = 3, fName = "mangoes"},
   [{2785}] = {fruit = 2677, NFTree = 2786, amount = 3, fName = "blueberries"},
   [{4012}] = {fruit = 2684, NFTree = 6218, amount = 3, fName = "carrots"}
}
function onUse(cid, item, frompos, item2, topos)
   if getPlayerSoul(cid) < cfg.soul then
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need more soul.")
       return true
   elseif...
try this?

Lua:
local cfg = {
   soul = 5,
   level = 1
}
local t = {
   [{4006}] = {fruit = 2675, NFTree = 4008, amount = 3, fName = "oranges"},
   [{5094}] = {fruit = 2676, NFTree = 5093, amount = 3, fName = "bananas"},
   [{5096}] = {fruit = 2678, NFTree = 2726, amount = 3, fName = "coconuts"},
   [{5157}] = {fruit = 5097, NFTree = 5156, amount = 3, fName = "mangoes"},
   [{2785}] = {fruit = 2677, NFTree = 2786, amount = 3, fName = "blueberries"},
   [{4012}] = {fruit = 2684, NFTree = 6218, amount = 3, fName = "carrots"}
}
function onUse(cid, item, frompos, item2, topos)
   if getPlayerSoul(cid) < cfg.soul then
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need more soul.")
       return true
   elseif getPlayerLevel(cid) < cfg.level then
       doPlayerSendCancel(cid, "You need more level.")
       return true
   end
   for i, k in pairs(t) do
       if isInArray(i, item.itemid) == true then
           doTransformItem(item.uid, k.NFTree)
           doPlayerAddItem(cid, k.fruit, k.amount)
           doPlayerAddSoul(cid, -cfg.soul)
           doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You got some "..k.fName..".")
       end
   end
   return true
end
 
Solution
try this?

Lua:
local cfg = {
   soul = 5,
   level = 1
}
local t = {
   [{4006}] = {fruit = 2675, NFTree = 4008, amount = 3, fName = "oranges"},
   [{5094}] = {fruit = 2676, NFTree = 5093, amount = 3, fName = "bananas"},
   [{5096}] = {fruit = 2678, NFTree = 2726, amount = 3, fName = "coconuts"},
   [{5157}] = {fruit = 5097, NFTree = 5156, amount = 3, fName = "mangoes"},
   [{2785}] = {fruit = 2677, NFTree = 2786, amount = 3, fName = "blueberries"},
   [{4012}] = {fruit = 2684, NFTree = 6218, amount = 3, fName = "carrots"}
}
function onUse(cid, item, frompos, item2, topos)
   if getPlayerSoul(cid) < cfg.soul then
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need more soul.")
       return true
   elseif getPlayerLevel(cid) < cfg.level then
       doPlayerSendCancel(cid, "You need more level.")
       return true
   end
   for i, k in pairs(t) do
       if isInArray(i, item.itemid) == true then
           doTransformItem(item.uid, k.NFTree)
           doPlayerAddItem(cid, k.fruit, k.amount)
           doPlayerAddSoul(cid, -cfg.soul)
           doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You got some "..k.fName..".")
       end
   end
   return true
end

Worked perfect, perhaps, what was the issue?
 
Worked perfect, perhaps, what was the issue?
Your script it working through the lua table 1 by 1, and checks if the item is correct each time, and if it wasn't, it'd send you the first error regarding soul each time.

I'd write the script like this, if I were doing it.
Lua:
local cfg = {
   soul = 5,
   level = 1
}
local t = {
   [4006] = {fruit = 2675, NFTree = 4008, amount = 3, fName = "oranges"},
   [5094] = {fruit = 2676, NFTree = 5093, amount = 3, fName = "bananas"},
   [5096] = {fruit = 2678, NFTree = 2726, amount = 3, fName = "coconuts"},
   [5157] = {fruit = 5097, NFTree = 5156, amount = 3, fName = "mangoes"},
   [2785] = {fruit = 2677, NFTree = 2786, amount = 3, fName = "blueberries"},
   [4012] = {fruit = 2684, NFTree = 6218, amount = 3, fName = "carrots"}
}
function onUse(cid, item, frompos, item2, topos)
   -- check player soul
   if getPlayerSoul(cid) < cfg.soul then
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need more soul.")
       return true
   end
   -- check player level
   if getPlayerLevel(cid) < cfg.level then
       doPlayerSendCancel(cid, "You need more level.")
       return true
   end
   -- check which tree is being used
   local fruit_tree = t[item.itemid]
   if fruit_tree then
       doTransformItem(item.uid, fruit_tree.NFTree)
       doPlayerAddItem(cid, fruit_tree.fruit, fruit_tree.amount)
       doPlayerAddSoul(cid, -cfg.soul)
       doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You got some "..fruit_tree.fName..".")
   end
   return true
end
 
Back
Top