Concordo plenamente REP + TEU
- Fórum
- xTibia - Notícias e Suporte
- Soluções
- Archived
- [Npc] Talkstates É Um Saco.
info
Grupo: Campones
Registrado: 10/12/11
Posts: 17
Reputação: +1
Char no Tibia: Shippuden

Tenta ai sky
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
local config = {
skills = {club = 1, sword = 2, axe = 3, distance = 4, shield = 5},
item = 9971,
count = 1
}
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, 'sword') then
if isInArray({4,8},getPlayerVocation(cid)) then
selfSay('You want to buy a skill sword for 1 gold ingot.?', cid)
talkState[talkUser] = 1
else
selfSay('Only knight and elite knight can buy sword fighting.', cid)
end
elseif msgcontains(msg, 'club') then
if isInArray({4,8},getPlayerVocation(cid)) then
selfSay('You want to buy a skill club for 1 gold ingot?', cid)
talkState[talkUser] = 2
else
selfSay('Only knight and elite knight can buy club fighting.', cid)
end
elseif msgcontains(msg, 'mace') then
if isInArray({4,8},getPlayerVocation(cid)) then
selfSay('You want to buy a skill mace for 1 gold ingot.?', cid)
talkState[talkUser] = 3
else
selfSay('Only knight and elite knight can buy mace fighting.', cid)
end
elseif msgcontains(msg, 'axe') then
if isInArray({4,8},getPlayerVocation(cid)) then
selfSay('You want to buy a skill axe for 1 gold ingot.?', cid)
talkState[talkUser] = 4
else
selfSay('Only knight and elite knight can buy axe fighting.', cid)
end
elseif msgcontains(msg, 'shield') then
if isInArray({4,3,7,8},getPlayerVocation(cid)) then
selfSay('You want to buy a skill distance for 1 gold ingot.?', cid)
talkState[talkUser] = 5
else
selfSay('Only paladins ,royal paladins, knight and elite knight can buy shield fighting.', cid)
end
elseif msgcontains(msg, 'distance') then
if isInArray({3,7},getPlayerVocation(cid)) then
selfSay('You want to buy a skill distance for 1 gold ingot.?', cid)
talkState[talkUser] = 6
else
selfSay('Only paladins and royal paladins can buy distance fighting.', cid)
end
elseif msgcontains(msg, 'info')then
selfSay('Você deseja ver suas informações?', cid)
talkState[talkUser] = 7
elseif talkState[talkUser] == 1 then
if msg == 'yes' or msg == 'sim' then
if doPlayerRemoveItem(cid,config.item,item.count) then
doPlayerAddSkill(cid,config.skills.sword,1)
selfSay('You bought a sword skill.', cid)
talkState[talkUser] = 0
else
selfSay('You do not have the needed item', cid)
end
elseif talkState[talkUser] == 3 then
if msg == 'yes' or msg == 'sim' then
if doPlayerRemoveItem(cid,config.item,item.count) then
doPlayerAddSkill(cid,config.skills.mace,1)
selfSay('You bought a mace skill.', cid)
talkState[talkUser] = 0
else
selfSay('You do not have the needed item', cid)
end
elseif talkState[talkUser] == 4 then
if msg == 'yes' or msg == 'sim' then
if doPlayerRemoveItem(cid,config.item,item.count) then
doPlayerAddSkill(cid,config.skills.axe,1)
selfSay('You bought a axe skill.', cid)
talkState[talkUser] = 0
else
selfSay('You do not have the needed item', cid)
end
elseif talkState[talkUser] == 5 then
if msg == 'yes' or msg == 'sim' then
if doPlayerRemoveItem(cid,config.item,item.count) then
doPlayerAddSkill(cid,config.skills.shield,1)
selfSay('You bought a shield skill.', cid)
talkState[talkUser] = 0
else
selfSay('You do not have the needed item', cid)
end
elseif talkState[talkUser] == 6 then
if msg == 'yes' or msg == 'sim' then
if doPlayerRemoveItem(cid,config.item,item.count) then
doPlayerAddSkill(cid,config.skills.distance,1)
selfSay('You bought a distance skill.', cid)
talkState[talkUser] = 0
else
selfSay('You do not have the needed item', cid)
end
elseif talkState[talkUser] == 7 then
if msg == 'yes' or msg == 'sim' then
if isInArray({4,8},getPlayerVocation(cid)) then
doShowTextDialog(cid, 5958, "•Skill Information:" ..
"\n¤Sword: " .. getPlayerSkillLevel(cid, config.skills.sword) ..
"\n¤Mace: " .. getPlayerSkillLevel(cid, config.skills.mace) ..
"\n¤Axe: " .. getPlayerSkillLevel(cid, config.skills.axe) ..
"\n¤Shield: " .. getPlayerSkillLevel(cid, config.skills.shield) ..
"" )
talkState[talkUser] = 0
elseif isInArray({3,7},getPlayerVocation(cid)) then
doSowTextDialog(cid, 5958, "•Skill Information:" ..
"\n¤Distance: " .. getPlayerSkillLevel(cid, config.skills.distance) ..
"\n¤Shield: " .. getPlayerSkillLevel(cid, config.skills.shield) ..
"" )
end
end
end
end
end
end
end
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
@EDIT AI ERREI NUMA PARTE NAO SEI C VAI FUNCIONAR C VOCE JA COPIO COPIA DNV
Editado Março 19 por Zmovir
info
Grupo: Herói
Registrado: 20/05/10
Posts: 3.4k
Reputação: +1.5k
Gênero: Masculino

sim,nesse caso eu preferia usar tabela...
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
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local skills = {
["club"] = {skillid = 1,price = {15,9971},vocs = {4,8}},
["sword"] = {skillid = 2,price = {15,9971},vocs = {4,8}},
["mace"] = {skillid = 0,price = {15,9971},vocs = {4,8}},
["axe"] = {skillid = 4,price = {15,9971},vocs = {4,8}},
["shield"] = {skillid = 5,price = {15,9971},vocs = {4,3,7,8}},
["distance"] = {skillid = 4,price = {15,9971},vocs = {3,7}}
}
if (msgcontains(msg, 'skill') or msgcontains(msg, 'skills'))then
local str = ""
str = str .. "I selling this skills: "
for name, pos in pairs(skills) do
str = str.." {"..name.."} = "..pos.price[1].." gold ingot /"
end
str = str .. "."
npcHandler:say(str, cid)
elseif skills[msg] then
if isInArray(skills[msg].vocs,getPlayerVocation(cid)) then
if doPlayerRemoveItem(cid,skills[msg].price[2],skills[msg].price[1]) then
doPlayerAddSkill(cid,skills[msg].skillid,1)
npcHandler:say("You bought a "..msg.." skill", cid)
else
npcHandler:say("You do not have "..skills[msg].price[1].." ".. getItemNameById(skills[msg].price[2]), cid)
end
else
npcHandler:say("You dont have vocation for buy this skill", cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Editado Março 19 por Vodkart




info
Grupo: Lorde
Registrado: 17/01/09
Posts: 2.1k
Reputação: +395
Char no Tibia: Adra Sata
Alguém pode dar arrumada no meu script, eu sei que ele ta muito pogzado, ultimamente não tenho querendo pensar em usar tabelas e for ;D
Ai eu faço da maneira que eu encontrar mais facil e pensar menos ;D
Quando eu falo hi , sword , yes .. ele só aceita o sword e não fala nada no yes.
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 local config = { skills = {club = 1, sword = 2, axe = 3, distance = 4, shield = 5}, item = 9971, count = 1 } 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, 'sword') then if isInArray({4,8},getPlayerVocation(cid)) then selfSay('You want to buy a skill sword for 1 gold ingot.?', cid) talkState[talkUser] = 1 else selfSay('Only knight and elite knight can buy sword fighting.', cid) end elseif msgcontains(msg, 'club') then if isInArray({4,8},getPlayerVocation(cid)) then selfSay('You want to buy a skill club for 1 gold ingot?', cid) talkState[talkUser] = 2 else selfSay('Only knight and elite knight can buy club fighting.', cid) end elseif msgcontains(msg, 'mace') then if isInArray({4,8},getPlayerVocation(cid)) then selfSay('You want to buy a skill mace for 1 gold ingot.?', cid) talkState[talkUser] = 3 else selfSay('Only knight and elite knight can buy mace fighting.', cid) end elseif msgcontains(msg, 'axe') then if isInArray({4,8},getPlayerVocation(cid)) then selfSay('You want to buy a skill axe for 1 gold ingot.?', cid) talkState[talkUser] = 4 else selfSay('Only knight and elite knight can buy axe fighting.', cid) end elseif msgcontains(msg, 'shield') then if isInArray({4,3,7,8},getPlayerVocation(cid)) then selfSay('You want to buy a skill distance for 1 gold ingot.?', cid) talkState[talkUser] = 5 else selfSay('Only paladins ,royal paladins, knight and elite knight can buy shield fighting.', cid) end elseif msgcontains(msg, 'distance') then if isInArray({3,7},getPlayerVocation(cid)) then selfSay('You want to buy a skill distance for 1 gold ingot.?', cid) talkState[talkUser] = 6 else selfSay('Only paladins and royal paladins can buy distance fighting.', cid) end elseif msgcontains(msg, 'info')then selfSay('Você deseja ver suas informações?', cid) talkState[talkUser] = 7 elseif talkState[talkUser] == 1 then if msgcontains(msg, 'yes') then if doPlayerRemoveItem(cid,config.item,item.count) then doPlayerAddSkill(cid,config.skills.sword,1) selfSay('You bought a sword skill.', cid) talkState[talkUser] = 0 else selfSay('You do not have the needed item', cid) end elseif talkState[talkUser] == 3 then if msgcontains(msg, 'yes') then if doPlayerRemoveItem(cid,config.item,item.count) then doPlayerAddSkill(cid,config.skills.mace,1) selfSay('You bought a mace skill.', cid) talkState[talkUser] = 0 else selfSay('You do not have the needed item', cid) end elseif talkState[talkUser] == 4 then if msgcontains(msg, 'yes') then if doPlayerRemoveItem(cid,config.item,item.count) then doPlayerAddSkill(cid,config.skills.axe,1) selfSay('You bought a axe skill.', cid) talkState[talkUser] = 0 else selfSay('You do not have the needed item', cid) end elseif talkState[talkUser] == 5 then if msgcontains(msg, 'yes') then if doPlayerRemoveItem(cid,config.item,item.count) then doPlayerAddSkill(cid,config.skills.shield,1) selfSay('You bought a shield skill.', cid) talkState[talkUser] = 0 else selfSay('You do not have the needed item', cid) end elseif talkState[talkUser] == 6 then if msgcontains(msg, 'yes') then if doPlayerRemoveItem(cid,config.item,item.count) then doPlayerAddSkill(cid,config.skills.distance,1) selfSay('You bought a distance skill.', cid) talkState[talkUser] = 0 else selfSay('You do not have the needed item', cid) end elseif talkState[talkUser] == 7 then if msgcontains(msg, 'yes') then if isInArray({4,8},getPlayerVocation(cid)) then doShowTextDialog(cid, 5958, "•Skill Information:" .. "\n¤Sword: " .. getPlayerSkillLevel(cid, config.skills.sword) .. "\n¤Mace: " .. getPlayerSkillLevel(cid, config.skills.mace) .. "\n¤Axe: " .. getPlayerSkillLevel(cid, config.skills.axe) .. "\n¤Shield: " .. getPlayerSkillLevel(cid, config.skills.shield) .. "" ) talkState[talkUser] = 0 elseif isInArray({3,7},getPlayerVocation(cid)) then doSowTextDialog(cid, 5958, "•Skill Information:" .. "\n¤Distance: " .. getPlayerSkillLevel(cid, config.skills.distance) .. "\n¤Shield: " .. getPlayerSkillLevel(cid, config.skills.shield) .. "" ) end end end end end end end end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())Sempre tive dificuldade nisso ;D