data > npc > scripts > NomeDoNPC.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 config = {
itemID = 11192, -- ID da Moeda VIP
quantity = 100, -- Quantidade de moedas que o jogador precisa ter na mochila
minLevel = 8 -- Level minimo que o jogador precisa ter para comprar a promotion
}
local itemName = getItemNameById(config.itemID)
function checkPlayerHavePromotion(cid)
local currentVocation = getPlayerVocation(cid) - 4
local vocationPromoted = getPromotedVocation(currentVocation) - 4
return currentVocation == vocationPromoted;
end
function checkPlayerHaveItems(cid, message, keywords, parameters, node)
if (not npcHandler:isFocused(cid)) then
return false
end
if (config.minLevel ~= nil and getPlayerLevel(cid) < config.minLevel) then
npcHandler:say('You must reach level '..config.minLevel..' to buy promotion.', cid)
return true
end
if checkPlayerHavePromotion(cid) then
npcHandler:say('You are already promoted!', cid)
return true
end
if (not doPlayerRemoveItem(cid, config.itemID, config.quantity)) then
npcHandler:say('You do not have enough '..itemName..'!', cid)
return true
end
doPlayerSetVocation(cid, getPlayerVocation(cid) + 4)
npcHandler:say(parameters.text, cid)
return true
end
local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {
npcHandler = npcHandler,
onlyFocus = true,
text = "I can promote you for "..config.quantity.." {"..itemName.."}. Do you want me to promote you?"
})
node1:addChildKeyword({'yes'}, checkPlayerHaveItems, {
npcHandler = npcHandler,
text = "Congratulations! You are now promoted."
})
node1:addChildKeyword({'no'}, StdModule.say, {
npcHandler = npcHandler,
onlyFocus = true,
reset = true,
text = "Alright then, come back when you are ready."
})
npcHandler:addModule(FocusModule:new())
data > npc > NomeDoNPC.xml
<?xml version="1.0" encoding="UTF-8"?>
<npc name="NomeDoNPC" script="data/npc/scripts/NomeDoNPC.lua" walkinterval="2000" floorchange="0">
<health now="100" max="100"/>
<look type="160" head="77" body="79" legs="56" feet="115" addons="0"/>
</npc>