• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua A little help

ond

Veteran OT User
Joined
Mar 24, 2008
Messages
2,782
Solutions
25
Reaction score
491
Location
Sweden
Edit: for a solution, scroll down to Cykotitans post.
 
Last edited:
1st: What would that help? o.O
2nd: I don't have a full script, I wrote those functions in a new document :P
 
1st: What would that help? o.O
0_0;
2nd: I don't have a full script, I wrote those functions in a new document :P
Those are statements not functions, these are functions:
LUA:
function blablabla(param)
     if param == true then
          print('Hi')
     else
          print('bye')
     end
end

Shorter:
LUA:
function blablabla(param)
     return print((param == true and 'Hi' or 'bye'))
end
 
Last edited:
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t

local phoenix = 44
local geomancer = 199

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

function greetCallback(cid)
	t = nil
	if getPlayerStorageValue(cid, phoenix) == -1 then
		npcHandler:setMessage(MESSAGE_GREET, "Welcome, pilgrim |PLAYERNAME|! May the flame guide you!")
	else
		npcHandler:setMessage(MESSAGE_GREET, "Be greeted |PLAYERNAME|! I can smell the scent of a phoenix on you!")
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	end

	local n
	if t == 6 and msgcontains(msg, 'yes') and getPlayerItemCount(cid, 2328) ~= 0 and getPlayerMoney(cid) < 9000 then
		selfSay("Oh. You do not have enough money.")
	elseif t == 6 and msgcontains(msg, 'yes') and getPlayerBlessing(cid, 2) then
		selfSay("You already possess this blessing.")
	elseif t == 6 and msgcontains(msg, 'yes') and getPlayerStorageValue(cid, geomancer) == -1 then
		selfSay("You need the blessing of the great geomancer first.")
	elseif t == 6 and msgcontains(msg, 'yes') and getPlayerItemCount(cid, 2328) ~= 0 then
		doPlayerRemoveMoney(cid, 9000)
		doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
		doPlayerAddBlessing(cid, 2)
		setPlayerStorageValue(cid, geomancer, -1)
	elseif t == 7 and msgcontains(msg, 'yes') and getPlayerBlessing(cid, 2) then
		selfSay("You already possess this blessing.")
	elseif t == 7 and msgcontains(msg, 'yes') and getPlayerStorageValue(cid, geomancer) == -1 then
		selfSay("You need the blessing of the great geomancer first.")
	elseif t == 7 and msgcontains(msg, 'yes') and getPlayerMoney(cid) < 10000 then
		selfSay("Oh. You do not have enough money.")
	elseif t == 5 and msgcontains(msg, 'yes') and getPlayerBlessing(cid, 2) then
		selfSay("You already possess this blessing.")
	elseif t == 5 and msgcontains(msg, 'yes') and getPlayerStorageValue(cid, geomancer) == -1 then
		selfSay("You need the blessing of the great geomancer first.")
	elseif t == 5 and msgcontains(msg, 'yes') and getPlayerMoney(cid) < 10000 then
		selfSay("Oh. You do not have enough money.")
	elseif msgcontains(msg, 'phoenix') and msgcontains(msg, 'egg') and getPlayerStorageValue(cid, phoenix) == 1 then
		selfSay("The phoenix seems to be fond of you! If you had a real phoenix egg on you, I could provide you the blessing of the spark of the phoenix more easy and cheaper!")
	elseif (msgcontains(msg, 'spark') or msgcontains(msg, 'phoenix')) and getPlayerStorageValue(cid, phoenix) == 1 then
		if getPlayerItemCount(cid, 2328) ~= 0 then
			selfSay("Since the phoenix smiles upon you, you might receive this blessing for 9.000 gold while you have a phoenix egg with you. So are you ready?")
			n = 6
		else
			selfSay("Since the phoenix smiles upon you, could have received this blessing cheaper if you had a phoenix egg with you. But because you don't have it with you, its still 10.000 gold. Is that ok?")
			n = 7
		end
	elseif (msgcontains(msg, 'spark') or msgcontains(msg, 'phoenix')) and getPlayerStorageValue(cid, phoenix) == -1 and getPlayerItemCount(cid, 2328) ~= 0 then
		selfSay("Although you have a phoenix egg with you, the phoenix doesn't smile on you since you didn't earn it by yourself. Thus, the blessing is still 10.000 gold. Is that alright?")
		n = 7
	elseif (t == 7 or t == 5) and msgcontains(msg, 'yes') then
		selfSay("So receive the mark of the flame and be blessed by the phoenix, pilgrim.")
		doPlayerRemoveMoney(cid, 10000)
		doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
		doPlayerAddBlessing(cid, 2)
		setPlayerStorageValue(cid, geomancer, -1)
	elseif msgcontains(msg, 'scent') and getPlayerStorageValue(cid, phoenix) == 1 then
		selfSay("The phoenix seems to be fond of you! If you had a real phoenix egg on you, I could provide you the blessing of the spark of the phoenix more easy and cheaper!")
	elseif msgcontains(msg, 'heal') and getCreatureCondition(cid, CONDITION_FIRE) then
		selfSay("You are burning. Take it as a blessing and don't cry like a baby, jawoll.")
	elseif msgcontains(msg, 'heal') and getCreatureCondition(cid, CONDITION_POISON) then
		selfSay("You are poisoned. I will help you.")
		doRemoveCondition(cid, CONDITION_POISON)
		doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED)
	elseif msgcontains(msg, 'heal') and getCreatureHealth(cid) < 40 then
		selfSay("Weakling! If you are not prepared to face the heat, stay out of the fire! Well, alright, I will heal you a little.")
		doCreatureAddHealth(cid, 40 - getCreatureHealth(cid))
		doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
	elseif msgcontains(msg, 'big') and msgcontains(msg, 'old') then
		selfSay("This mountain is said to be the oldest in the world. It's the place where fire and earth meet and part at the same time.")
	elseif msgcontains(msg, 'fire') and msgcontains(msg, 'devil') then
		selfSay("They mock the great flame with their sheer existence. BLAST THEM ALL! Jawoll!")
	elseif msgcontains(msg, 'what') and msgcontains(msg, 'do') then
		selfSay("Ask around. There's a lot to do, jawoll.")
	elseif msgcontains(msg, 'sacred') and msgcontains(msg, 'places') then
		selfSay("Just tell me in which of the five blessings you are interested.")
	elseif t == 6 or t == 7 or t == 5 then
		selfSay("Maybe another time.")
	elseif msgcontains(msg, 'suns') then
		selfSay("Ask for the Fire of the Suns in the Suntower near Ab'Dendriel.")
	elseif msgcontains(msg, 'job') then
		selfSay("I'm the head pyromancer of Kazordoon.")
	elseif msgcontains(msg, 'name') then
		selfSay("My name is Pydar Firefist, Son of Fire from the Savage Axes.")
	elseif msgcontains(msg, 'tibia') then
		selfSay("That's our world.")
	elseif msgcontains(msg, 'kazordoon') then
		selfSay("Our city was founded in ancient times. Abandoned by the gods we once fought for, we created a secure haven for our people.")
	elseif msgcontains(msg, 'elves') then
		selfSay("They don't understand anything about the world.")
	elseif msgcontains(msg, 'humans') then
		selfSay("They took the place dwarfs used to hold in the world. They don't see that they are destined to fall just like we did.")
	elseif msgcontains(msg, 'orcs') then
		selfSay("The arch enemy. We could have destroyed them long ago, but this would have meant doing the gods that betrayed us a favour.")
	elseif msgcontains(msg, 'minotaurs') then
		selfSay("Another pawn the gods do no longer care for, a discarded toy like all of the elder races.")
	elseif msgcontains(msg, 'pyromancer') then
		selfSay("We are the keepers and shepherds of the elemental force of fire.")
	elseif msgcontains(msg, 'god') or msgcontains(msg, 'keeper') or msgcontains(msg, 'shepherd') then
		selfSay("The ways of the gods are incomprehensible to mortals.")
	elseif msgcontains(msg, 'fire') or msgcontains(msg, 'flame') then
		selfSay("Unlike the gods, the elements don't use mortals as toys. A skilled mind can understand and even control them to some extent.")
	elseif msgcontains(msg, 'durin') then
		selfSay("Though we are through with the so-called gods, Durin, the first dwarf to acquire divine powers, is considered as protector of our race.")
	elseif msgcontains(msg, 'life') then
		selfSay("Life feeds on fire and ultimately fire will feed on life.")
	elseif msgcontains(msg, 'plant') then
		selfSay("I don't care much about plants.")
	elseif msgcontains(msg, 'citizen') then
		selfSay("Many brave people are citizens of our town.")
	elseif msgcontains(msg, 'kroox') then
		selfSay("He's a smith. If you are looking for exquisite weapons and armor, just talk to him.")
	elseif msgcontains(msg, 'jimbin') then
		selfSay("He and his wife are running the Jolly Axeman tavern.")
	elseif msgcontains(msg, 'maryza') then
		selfSay("She and her husband are running the Jolly Axeman tavern.")
	elseif msgcontains(msg, 'bezil') or msgcontains(msg, 'nezil') then
		selfSay("Bezil and Nezil are buying and selling equipment of all kinds.")
	elseif msgcontains(msg, 'uzgod') then
		selfSay("Uzgod is a weaponsmith just like those in the old legends.")
	elseif msgcontains(msg, 'etzel') then
		selfSay("Etzel is a true master of the elements. He is a role-model for our youngsters, jawoll.")
	elseif msgcontains(msg, 'gregor') then
		selfSay("The leader of the Thaian knight guild is a man of few words.")
	elseif msgcontains(msg, 'duria') then
		selfSay("She is the first knight of Kazordoon. She is responsible for teaching our young warriors how to handle an axe.")
	elseif msgcontains(msg, 'emperor') or msgcontains(msg, 'kruzak') then
		selfSay("Our emperor has his halls in the upper caves.")
	elseif msgcontains(msg, 'geomancer') then
		selfSay("They are followers of the path of earth.")
	elseif msgcontains(msg, 'technomancer') then
		selfSay("Those heretics believe they have discovered a new elemental force they can control easily. These fools, they'll bring doom upon all of us!")
	elseif msgcontains(msg, 'motos') or msgcontains(msg, 'general') then
		selfSay("He is the fiercest axe fighter of our times and a fine strategist.")
	elseif msgcontains(msg, 'army') then
		selfSay("Our strong fortifications allow our armies to defend Kazordoon against any threat.")
	elseif msgcontains(msg, 'ferumbras') then
		selfSay("If he ever dares to enter Kazordoon, I will gladly dump him into the lava. The sacred flame shall bring justice upon him.")
	elseif msgcontains(msg, 'excalibug') then
		selfSay("A weapon too powerful to be wielded by mortals. It has to be returned to the fire which gave birth to it.")
	elseif msgcontains(msg, 'news') then
		selfSay("I'm a busy man. I have no time for chitchat.")
	elseif msgcontains(msg, 'monster') then
		selfSay("May the great flame devour them all!")
	elseif msgcontains(msg, 'help') then
		selfSay("I'm not here to help you. You have to help yourself.")
	elseif msgcontains(msg, 'quest') or msgcontains(msg, 'task') then
		selfSay("Ask around. There's a lot to do, jawoll.")
	elseif msgcontains(msg, 'gold') or msgcontains(msg, 'money') then
		selfSay("Gold has been given birth to by the great flame. So it's wise to give some back to the fire now and then.")
	elseif msgcontains(msg, 'equipment') then
		selfSay("Bezil and Nezil are running a shop where you can buy all the stuff you need.")
	elseif msgcontains(msg, 'fight') then
		selfSay("You should fight like fire, fearless and without mercy.")
	elseif msgcontains(msg, 'heal') then
		selfSay("You aren't looking that bad. Sorry, I can't help you. But if you are looking for additional protection, you should go on the pilgrimage of ashes.")
	elseif msgcontains(msg, 'pilgrimage') or msgcontains(msg, 'ashes') then
		selfSay("Whenever you receive a lethal wound, your vital force is damaged and there is a chance that you lose some of your equipment. With every single of the five blessings you have, this damage and chance of loss will be reduced.")
	elseif msgcontains(msg, 'blessing') then
		selfSay("There are five different blessings available in five sacred places. These blessings are: the spiritual shielding, the spark of the phoenix, the embrace of Tibia, the fire of the suns and the wisdom of solitude.")
	elseif msgcontains(msg, 'spiritual') or msgcontains(msg, 'shielding') then
		selfSay("You can receive the Spiritual Shielding in the Whiteflower Temple south of Thais.")
	elseif msgcontains(msg, 'spark') or msgcontains(msg, 'phoenix') then
		selfSay("The Spark of the Phoenix is given by me and by the great geomancer of the local earth temple. Do you wish to receive my part of the Spark of the Phoenix for 10.000 gold?")
		n = 5
	elseif msgcontains(msg, 'embrace') then
		selfSay("The druids north of Carlin can provide you with the Embrace of Tibia.")
	elseif msgcontains(msg, 'wisdom') or msgcontains(msg, 'solitude') then
		selfSay("Talk to the hermit Eremo on the isle of Cormaya about this blessing.")
	elseif msgcontains(msg, 'time') then
		selfSay("It's the fourth age of the yellow flame.")
	else
		return true
	end
	t = n
	return true
end

npcHandler:setMessage(MESSAGE_FAREWELL, "May the fire in your heart never die, |PLAYERNAME|!")
npcHandler:setMessage(MESSAGE_IDLETIMEOUT, "May the fire in your heart never die.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "May the fire in your heart never die.")
npcHandler:setMessage(MESSAGE_PLACEDINQUEUE, "Please wait a minute, |PLAYERNAME|.")

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
sorry for the mess, it's been made in a way which makes the NPC behave exactly like with Cipsoft's npc system (cases with most conditions get checked first), which doesn't look really good in a more advanced language like Lua, but it works
 
Back
Top