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












