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

Script too large.

bomba

Member
Joined
Feb 26, 2008
Messages
635
Reaction score
7
Location
Brazil
I created a "NPC", however long ago that I do not handle script I forgot many functions.
I used a lot of "storage" to offset the "talkState". Someone decreases the size of this script I made using "talkState"?
There's another problem too. After I finished the first mission, he is not giving me the option to start the second.
He keeps saying the same thing from the start when I say "hi": Hello. I am the guardian of this small town and I'm having some problems, if you {help} me I will give you a reward..
LUA:
local storOfNpc = 900001
local focuses = {}
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid)   npcHandler:onCreatureAppear(cid)   end

function onCreatureDisappear(cid)
    if isFocused(cid, focuses) then
     removeFocus(cid, focuses)
        if isPlayer(cid) then
         closeShopWindow(cid)
        end
    end
end

local function talkAnderson(cid)
   local distance = getDistanceTo(cid) or 5
	if distance > 4 then
	   return FALSE
	else
		if getPlayerStorageValue(cid, storOfNpc) > 0 then
		   setPlayerStorageValue(cid, storOfNpc, 0)
		   removeFocus(cid, focuses)
		   lookAtFocus(focuses)
		else
		   return FALSE
		end
	end
 return TRUE
end

function onCreatureSay(cid, type, msg)
   local distance = getDistanceTo(cid) or 5
	if distance > 4 then
	   return FALSE
	else
		if msgcontains(msg, "hi") or msgcontains(msg, "oi") then
			if getPlayerStorageValue(cid, 800001) == 2 then
				if getPlayerStorageValue(cid, storOfNpc) == 0 then
					if getLanguage(cid) == 1 then
					   selfSay("Good job! Take your reward!", cid)
					else
					   selfSay("Bom trabalho! Pegue sua recompensa!", cid)
					end
				   addFocus(cid, focuses)
				   setPlayerStorageValue(cid, storOfNpc, 0)
				   doPlayerAddItem(cid, 7618, 1)
				   setPlayerStorageValue(cid, 800001, 3)
				end
			elseif getPlayerStorageValue(cid, 800001) == 2 and getPlayerStorageValue(cid, 800002) == -1 then
				if getPlayerStorageValue(cid, storOfNpc) == 0 then
					if getLanguage(cid) == 1 then
					   selfSay("I have a new mission for you ... Kill a {spider} and prove that you are able to protect this city.", cid)
					else
					   selfSay("Tenho uma nova missão para você... Mate uma {aranha} e prove que você  é capaz de proteger esta cidade.", cid)
					end
				   addFocus(cid, focuses)
				   setPlayerStorageValue(cid, storOfNpc, 1)
				   setPlayerStorageValue(cid, 800002, 1)
				   addEvent(talkAnderson, 30000, cid)
				end
			elseif getPlayerStorageValue(cid, 800002) == 3 then
				if getPlayerStorageValue(cid, storOfNpc) == 0 then
					if getLanguage(cid) == 1 then
					   selfSay("Good job! Take your reward!", cid)
					else
					   selfSay("Bom trabalho! Pegue sua recompensa!", cid)
					end
				   addFocus(cid, focuses)
				   setPlayerStorageValue(cid, storOfNpc, 0)
				   doPlayerAddItem(cid, 2512, 1)
				   setPlayerStorageValue(cid, 800002, 4)
				end
			else
				if getPlayerStorageValue(cid, storOfNpc) == 0 then
					if getLanguage(cid) == 1 then
					   selfSay("Hello. I am the guardian of this small town and I'm having some problems, if you {help} me I will give you a reward.", cid)
					else
					selfSay("Olá. Sou o guardião desta pequena cidade e estou com alguns problemas, se quiser me {ajudar} eu irei lhe dar uma recompensa.", cid)
					end
				   addFocus(cid, focuses)
				   setPlayerStorageValue(cid, storOfNpc, 1)
				   addEvent(talkAnderson, 30000, cid)
			end
		end
	end
	if msgcontains(msg, "help") or msgcontains(msg, "ajudar") then
		if getPlayerStorageValue(cid, storOfNpc) == 1 then
			if getPlayerStorageValue(cid, 800001) == -1 then
				if getLanguage(cid) == 1 then
				   selfSay("I have a debt with a senior this small town. The name of this old and he is Olavio want three chicken feathers. Take him and seek reward with me. You want to do this for me?", cid)
				   setPlayerStorageValue(cid, storOfNpc, 2)
				else
				   selfSay("Tenho uma dívida com um idoso desta pequena cidade. O nome deste idoso é Olavio e ele quer três penas de galinha. Leve para ele e busque a recompensa comigo. Você quer fazer isto por mim?", cid)
				   setPlayerStorageValue(cid, storOfNpc, 2)
				end
			elseif getPlayerStorageValue(cid, 800001) == 1 then
				if getLanguage(cid) == 1 then
				   selfSay("You're already on a mission.", cid)
				else
				   selfSay("Você já está em uma missão.", cid)
				end
			else
				if getLanguage(cid) == 1 then
				   selfSay("You've done this mission.", cid)
				else
				   selfSay("Você já fez esta missão.", cid)
				end
			end
		   stopEvent(talkAnderson)
		   addEvent(talkAnderson, 30000, cid)
		else
		   return FALSE
		end
	end
	if msgcontains(msg, "spider") or msgcontains(msg, "aranha") and getPlayerStorageValue(cid, 800002) == 1 then
		if getPlayerStorageValue(cid, storOfNpc) == 1 then
			if getPlayerStorageValue(cid, 800002) == 1 then
				if getLanguage(cid) == 1 then
				   selfSay("You will even kill a spider? The reward is good.", cid)
				   setPlayerStorageValue(cid, storOfNpc, 2)
				   setPlayerStorageValue(cid, 800002, 2)
				else
				   selfSay("Você vai mesmo matar uma aranha? A recompensa é boa.", cid)
				   setPlayerStorageValue(cid, storOfNpc, 2)
				   setPlayerStorageValue(cid, 800002, 2)
				end
			elseif getPlayerStorageValue(cid, 800002) == 2 then
				if getLanguage(cid) == 1 then
				   selfSay("You're already on a mission.", cid)
				else
				   selfSay("Você já está em uma missão.", cid)
				end
			else
				if getLanguage(cid) == 1 then
				   selfSay("You've done this mission.", cid)
				else
				   selfSay("Você já fez esta missão.", cid)
				end
			end
		   stopEvent(talkAnderson)
		   addEvent(talkAnderson, 30000, cid)
		else
		   return FALSE
		end
	end
	if msgcontains(msg, "yes") or msgcontains(msg, "sim") then
		if getPlayerStorageValue(cid, storOfNpc) == 2 then
			if getLanguage(cid) == 1 then
			   selfSay("I'll be waiting for you with your reward!", cid)
			else
			   selfSay("Estarei lhe esperando com sua recompensa!", cid)
			end
		   setPlayerStorageValue(cid, 800001, 1)
		   setPlayerStorageValue(cid, storOfNpc, 3)
		   stopEvent(talkAnderson)
		   addEvent(talkAnderson, 30000, cid)
		else
		   return FALSE
		end
	end
	if msgcontains(msg, "no") or msgcontains(msg, "nao") then	
		if getPlayerStorageValue(cid, storOfNpc) == 2 then	
			if getLanguage(cid) == 1 then
			   selfSay("Ok then.", cid)
			else
			   selfSay("Você que sabe...", cid)
			end
		   setPlayerStorageValue(cid, storOfNpc, 3)
		   stopEvent(talkAnderson)
		   addEvent(talkAnderson, 30000, cid)
		end
	end
	if msgcontains(msg, "bye") or msgcontains(msg, "tchau") then
		if getPlayerStorageValue(cid, storOfNpc) > 0 then
			if getLanguage(cid) == 1 then
			   selfSay("Goodbye!", cid)
			else
			   selfSay("Adeus!", cid)
			end
		   setPlayerStorageValue(cid, storOfNpc, 0)
		   removeFocus(cid, focuses)
		   lookAtFocus(focuses)
		else
		   return FALSE
		end
	end
   end
end

function onThink()
    for _, focus in pairs(focuses) do
        if not isCreature(focus) then
         removeFocus(focus, focuses)
	 setPlayerStorageValue(focus, storOfNpc, 0)
        else
	   local distance = getDistanceTo(focus) or 5
            if distance > 4 then
                selfSay("...", focus)
                removeFocus(focus, focuses)
		setPlayerStorageValue(focus, storOfNpc, 0)
            end
        end
    end
    lookAtFocus(focuses)
end
 
Problem with very large script solved.
Now I have another problem:erro.jpg
LUA:
-- NPC Mission Example by Ramza (Ricardo Ianelli), made to OTservBrasil ([url=http://www.otserv.com.br]OTServ Brasil - O maior e melhor site de Open Tibia Server do Brasil[/url]). If you want to share or use as tutorial, please, keep the credits.-- Exemplo de NPC de missões feito por Ramza (Ricardo Ianelli), criado para OTservBrasil ([url=http://www.otserv.com.br]OTServ Brasil - O maior e melhor site de Open Tibia Server do Brasil[/url]). Se você quiser compartilhar ou usar como tutorial, por favor, mantenha os créditos. 
local focuses = {}
local talkState = {}

function onCreatureDisappear(cid)
    if isFocused(cid, focuses) then
     removeFocus(cid, focuses)
        if isPlayer(cid) then
         closeShopWindow(cid)
        end
    end
end

-- Storage 800001 = Missão atual (ID, a primeira é 0)
-- Storage 800002 = Missão completa (só pra dizer que a missão já foi completada, no caso, na das penas você assim que pegar 3 penas tem que mudar essa storage pra '1', que significa que você terminou a missão já.

local uncompleteMessage = {"You are already doing a mission for me! Finish that one before requesting another!", "Você já está fazendo uma missão para mim! Termine esta antes de pedir outra!"}
local completeMessage = {"Thank you very much for your help!", "Muito obrigado!"}

local missions = {
 [0] = { -- esse aqui é o numero que você colocava no storage 'storOfNpc'
       text = {  -- Aqui você coloca os textos, primeiro em inglês, depois em português.
               "I have a debt with a senior this small town. The name of this old and he is Olavio want three chicken feathers. Take him and seek reward with me!",
               "Tenho uma dívida com um idoso desta pequena cidade. O nome deste idoso é Olavio e ele quer três penas de galinha. Leve para ele e busque a recompensa comigo!",
              },
       rewards = {
                  {7618, 1}, -- aqui vocÊ vai colocando as recompensas assim, sempre entre {} e primeiro o ID do item, depois a quantidade.
                 },
       
       
       }, 
 [1] = { 
       text = {  
               "I have a new mission for you ... Kill a {spider} and prove that you are able to protect this city.",
               "Tenho uma nova missão para você... Mate uma {aranha} e prove que você  é capaz de proteger esta cidade.",
              },
       rewards = {
                  {2512, 1}, 
                 },
       
       
       },
       
       
}

function onCreatureSay(cid, type, msg)
   local name = getCreatureName(cid)
   local currentMission = getPlayerStorageValue(cid, 800001)
   local missionState = getPlayerStorageValue(cid, 800002)
   local language = getLanguage(cid)

	if msgcontains(msg, "hi", "hello", "oi", "ola", "olá", "bom dia", "boa tarde", "boa noite") and not isFocused(cid, focuses) then
		if getLanguage(cid) == ENGLISH then
		   selfSay("Hello. I am the guardian of this small town and I'm having some problems, if you {help} me I will give you a reward.", cid)
		else
		   selfSay("Olá. Sou o guardião desta pequena cidade e estou com alguns problemas, se quiser me {ajudar} eu irei lhe dar uma recompensa.", cid)
		end
	   talkState[cid] = 1 -- Talkstate 1 = você acabou de falar hi
	   addFocus(cid, focuses)
     
	elseif msgcontains(msg, "help", "ajudar", "ajuda") and isFocused(cid, focuses) then 
	   talkState[cid] = 2  -- talkstate 2 = você quer uma missão nova
		if currentMission == -1 then  -- Isso só vai ser feito uma vez, é pra quando você nunca tiver pego missão.
		   setPlayerStorageValue(cid, 800001, 0)  
	   	   currentMission = 0
		   missionState = 0
		   selfSay(missions[currentMission].text[language], cid)
		   removeFocus(cid, focuses)
		   lookAtFocus(focuses)       -- Ele sempre vai se despedir após passar uma nova missão pra você. Isso é pra facilitar seu trampo, já que você não consegue fazer muito bem as coisas ainda.
		   return true
		end
		if missionState == 0 then
		   selfSay(uncompleteMessage[language], cid)
		 else
		   selfSay(completeMessage[language], cid)
		   setPlayerStorageValue(cid, 800001, currentMission + 1) 
		   setPlayerStorageValue(cid, 800001, 0)
		   currentMission = currentMission + 1
		   missionState = 0
		   selfSay(missions[currentMission].text[language], cid)
		end
	elseif msgcontains(msg, "bye", "goodbye", "adeus", "tchau") and isFocused(cid, focuses) then
	   talkState[cid] = nil
		if getLanguage(cid) == ENGLISH then
		   selfSay("Bye.", cid)
		else
		   selfSay("Tchau.", cid)
		end
	   removeFocus(cid, focuses)
	   lookAtFocus(focuses)
	end
end


function onThink()
    for _, focus in pairs(focuses) do
        if not isCreature(focus) then
         removeFocus(focus, focuses)
        else
         local distance = getDistanceTo(focus) or 4
            if distance > 3 then
		if getLanguage(focus) == ENGLISH then
		   selfSay("Bye.", focus)
		else
		   selfSay("Tchau.", focus)
		end
                closeShopWindow(focus)
                removeFocus(focus, focuses)
            end
        end
    end
    lookAtFocus(focuses)
end
 
I don't see a large script.

LUA:
-- NPC Mission Example by Ramza (Ricardo Ianelli), made to OTservBrasil (<a href="http://www.otserv.com.br" target="_blank">OTServ Brasil - O maior e melhor site de Open Tibia Server do Brasil</a>). If you want to share or use as tutorial, please, keep the credits.-- Exemplo de NPC de missões feito por Ramza (Ricardo Ianelli), criado para OTservBrasil (<a href="http://www.otserv.com.br" target="_blank">OTServ Brasil - O maior e melhor site de Open Tibia Server do Brasil</a>). Se você quiser compartilhar ou usar como tutorial, por favor, mantenha os créditos. 
local focuses = {}
local talkState = {}
 
function onCreatureDisappear(cid)
    if isFocused(cid, focuses) then
     removeFocus(cid, focuses)
        if isPlayer(cid) then
         closeShopWindow(cid)
        end
    end
end
 
-- Storage 800001 = Missão atual (ID, a primeira é 0)
-- Storage 800002 = Missão completa (só pra dizer que a missão já foi completada, no caso, na das penas você assim que pegar 3 penas tem que mudar essa storage pra '1', que significa que você terminou a missão já.
 
local uncompleteMessage = {"You are already doing a mission for me! Finish that one before requesting another!", "Você já está fazendo uma missão para mim! Termine esta antes de pedir outra!"}
local completeMessage = {"Thank you very much for your help!", "Muito obrigado!"}
 
local missions = {
 [0] = { -- esse aqui é o numero que você colocava no storage 'storOfNpc'
       text = { -- Aqui você coloca os textos, primeiro em inglês, depois em português.
               "I have a debt with a senior this small town. The name of this old and he is Olavio want three chicken feathers. Take him and seek reward with me!",
               "Tenho uma dívida com um idoso desta pequena cidade. O nome deste idoso é Olavio e ele quer três penas de galinha. Leve para ele e busque a recompensa comigo!",
              },
       rewards = {
                  {7618, 1}, -- aqui vocÊ vai colocando as recompensas assim, sempre entre {} e primeiro o ID do item, depois a quantidade.
                 },
 
 
       }, 
 [1] = { 
       text = {  
               "I have a new mission for you ... Kill a {spider} and prove that you are able to protect this city.",
               "Tenho uma nova missão para você... Mate uma {aranha} e prove que você  é capaz de proteger esta cidade.",
              },
       rewards = {
                  {2512, 1}, 
                 },
 
 
       },
 
 
}
 
function onCreatureSay(cid, type, msg)
   local name = getCreatureName(cid)
   local currentMission = getPlayerStorageValue(cid, 800001)
   local missionState = getPlayerStorageValue(cid, 800002)
   local language = getLanguage(cid)
 
	if msgcontains(msg, "hi", "hello", "oi", "ola", "olá", "bom dia", "boa tarde", "boa noite") and not isFocused(cid, focuses) then
		if getLanguage(cid) == ENGLISH then
		   selfSay("Hello. I am the guardian of this small town and I'm having some problems, if you {help} me I will give you a reward.", cid)
		else
		   selfSay("Olá. Sou o guardião desta pequena cidade e estou com alguns problemas, se quiser me {ajudar} eu irei lhe dar uma recompensa.", cid)
		end
	   talkState[cid] = 1 -- Talkstate 1 = você acabou de falar hi
	   addFocus(cid, focuses)
 
	elseif msgcontains(msg, "help", "ajudar", "ajuda") and isFocused(cid, focuses) then 
	   talkState[cid] = 2 -- talkstate 2 = você quer uma missão nova
		if currentMission == -1 then -- Isso só vai ser feito uma vez, é pra quando você nunca tiver pego missão.
		   setPlayerStorageValue(cid, 800001, 0)  
	   	   currentMission = 0
		   missionState = 0
		   selfSay(missions[currentMission].text[language], cid)
		   removeFocus(cid, focuses)
		   lookAtFocus(focuses) -- Ele sempre vai se despedir após passar uma nova missão pra você. Isso é pra facilitar seu trampo, já que você não consegue fazer muito bem as coisas ainda.
		   return true
		end
		if missionState == 0 then
		   selfSay(uncompleteMessage[language], cid)
		 else
		   selfSay(completeMessage[language], cid)
		   setPlayerStorageValue(cid, 800001, currentMission + 1) 
		   setPlayerStorageValue(cid, 800001, 0)
		   currentMission = currentMission + 1
		   missionState = 0
           if missions[currentMission] then
                selfSay(missions[currentMission].text[language], cid)
           end
		end
	elseif msgcontains(msg, "bye", "goodbye", "adeus", "tchau") and isFocused(cid, focuses) then
	   talkState[cid] = nil
		if getLanguage(cid) == ENGLISH then
		   selfSay("Bye.", cid)
		else
		   selfSay("Tchau.", cid)
		end
	   removeFocus(cid, focuses)
	   lookAtFocus(focuses)
	end
end
 
 
function onThink()
    for _, focus in pairs(focuses) do
        if not isCreature(focus) then
         removeFocus(focus, focuses)
        else
         local distance = getDistanceTo(focus) or 4
            if distance > 3 then
		if getLanguage(focus) == ENGLISH then
		   selfSay("Bye.", focus)
		else
		   selfSay("Tchau.", focus)
		end
                closeShopWindow(focus)
                removeFocus(focus, focuses)
            end
        end
    end
    lookAtFocus(focuses)
end
 
Back
Top