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

Just some advice/help.

Dayon

New Member
Joined
Nov 12, 2012
Messages
15
Reaction score
1
Hello there! I just got back to Tibia to start scripting for a friend again but when I sat down to script I realized I had almost forgot everything about it....
So after I've read through a ton of scripts I tried to do an own one which is a npc who is supposed to teleport you to a location if you got the correct lvl when you talk to him.
Well my question is if someone could take a look at it real quick and see if it's correct atm or if there is anything that needs to get changed.
All comments are welcome! :)
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
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
 
local telepos = {x = xxx, y = xxx, z = xx}

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

		if msgcontains(msg, 'fight') then
			selfSay('Okey young one, you are here to fight demonic creatures? Am I right?', cid) then
		if msgcontains(msg, 'yes') then
			selfSay('Then what would you like to face? {lightweight} creatures, {normal} creatures, {stronger} creatures or {DAFUQ} WHAT AM I FIGHITING?', cid)
	end
end
		if msgcontains(msg, 'lightweight') then
			selfSay('Are you sure that you want to fight the lightweight creatures?', cid) then
		if msgcontains(msg, 'yes') then
			if(getPlayerLevel(cid) > x) then
				doTeleportPlayer(cid, telepos)
	else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
	end
end
		elseif msgcontains(msg, 'normal') then
			selfSay('Are you sure that you want to fight the normal creatures?', cid) then
		if msgcontains(msg, 'yes') then
			if(getPlayerLevel(cid) > x) then
				doTeleportPlayer(cid, telepos)
	else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
end
		elseif msgcontains(msg, 'stronger') then
			selfSay('Are you sure that you want to fight the stronger creatures?', cid) then
		if msgcontains(msg, 'yes') then
			if(getPlayerLevel(cid) > x) then
				doTeleportPlayer(cid, telepos)
	else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
end
		elseif msgcontains(msg, 'dafuq') then
			selfSay('Have you really thought about this? There is no way back from this insane creatures!', cid) then
		if msgcontains(msg, 'yes') then
			if(getPlayerLevel(cid) > x) then
				doTeleportPlayer(cid, telepos)
	else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
end

This is for 8.54 core btw.
 
Last edited by a moderator:
This is your script, in formated form:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid) npcHandlernCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandlernCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandlernCreatureSay(cid, type, msg) end
function onThink() npcHandlernThink() end

local telepos = {x = xxx, y = xxx, z = xx}

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

if msgcontains(msg, 'fight') then
	selfSay('Okey young one, you are here to fight demonic creatures? Am I right?', cid) then
	if msgcontains(msg, 'yes') then
		selfSay('Then what would you like to face? {lightweight} creatures, {normal} creatures, {stronger} creatures or {DAFUQ} WHAT AM I FIGHITING?', cid)
	end
end
if msgcontains(msg, 'lightweight') then
	selfSay('Are you sure that you want to fight the lightweight creatures?', cid) then
	if msgcontains(msg, 'yes') then
		if(getPlayerLevel(cid) > x) then
			doTeleportPlayer(cid, telepos)
		else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
		end
	end
elseif msgcontains(msg, 'normal') then
	selfSay('Are you sure that you want to fight the normal creatures?', cid) then
	if msgcontains(msg, 'yes') then
		if(getPlayerLevel(cid) > x) then
			doTeleportPlayer(cid, telepos)
		else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'stronger') then
		selfSay('Are you sure that you want to fight the stronger creatures?', cid) then
		if msgcontains(msg, 'yes') then
			if(getPlayerLevel(cid) > x) then
				doTeleportPlayer(cid, telepos)
			else
				selfSay('Come back when you have grown up kiddo!', cid)
				talk_state = 0
			end
		elseif msgcontains(msg, 'dafuq') then
			selfSay('Have you really thought about this? There is no way back from this insane creatures!', cid) then
			if msgcontains(msg, 'yes') then
				if(getPlayerLevel(cid) > x) then
					doTeleportPlayer(cid, telepos)
				else
					selfSay('Come back when you have grown up kiddo!', cid)
					talk_state = 0
				end
Some end's are missing, and why you write "then" after "selfSay" ???
Also it won't work, if you put a "if msgcontains()" into an "if msgcontains()" :p
If you need further help, write here. Or just look over your script again ;)
 
Thanks for the quick reply and yeh I thought it was wrong with "then" after "selfSay" but I saw it in some other script so I thought it had with new clients to do or something xD

But now then? I have looked through what you said and got this.
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
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
 
local telepos = {x = xxx, y = xxx, z = xx}

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

		if msgcontains(msg, 'fight') then
			selfSay('Okey young one, you are here to fight demonic creatures? Am I right?', cid)
end
		if msgcontains(msg, 'yes') then
			selfSay('Then what would you like to face? {lightweight} creatures, {normal} creatures, {stronger} creatures or {DAFUQ} WHAT AM I FIGHITING?', cid)
	end
end
		if msgcontains(msg, 'lightweight') then
			selfSay('Are you sure that you want to fight the lightweight creatures?', cid)
end
		if msgcontains(msg, 'yes') then
			if(getPlayerLevel(cid) > x) then
				doTeleportPlayer(cid, telepos)
	else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
	end
end
		elseif msgcontains(msg, 'normal') then
			selfSay('Are you sure that you want to fight the normal creatures?', cid)
end
		if msgcontains(msg, 'yes') then
			if(getPlayerLevel(cid) > x) then
				doTeleportPlayer(cid, telepos)
	else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
end
		elseif msgcontains(msg, 'stronger') then
			selfSay('Are you sure that you want to fight the stronger creatures?', cid)
end
		if msgcontains(msg, 'yes') then
			if(getPlayerLevel(cid) > x) then
				doTeleportPlayer(cid, telepos)
	else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
end
		elseif msgcontains(msg, 'dafuq') then
			selfSay('Have you really thought about this? There is no way back from this insane creatures!', cid)
end
		if msgcontains(msg, 'yes') then
			if(getPlayerLevel(cid) > x) then
				doTeleportPlayer(cid, telepos)
	else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
end
 
Last edited by a moderator:
Right formated ;)
Use:
[ lua]
script
[/code]
instead of
[ code]
script
[/code]
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
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
 
local telepos = {x = xxx, y = xxx, z = xx}

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	if msgcontains(msg, 'fight') then
		selfSay('Okey young one, you are here to fight demonic creatures? Am I right?', cid)
	end
	if msgcontains(msg, 'yes') then
		selfSay('Then what would you like to face? {lightweight} creatures, {normal} creatures, {stronger} creatures or {DAFUQ} WHAT AM I FIGHITING?', cid)
	end
end


	if msgcontains(msg, 'lightweight') then
		selfSay('Are you sure that you want to fight the lightweight creatures?', cid)
	end
	if msgcontains(msg, 'yes') then
		if(getPlayerLevel(cid) > x) then
			doTeleportPlayer(cid, telepos)
		else
			selfSay('Come back when you have grown up kiddo!', cid)
			talk_state = 0
		end
	end
	
	
elseif msgcontains(msg, 'normal') then
	selfSay('Are you sure that you want to fight the normal creatures?', cid)
end
if msgcontains(msg, 'yes') then
	if(getPlayerLevel(cid) > x) then
		doTeleportPlayer(cid, telepos)
	else
		selfSay('Come back when you have grown up kiddo!', cid)
		talk_state = 0
	end
elseif msgcontains(msg, 'stronger') then
	selfSay('Are you sure that you want to fight the stronger creatures?', cid)
end
if msgcontains(msg, 'yes') then
	if(getPlayerLevel(cid) > x) then
		doTeleportPlayer(cid, telepos)
	else
		selfSay('Come back when you have grown up kiddo!', cid)
		talk_state = 0
	end
elseif msgcontains(msg, 'dafuq') then
	selfSay('Have you really thought about this? There is no way back from this insane creatures!', cid)
end
if msgcontains(msg, 'yes') then
	if(getPlayerLevel(cid) > x) then
		doTeleportPlayer(cid, telepos)
	else
		selfSay('Come back when you have grown up kiddo!', cid)
		talk_state = 0
	end
Don't use that much new if's. Use "elseif" instead.
Also If you do "msgcontains(msg, 'yes')" twice, only the first one is "seen" by the script.
 
Okey thanks a lot, but can't I use msgcontains(msg, 'yes') in another "part"?
Like after an end? Cause I can't find once where I have double yes :p
 
Maybe, you could try this example:
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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

npcHandler:setMessage(MESSAGE_GREET, 'Herzlich willkommen auf meiner kleinen Farm |PLAYERNAME|. Wie kann mein {job} dir weiter helfen?')

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	if msgcontains(msg, 'job') then
		selfSay("My job is, to teach you scripting.", cid)
	elseif msgcontains(msg, 'question') or msgcontains(msg, 'task') or msgcontains(msg, 'mission') then
		selfSay("So you want me to ask you a question, is that right?", cid)
		talkState[talkUser] = 1
	elseif msgcontains(msg, 'monster') then
		selfSay("You want to hear more about the dangerous monster out there?", cid)
		talkState[talkUser] = 2
	elseif msgcontains(msg, 'yes') then
		if talkState[talkUser] == 1 then
			selfSay("My question is... are you really that stupid?", cid)
			talkState[talkUser] = 0
		elseif talkState[talkUser] == 2 then
			selfSay("The monster is a dragon, and there is a big story to tell...", cid)
			talkState[talkUser] = 0
		else
			selfSay("Yes? Yes what?", cid)
		end
	end
	return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Hope you understand, what I want you to tell :)
 
I have never seen that way of using talkstates. Really amazing thing you can do then! Thanks for showing me that.
Tho this talkState thingys is new to me so if you could I would appriciate if you explain what they are for and what they do :p Same with the "return True/False". I remember writing em but I can figure out what they do really xD
 
Talkstates act as railroad tracks.

Depending on the talkstate value, it will lead you to different paths in the conversation.

Simple algorithm for example:
Lua:
if msg == "task" and talkstate == 0 then
selfSay("Pick task: A or B", cid)
talkstate = 1

if msg == "A" and talkstate == 1 then
selfSay("Do you want to do task A?", cid)
talkstate = 2

if msg == "B" and talkstate == 1 then
selfSay("Do you want to do task B?", cid)
talkstate = 3

if msg == "yes" and talkstate == 2 then
selfSay("Task A it is then!", cid)
talkstate = 4

if msg == "yes" and talkstate == 3 then
selfSay("Task B it is then!", cid)
talkstate = 5

if msg == "complete" and talkstate == 4 then
selfSay("Task A complete!", cid)
talkstate = 0

if msg == "complete" and talkstate == 5 then
selfSay("Task B complete!", cid)
talkstate = 0

If you follow the tracks:
Task A talkstates: 0 -> 1 -> 2 -> 4 -> 0
Task B talkstates: 0 -> 1 -> 3 -> 5 -> 0
 
Back
Top