Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 cfg = {
- kicktime = 3, -- Tempo para Kickar o Player / Em Segundos
- vocations = {
- ["druid"] = {
- level = 30, -- Level Mínimo
- voc = { -- Possíveis Promoções
- {name = 'sanders druid', id = 6},
- },
- price = { -- Preço
- {id = 2152, amount = 100},
- {id = 2160, amount = 1},
- },
- },
- -- [[ New Vocation Below ]] --
- ["sorcerer"] = {
- level = 30, -- Level Mínimo
- voc = { -- Possíveis Promoções
- {name = 'crowler sorcerer', id = 5},
- },
- price = { -- Preço
- {id = 2152, amount = 100},
- {id = 2160, amount = 1},
- },
- },
- ["paladin"] = {
- level = 30, -- Level Mínimo
- voc = { -- Possíveis Promoções
- {name = 'Drizzt Paladin', id = 7},
- },
- price = { -- Preço
- {id = 2152, amount = 100},
- {id = 2160, amount = 1},
- },
- },
- ["knight"] = {
- level = 30, -- Level Mínimo
- voc = { -- Possíveis Promoções
- {name = 'Beowulf Knight', id = 8},
- },
- price = { -- Preço
- {id = 2152, amount = 100},
- {id = 2160, amount = 1},
- },
- },
- },
- }
- function creatureSayCallback(cid, type, msg)
- if(not npcHandler:isFocused(cid)) then
- return false
- end
- if msgcontains(msg, 'promote') or msgcontains(msg, 'promo') or msgcontains(msg, 'promotion') and talk_state == 0 then
- getVocation = getPlayerVocationName(cid):lower()
- get = vocations[getVocation]
- if get then
- if getPlayerLevel(cid) >= get.level then
- str = getTextPromoVocations(get.voc)
- npcHandler:say('Alright, you can choose this vocation(s): '..str..'.', cid)
- talk_state = 1
- else
- npcHandler:say('Sorry, but you need level '..get.level..' to be promoted.', cid)
- talk_state = 0
- return true
- end
- else
- npcHandler:say('Sorry, but I don\'t have nothing more for your vocation.', cid)
- talk_state = 0
- return true
- end
- elseif talk_state == 1 then
- get = cfg[getVocation]
- if get then
- ctrl = 0
- svocId = 0
- for b = 1, #get.voc do
- g = get.voc[b].name:lower()
- if msg:lower() == g then
- ctrl = ctrl + 1
- svocId = get.voc[b].id
- end
- end
- if ctrl > 0 then
- items = getItemsPromoVocations(get.price)
- npcHandler:say('Alright, you need pay: '..items..' to continue, you have this items?', cid)
- talk_state = 2
- else
- npcHandler:say('Vocation not founded, try choose again: '..str..'.', cid)
- talk_state = 1
- return true
- end
- else
- npcHandler:say('Sorry, but some error have occurred with your vocation, please contact to administrator.', cid)
- talk_state = 0
- end
- elseif talk_state == 2 then
- if msgcontains(msg, 'yes') then
- c = 0
- for j = 1, #get.price do
- if getPlayerItemCount(cid, get.price[j].id) >= get.price[j].amount then
- c = c + 1
- else
- if get.price[j].amount > 1 then name = getItemPluralNameById else name = getItemNameById end
- npcHandler:say('Sorry, but you DON\'T have {'..get.price[j].amount..'x '..name(get.price[j].id)..'}.', cid)
- talk_state = 0
- break
- end
- end
- if c == #get.price then
- npcHandler:say('Well, well, you have been PROMOTED and will be kicked in 3 seconds.', cid)
- doNewPromoteThing(cid, get.price, svocId)
- talk_state = 0
- end
- end
- elseif msgcontains(msg, 'no') then
- npcHandler:say('Well, then leave.', cid)
- talk_state = 0
- end
- return true
- end
- function getTextPromoVocations(vocs)
- text = ''
- for i = 1, #vocs do
- if #vocs == 1 or i == 1 then
- text = '{'..vocs[i].name..'}'
- elseif #vocs > 1 and i == #vocs then
- text = ''..text..' and {'..vocs[i].name..'}'
- else
- text = ''..text..', {'..vocs[i].name..'}'
- end
- end
- return text
- end
- function getItemsPromoVocations(list)
- items = ''
- for i = 1, #list do
- if list[i].amount > 1 then name = getItemPluralNameById else name = getItemNameById end
- if #list == 1 or i == 1 then
- items = '{'..list[i].amount..'x '..name(list[i].id)..'}'
- elseif #list > 1 and i == #list then
- items = ''..items..' and {'..list[i].amount..'x '..name(list[i].id)..'}'
- else
- items = ''..items..', {'..list[i].amount..'x '..name(list[i].id)..'}'
- end
- end
- return items
- end
- function doNewPromoteThing(cid, list, vocid)
- for k = 1, #list do
- doPlayerRemoveItem(cid, list[k].id, list[k].amount)
- end
- doPlayerSetVocation(cid, vocid)
- addEvent(doRemoveCreature, cfg.kicktime * 1000, cid)
- return true
- end
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement