• 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 0.X Upgrade Staff - Prevent use itself

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
Hello guys,

I have a working script for an upgrade staff (upgrade system), the item has the ID 5114 and I want it to be impossible for players to use it on it, could you help me?

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if isCreature(itemEx.uid) then    
    return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
end

local obj = UpgradeHandler:new(itemEx)

if(obj == false) then
    return doPlayerSendCancel(cid, UpgradeHandler.message.notupgradeable)
end

local status = obj:refine(cid, item)
if status == "success" then
    doSendAnimatedText(toPosition, "Success!", COLOR_GREEN)
    doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
elseif status == "fail" then
    doSendAnimatedText(toPosition, "Fail!", COLOR_RED)
    doSendMagicEffect(toPosition, CONST_ME_POFF)
else
    doSendMagicEffect(toPosition, CONST_ME_POFF)
end
return true
end
 
Solution
cid is the creature. item is the item being used. itemex is the target of crosshairs.

cid is useless in this situation.

just use
Code:
if item.uid == itemEx.uid then
       print("item used on itself")
end
Try this
Lua:
if cid == itemEx.uid then  
    ...
end
or
Lua:
if cid == itemEx.uid or isCreature(itemEx.uid) then   
    return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
end
 
Last edited:
Works, but got error in console:

1633266613011.png

Actual script:

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
if cid.uid == itemEx.uid then   
    return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
end

if isCreature(itemEx.uid) then    
    return doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
end


local obj = UpgradeHandler:new(itemEx)

if(obj == false) then
    return doPlayerSendCancel(cid, UpgradeHandler.message.notupgradeable)
end

local status = obj:refine(cid, item)
if status == "success" then
    doSendAnimatedText(toPosition, "Success!", COLOR_GREEN)
    doSendMagicEffect(toPosition, CONST_ME_MAGIC_GREEN)
elseif status == "fail" then
    doSendAnimatedText(toPosition, "Fail!", COLOR_RED)
    doSendMagicEffect(toPosition, CONST_ME_POFF)
else
    doSendMagicEffect(toPosition, CONST_ME_POFF)
end
return true
end
 
cid is the creature. item is the item being used. itemex is the target of crosshairs.

cid is useless in this situation.

just use
Code:
if item.uid == itemEx.uid then
       print("item used on itself")
end
 
Solution
cid is the creature. item is the item being used. itemex is the target of crosshairs.

cid is useless in this situation.

just use
Code:
if item.uid == itemEx.uid then
       print("item used on itself")
end
Works Xiki, thank you
 
Back
Top