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

Solved Problem with first script.

Fec

Member
Joined
Oct 24, 2008
Messages
69
Reaction score
6
Hello. I've written my first LUA script and I have a little problem with it.
PHP:
-- uh/mana with commands in-game.
function onSay(cid, words, param)
	local playerInfo = {currentHp = getCreatureHealth(cid), maxHp =  getCreatureMaxHealth(cid), currentMana = getPlayerMana(cid), maxMana = getPlayerMaxMana(cid), playerSoul = getPlayerSoul(cid)}

	if words == "!heal" and playerInfo[1] < playerInfo[2] and playerInfo[5] > 9 then
		if doCreatureAddHealth(cid, 50) then
			doPlayerAddSoul(cid, playerInfo[5]-9)
			doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Agrhhh!")
		--
		else
			doPlayerSendCancel(cid, "You do not have soul for this!")
		end
	
	elseif words == "!mana" and playerInfo[3] < playerInfo[4] and playerInfo[5] > 7 then 
		if doPlayerAddMana(cid, 45) then
			doPlayerAddSoul(cid, playerInfo[5]-7)
			doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Ahhhh!")
		else
			doPlayerSendCancel(cid, "You do not have soul for this!")
		end
	end
	return TRUE
end

Unfortunately when I try use "!heal" or "!mana" I get those errors :
Code:
 Lua Script Error: [TalkAction Interface] 
[17/06/2013 23:29:24] data/talkactions/scripts/healtandmana.lua:onSay
[17/06/2013 23:29:24] data/talkactions/scripts/healtandmana.lua:5: attempt to compare two nil values
[17/06/2013 23:29:24] stack traceback:
[17/06/2013 23:29:24] 	[C]: in function '__lt'
[17/06/2013 23:29:24] 	data/talkactions/scripts/healtandmana.lua:5: in function <data/talkactions/scripts/healtandmana.lua:2>
What is wrong with this code ?
#Edit - I'm using TFS 0.2.15.r102 [9.81 tibia]
 
Last edited:
Lua:
-- uh/mana with commands in-game.
function onSay(cid, words, param)
    	local playerInfo = {currentHp = getCreatureHealth(cid), maxHp =  getCreatureMaxHealth(cid), currentMana = getPlayerMana(cid), maxMana = getPlayerMaxMana(cid), playerSoul = getPlayerSoul(cid)}

	if words == "!heal" and playerInfo.currentHp < playerInfo.maxHp then
		if playerInfo.playerSoul >= 9 then
        		doCreatureAddHealth(cid, 50)
            		doPlayerAddSoul(cid, -9)
            		doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Agrhhh!")
        	else
            		doPlayerSendCancel(cid, "You do not have soul for this!")
        	end
    	elseif words == "!mana" and playerInfo.currentMana < playerInfo.maxMana then
	 	if playerInfo.playerSoul >= 7 then 
			doPlayerAddMana(cid, 45)
            		doPlayerAddSoul(cid, -7)
            		doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Ahhhh!")
        	else
            		doPlayerSendCancel(cid, "You do not have soul for this!")
        	end
    	end
    	return TRUE
end
Or
Lua:
-- uh/mana with commands in-game.
function onSay(cid, words, param)
    	local playerInfo = {getCreatureHealth(cid), getCreatureMaxHealth(cid), getPlayerMana(cid), getPlayerMaxMana(cid), getPlayerSoul(cid)}

	if words == "!heal" and playerInfo[1] < playerInfo[2] then
		if playerInfo[5] >= 9 then
        		doCreatureAddHealth(cid, 50)
            		doPlayerAddSoul(cid, -9)
            		doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Agrhhh!")
        	else
            		doPlayerSendCancel(cid, "You do not have soul for this!")
        	end
    	elseif words == "!mana" and playerInfo[3] < playerInfo[4] then
	 	if playerInfo[5] >= 7 then 
			doPlayerAddMana(cid, 45)
            		doPlayerAddSoul(cid, -7)
            		doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "Ahhhh!")
        	else
            		doPlayerSendCancel(cid, "You do not have soul for this!")
        	end
    	end
    	return TRUE
end
 
Last edited:
Ok it's working.
Now i have only 1 question.
How to make something like "orange spells" for my "!heal" and "!mana"
 
Last edited:
doCreatureSay(cid, "Healed!", TALKTYPE_MONSTER)
or
doCreatureSay(cid, "Healed!", TALKTYPE_MONSTER_SAY)
 
Back
Top