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

Lever

memofighter

New Member
Joined
Mar 11, 2010
Messages
10
Reaction score
0
Hey there!

I've just started practicing Lua and it isn't going very well xD

I'm trying some things out with a lever, but when I use the lever ingame, it doesn't work. It just moves but I don't get any mana or a message.
This is the script I'm using:


Code:
function onUse(cid, item, frompos, item2, topos)
local mana = 50
        if item.uid == 2020 and item.itemid == 1945 then
                doTransformItem(item.uid, item.itemid + 1)
                doCreatureAddMana(cid,mana)
                doCreatureAddHealth(cid,mana)
                doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
                doSendAnimatedText(getPlayerPosition(cid), "Mana Up!", TEXTCOLOR_ORANGE)

elseif item.uid == 2020 and item.itemid == 1946 then
                doTransformItem(item.uid, item.itemid -1)
                doCreatureAddMana(cid,mana)
                doCreatureAddHealth(cid,mana)
                doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
                doSendAnimatedText(getPlayerPosition(cid),"Mana Up!",TEXTCOLOR_ORANGE)
        end
        return TRUE
end
File in actions.XML:

Code:
<action itemid="2020" event="script" value="tools/addmana.lua"/>

I've added the unique id in my map editor.

Does anyone see what I'm doing wrong?

Kind Regards, Memo
 
Last edited by a moderator:
Instead of
Code:
<action itemid="2020" event="script" value="tools/addmana.lua"/>
Try
Code:
 <action uniqueid="2020" event="script" value="tools/addmana.lua"/>

P.s Use code tags ([noparse]
Code:
 script
[/noparse]
) when pasting chunks of scripts.
 
Last edited:
Instead of
Code:
<action itemid="2020" event="script" value="tools/addmana.lua"/>
Try
Code:
 <action uniqueid="2020" event="script" value="tools/addmana.lua"/>

P.s Use code tags ([noparse]
Code:
 script
[/noparse]
) when pasting chunks of scripts.

Nice, it works! Thanks for your help!
 
Shortened script:
Code:
local mana = 50
function onUse(cid, item, fromPosition, itemEx, toPosition)
	doCreatureAddMana(cid, mana)
	doCreatureAddHealth(cid, mana)
	doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
	doSendAnimatedText(getThingPos(cid), "Mana Up!", TEXTCOLOR_ORANGE)
	return doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
end
 
Back
Top