Nerevr back
Member
- Joined
- Nov 7, 2014
- Messages
- 269
- Reaction score
- 7
Hello guys please i need fast help with promotion npc if u knight can choose btween 2 vocation and if u mage same and if paladin same please if any one can help me
Mage > Druid or sorcere
Paladin > Archer or sniper
Knight > Warrior or Guardian
im use 0.4
i have this but don't work when say promotion don't give me anything
Mage > Druid or sorcere
Paladin > Archer or sniper
Knight > Warrior or Guardian
im use 0.4
i have this but don't work when say promotion don't give me anything
Code:
local vocations = {
[1] = {5},
[2] = {6},
[3] = {7},
[4] = {8, 9}
}
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 talkState, choose, text = {}, 0, ""
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE and 0 or cid
local v = getPlayerVocation(cid)
if msgcontains(msg, 'no') then
selfSay("Ok. Maybe next time.", cid)
npcHandler:resetNpc()
elseif msgcontains(msg, 'heal') then
local hp = getCreatureHealth(cid)
local pos = getCreaturePosition(cid)
if hp < 65 then
doCreatureAddHealth(cid, 65-hp)
doSendMagicEffect(pos, CONST_ME_MAGICBLUE)
doRemoveConditions(cid)
selfSay("Here you are.", cid)
else
selfSay("I cannot help you.", cid)
end
elseif msgcontains(msg, 'promotion') then
if isInArray(vocations, v) then
for i = 1, #vocations[v] do
text = text.. " {" ..getVocationInfo(vocations[v][i]).name.. "}"
if i < #vocations[v] then
text = text.. ","
end
end
selfSay("Young " ..getVocationInfo(v).name.. ". Hmm, which one you would like to be:" ..text.. ".", cid)
talkState[talkUser] = 1
else
selfSay("I can\'t promote you. Maybe you already have the highest promotion?", cid)
npcHandler:resetNpc()
end
end
if talkState[talkUser] == 1 then
for j = 1, #vocations[v] do
if msgcontains(msg, getVocationInfo(vocations[v][j]).name) then
choose = j
selfSay("You choosen a " ..getVocationInfo(vocations[v][j]).name.. ". This decision is IRREVERSIBLE. So, do you want to be a " ..getVocationInfo(vocations[v][j]).name.. "?", cid)
talkState[talkUser] = 2
else
selfSay("Don\'t waste my time.", cid)
npcHandler:resetNpc()
end
end
elseif talkState[talkUser] == 2 and msgcontains(msg, "yes") then
doPlayerSetVocation(cid, choose)
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGICBLUE)
selfSay("Congratulations! You have been promoted to " .. getVocationInfo(choose).name .. ".", cid)
npcHandler:resetNpc()
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())