local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- OTServ event handling functions start
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
-- OTServ event handling functions end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
if msgcontains(msg, 'help') then
selfSay('Write "shielding", "sword", "axe", "club", "distance" or "magic" to get skills.')
elseif msgcontains(msg, 'magic') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get magic skill for 1 Crystal coin ?')
talk_state = 2
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 2 then
talk_state = 0
if(getPlayerMagLevel(cid) >= 100) then
selfSay('You have max amount of this skill.')
return 0
elseif getPlayerItemCount(cid, 2160) >= 1 then
if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
doPlayerAddSpentMana(cid, 15000)
selfSay('Here u are.')
end
else
selfSay('You must have 20 lvl.')
end
elseif msgcontains(msg, 'shielding') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get shielding skill for 1 Crystal coin ?')
talk_state = 1
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 1 then
talk_state = 0
if(getPlayerSkillLevel(cid, 5) >= 100) then
selfSay('You have max amount of this skill.')
return 0
elseif getPlayerItemCount(cid, 2160) >= 1 then
if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
doPlayerAddSkillTry(cid, 5, 150)
selfSay('Here u are.')
end
else
selfSay('You must have 20 lvl.')
end
elseif msgcontains(msg, 'sword') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get sword skill for 1 Crystal coin ?')
talk_state = 3
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 3 then
talk_state = 0
if(getPlayerSkillLevel(cid, 2) >= 100) then
selfSay('You have max amount of this skill.')
return 0
elseif getPlayerItemCount(cid, 2160) >= 1 then
if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
doPlayerAddSkillTry(cid, 2, 20)
selfSay('Here u are.')
end
end
elseif msgcontains(msg, 'axe') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get axe skill for 1 Crystal coin ?')
talk_state = 4
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 4 then
talk_state = 0
if(getPlayerSkillLevel(cid, 3) >= 100) then
selfSay('You have max amount of this skill.')
return 0
elseif getPlayerItemCount(cid, 2160) >= 1 then
if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
doPlayerAddSkillTry(cid, 3, 20)
selfSay('Here u are.')
end
end
elseif msgcontains(msg, 'club') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get club skill for 1 Crystal coin ?')
talk_state = 5
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 5 then
talk_state = 0
if(getPlayerSkillLevel(cid, 1) >= 100) then
selfSay('You have max amount of this skill.')
return 0
elseif getPlayerItemCount(cid, 2160) >= 1 then
if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
doPlayerAddSkillTry(cid, 1, 20)
selfSay('Here u are.')
end
end
elseif msgcontains(msg, 'distance') then
if getPlayerItemCount(cid, 2160) >= 1 then
selfSay('Do you want to get distance skill for 1 Crystal coin ?')
talk_state = 6
else
selfSay('You have to pay 1 crystal coin.')
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 6 then
talk_state = 0
if(getPlayerSkillLevel(cid, 4) >= 100) then
selfSay('You have max amount of this skill.')
return 0
elseif getPlayerItemCount(cid, 2160) >= 1 then
if doPlayerRemoveItem(cid, 2160, 1) == TRUE then
doPlayerAddSkillTry(cid, 4, 100)
selfSay('Here u are.')
end
end
elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
selfSay('Ok than.')
talk_state = 0
end
-- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())