Postado Agosto 14, 2012 12 anos Este é um post popular. Bem venho postar esse script de um npc de vocations. local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid 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 function greetCallback(cid) talkState[talkUser] = 0 return true end function creatureSayCallback(cid, type, msg) local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if(not npcHandler:isFocused(cid)) then return false end local vocationsNameId = { {name = "Elder Druid", id = 5}, -- nome da vocação, id {name = "Master Sorcerer", id = 6} } local startstorageid = 30031 local msg = string.lower(msg) if getPlayerLevel(cid) < 20 then selfSay("You need level 20 to change vocation.", cid) npcHandler:onCreatureDisappear(cid) end if getPlayerStorageValue(cid, startstorageid) == 3 then selfSay("You has changed your vocation!", cid) npcHandler:onCreatureDisappear(cid) end if msgcontains(msg, 'yes') and talkState[talkUser] == nil or talkState[talkUser] == 0 then selfSay("You want to change your vocation?", cid) talkState[talkUser] = 2 elseif msgcontains(msg, 'no') and talkState[talkUser] == nil or talkState[talkUser] == 0 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then selfSay("Ok, you change to {"..(vocationsNameId[1].name).."} or {"..(vocationsNameId[2].name).."}?", cid) talkState[talkUser] = 3 elseif msgcontains(msg, 'no') and talkState[talkUser] == 2 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, string.lower(vocationsNameId[1].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[1].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 1) talkState[talkUser] = 4 elseif msgcontains(msg, string.lower(vocationsNameId[2].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[2].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 2) talkState[talkUser] = 4 elseif msgcontains(msg, 'yes') and talkState[talkUser] == 4 then doPlayerSetVocation(cid, vocationsNameId[getPlayerStorageValue(cid, startstorageid)].id) doSendMagicEffect(getCreaturePosition(cid), 29) setPlayerStorageValue(cid, startstorageid, 3) selfSay("Ok, you have changed this vocation to vocation {"..(vocationsNameId[getPlayerStorageValue(cid, startstorageid)].name).."}.", cid) talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, 'no') and talkState[talkUser] == 4 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Explicando: Vermelho:Mensagem quando o player trocar a vocation. Vermelho meio escuro:Mensagem quando o player escolher a vocation 2. Marrom:Mensagem quando o player escolher a vocation 2. Vermelho bem escuro:Mensagem quando o player falar hi, bem, à pergunta para dizer "yes". Amarelo escuro:level para trocar vocation e mensagem se não tiver level para trocar a vocation. Roxo:Storage que o player vai ficar (não mecha). Azul meio verde:Vocations que o player vai escolher. caso queria adicionar mais vocations faça o seguinte. Mude isso: local vocationsNameId = { {name = "Elder Druid", id = 5}, -- nome da vocação, id {name = "Master Sorcerer", id = 6} } Para isso: local vocationsNameId = { {name = "Elder Druid", id = 5}, -- nome da vocação, id {name = "Master Sorcerer", id = 6}, {name = "Elite Knight", id = 8} } E mude isso: if msgcontains(msg, 'yes') and talkState[talkUser] == nil or talkState[talkUser] == 0 then selfSay("You want to change your vocation?", cid) talkState[talkUser] = 2 elseif msgcontains(msg, 'no') and talkState[talkUser] == nil or talkState[talkUser] == 0 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then selfSay("Ok, you change to {"..(vocationsNameId[1].name).."} or {"..(vocationsNameId[2].name).."}?", cid) talkState[talkUser] = 3 elseif msgcontains(msg, 'no') and talkState[talkUser] == 2 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, string.lower(vocationsNameId[1].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[1].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 1) talkState[talkUser] = 4 elseif msgcontains(msg, string.lower(vocationsNameId[2].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[2].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 2) talkState[talkUser] = 4 elseif msgcontains(msg, 'yes') and talkState[talkUser] == 4 then doPlayerSetVocation(cid, vocationsNameId[getPlayerStorageValue(cid, startstorageid)].id) doSendMagicEffect(getCreaturePosition(cid), 29) setPlayerStorageValue(cid, startstorageid, 3) selfSay("Ok, you have changed this vocation to vocation {"..(vocationsNameId[getPlayerStorageValue(cid, startstorageid)].name).."}.", cid) talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, 'no') and talkState[talkUser] == 4 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) end Para isso: if msgcontains(msg, 'yes') and talkState[talkUser] == nil or talkState[talkUser] == 0 then selfSay("You want to change your vocation?", cid) talkState[talkUser] = 2 elseif msgcontains(msg, 'no') and talkState[talkUser] == nil or talkState[talkUser] == 0 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then selfSay("Ok, you change to {"..(vocationsNameId[1].name).."} or {"..(vocationsNameId[2].name).."}?", cid) talkState[talkUser] = 3 elseif msgcontains(msg, 'no') and talkState[talkUser] == 2 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, string.lower(vocationsNameId[1].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[1].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 1) talkState[talkUser] = 4 elseif msgcontains(msg, string.lower(vocationsNameId[2].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[2].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 2) talkState[talkUser] = 4 elseif msgcontains(msg, string.lower(vocationsNameId[3].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[3].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 3) talkState[talkUser] = 4 elseif msgcontains(msg, 'yes') and talkState[talkUser] == 4 then doPlayerSetVocation(cid, vocationsNameId[getPlayerStorageValue(cid, startstorageid)].id) doSendMagicEffect(getCreaturePosition(cid), 29) setPlayerStorageValue(cid, startstorageid, 4) selfSay("Ok, you have changed this vocation to vocation {"..(vocationsNameId[getPlayerStorageValue(cid, startstorageid)].name).."}.", cid) talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, 'no') and talkState[talkUser] == 4 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) end Pronto assim você acabou de adicionar a vocation elite knight no seu npc caso queira adicionar ainda mais faça o seguinte. Preste bem atenção: essa parte quando você for mudar para adicionar nova vocação você tem que prestar bem atenção na virgula. Correto: local vocationsNameId = { {name = "Elder Druid", id = 5}, -- nome da vocação, id {name = "Master Sorcerer", id = 6}, {name = "Elite Knight", id = 8}, {name = "Royal Paladin", id = 7}, (Comtém a virgula ,) } Errado: local vocationsNameId = { {name = "Elder Druid", id = 5}, -- nome da vocação, id {name = "Master Sorcerer", id = 6}, {name = "Elite Knight", id = 8}, {name = "Royal Paladin", id = 7} <<<(Não comtém a virgula ,) } E também quando for adicionar na hora de falar: Preste bem atenção na parte do storage id.(Irei deixar a parte maior para melhor visualização.) if msgcontains(msg, 'yes') and talkState[talkUser] == nil or talkState[talkUser] == 0 then selfSay("You want to change your vocation?", cid) talkState[talkUser] = 2 elseif msgcontains(msg, 'no') and talkState[talkUser] == nil or talkState[talkUser] == 0 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then selfSay("Ok, you change to {"..(vocationsNameId[1].name).."} or {"..(vocationsNameId[2].name).."}?", cid) talkState[talkUser] = 3 elseif msgcontains(msg, 'no') and talkState[talkUser] == 2 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, string.lower(vocationsNameId[1].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[1].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 1) talkState[talkUser] = 4 elseif msgcontains(msg, string.lower(vocationsNameId[2].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[2].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 2) talkState[talkUser] = 4 elseif msgcontains(msg, string.lower(vocationsNameId[3].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[3].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 3) talkState[talkUser] = 4 elseif msgcontains(msg, string.lower(vocationsNameId[4].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[4].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 4 [aqui você sim meche, está 4 por que mudei para adicionar o royal paladin, mas quando você adicionar uma nova vocação você sempre adiciona +1 na storage ex: está 4, você quer colocar epic royal paladin, então deixe 5, mas la em baixo \/ (vamos pular para lá) ) talkState[talkUser] = 4 [aqui você deixa 4 mesmo para ficar na mesma função de mensagem de quando seleciona a vocation.] elseif msgcontains(msg, 'yes') and talkState[talkUser] == 4 then doPlayerSetVocation(cid, vocationsNameId[getPlayerStorageValue(cid, startstorageid)].id) doSendMagicEffect(getCreaturePosition(cid), 29) setPlayerStorageValue(cid, startstorageid, 5 (aqui você tem que adicionar mais 1 também assim deixando essa parte como ultima storage se você não mudar o script pode não funcionar como planejado, se você está com 4 vocações coloque aqui como 5 se estiver com 8 vocações coloque aqui como 9, se estiver com 6 vocações coloque aqui como 7 e assim por diante.) [/b] [b]essa parte você não meche mais por que já está tudo configurado.[/b] [b]selfSay("Ok, you have changed this vocation to vocation {"..(vocationsNameId[getPlayerStorageValue(cid, startstorageid)].name).."}.", cid) talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, 'no') and talkState[talkUser] == 4 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) end[/b] [b] Agora é só por seu npc configurado no seu servidor e se divertir . Obrigado pela atenção de todos, sigam o tutorial para adicionar novas vocações sempre em , caso queria que só certas vocações possam trocar a vocação usem esse outro script local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid 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 function greetCallback(cid) talkState[talkUser] = 0 return true end function creatureSayCallback(cid, type, msg) local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if(not npcHandler:isFocused(cid)) then return false end local vocationsNameId = { {name = "Elder Druid", id = 5}, -- nome da vocação, id {name = "Master Sorcerer", id = 6} } local vocationNeed = {1,2,3} -- id da vocação que precisa estar. local startstorageid = 30031 local msg = string.lower(msg) if getPlayerLevel(cid) < 20 then selfSay("You need level 20 to change vocation.", cid) npcHandler:onCreatureDisappear(cid) end if not isInArray(vocationNeed, getPlayerVocation(cid)) then selfSay("You can not change his vocation here!", cid) npcHandler:onCreatureDisappear(cid) end if getPlayerStorageValue(cid, startstorageid) == 3 then selfSay("You has changed your vocation!", cid) npcHandler:onCreatureDisappear(cid) end if msgcontains(msg, 'yes') and talkState[talkUser] == nil or talkState[talkUser] == 0 then selfSay("You want to change your vocation?", cid) talkState[talkUser] = 2 elseif msgcontains(msg, 'no') and talkState[talkUser] == nil or talkState[talkUser] == 0 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then selfSay("Ok, you change to {"..(vocationsNameId[1].name).."} or {"..(vocationsNameId[2].name).."}?", cid) talkState[talkUser] = 3 elseif msgcontains(msg, 'no') and talkState[talkUser] == 2 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, string.lower(vocationsNameId[1].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[1].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 1) talkState[talkUser] = 4 elseif msgcontains(msg, string.lower(vocationsNameId[2].name)) and talkState[talkUser] == 3 then selfSay("You want to change your vocation to {"..(vocationsNameId[2].name).."}?", cid) setPlayerStorageValue(cid, startstorageid, 2) talkState[talkUser] = 4 elseif msgcontains(msg, 'yes') and talkState[talkUser] == 4 then doPlayerSetVocation(cid, vocationsNameId[getPlayerStorageValue(cid, startstorageid)].id) doSendMagicEffect(getCreaturePosition(cid), 29) setPlayerStorageValue(cid, startstorageid, 3) selfSay("Ok, you have changed this vocation to vocation {"..(vocationsNameId[getPlayerStorageValue(cid, startstorageid)].name).."}.", cid) talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) elseif msgcontains(msg, 'no') and talkState[talkUser] == 4 then talkState[talkUser] = 0 npcHandler:onCreatureDisappear(cid) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Esse script /\ está apenas configurado para elder druid e master sorcerer se quiser adicionar mais siga o tutorial acima. Só isso galera. Ae ajudei? Rep+
Postado Agosto 15, 2012 12 anos bem legal, útil para Ot's, que por exemplo: tenha um sistema de se transformar em certa vocation para poder usar tal spell, ou item, ou como um avanço na "raça" de teu personagem ;x bem explicado rep+
Postado Janeiro 9, 2013 12 anos Aonde eu adiciono isso?? Se me falar dou rep + Amigo o primeiro script deve ficar em, data/npc/ Crie um arquivo .xml dentro dessa pasta e adicione o code informado, depois é só testar. www.patronum.online
Postado Janeiro 23, 2017 8 anos Oi, foi mal ressucitar o post, mas no caso, se eu quiser que só promova se já tiver x vocation, no caso druid só se promover pra elder druid, e assim em diante, como faz? Porque testei o script, e se eu for druid posso trocar pra sorc :x #Edit Consegui resolver, achei um script aqui no fórum e alterei para ficar "perfeito", no caso do meu script, o npc pede a quantidade de money configurada no script, e x item (configurável e você pode remover também) Caso queira, basta criar um novo npc para sorcerer e assim vai, e se tiver um conhecimento maior de script basta adicionar mais linhas aí no mesmo script que vai servir para todas as vocs (sim esse npc aí só da promotion pra druids, pois no meu server eu separei a promotion entre quatro npcs.) Ah, eu testei esse script em TFS 1.2 (10.98), acredito que ele só sirva pra 1.0 + Script : Citar 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 function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid local prom = getPlayerVocation(cid) local lvl = getPlayerLevel(cid) local money = getPlayerMoney(cid) if(msgcontains(msg, 'promotion')) then -- aqui no caso é a promotion normal, mas se você quiser alterar para ser a segunda, e deixar o npc normal dando a primeira, e criar um novo npc pra segunda, que no caso é este selfSay('I can sell you the first promotion (elder druid), you will want?', cid) talkState[talkUser] = 1 elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then if (lvl >= 20) and (prom == 2) and (money >= 10000) and getPlayerItemCount(cid, 12399, 30) then doPlayerSetVocation(cid, 6) -- Id da promotion antiga, elder druid doPlayerRemoveMoney(cid, 10000) doPlayerRemoveItem(cid, 12399, 30) doSendMagicEffect(getThingPos(cid), CONST_ME_GIFT_WRAPS) selfSay('Now you are Elder Druid.', cid) talkState[talkUser] = 0 else selfSay('You don\'t have the right level, previous promotion, or money.', cid) talkState[talkUser] = 0 end elseif(msgcontains(msg, 'shamanic')) then -- nome da segunda promotion selfSay('I can give you the second promotion (shamanic apprentice), you will want?', cid) talkState[talkUser] = 2 elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then if (lvl >= 150) and (prom == 6) and (money >= 100000) and getPlayerItemCount(cid, 11199, 100) then doPlayerSetVocation(cid, 10) -- Id da nova promotion, caso o player tenha a anterior, que é a 6 (elder druid) no meu caso doPlayerRemoveMoney(cid, 100000) doPlayerRemoveItem(cid, 11199, 100) doSendMagicEffect(getThingPos(cid), CONST_ME_GIFT_WRAPS) selfSay('Now you are Elder Druid (Shamanic).', cid) talkState[talkUser] = 0 else selfSay('You don\'t have the right level, previous promotion, money, or items.', cid) talkState[talkUser] = 0 end end return true end keywordHandler:addKeyword({"promote"}, StdModule.say, {npcHandler = npcHandler, text = "I can promote the adventurers with the vocation of druid, the vocations available are Elder Druid per {10.000 gps} and {30} {girlish hair decoration}. And Elder Druid Shamanic (apprentice) per {100.000 gps} and {100 hydra head}."}) keywordHandler:addKeyword({"help"}, StdModule.say, {npcHandler = npcHandler, text = "The Elder Druid promotion, gives you over 100 soul points, plus your life/mana regeneration go up more fast, Elder Druids have more endurance and unique spells. Just like Shamanic, who has unique spells for promotion (you can see when it's promoted), your soul points will increase to 300 when you promote to the Shamanic.."}) npcHandler:setMessage(MESSAGE_GREET, "Hello brave adventurer, are you missed on this side of the continent? It is not common to find warriors here. Do you want to {promote} your vocation? Or {Help}?") npcHandler:setMessage(MESSAGE_FAREWELL, "Goodbye |PLAYERNAME|") npcHandler:setMessage(MESSAGE_WALKAWAY, "Goodbye |PLAYERNAME|") npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Editado Janeiro 24, 2017 8 anos por Eduardo Dantas Solucionado o problema. (veja o histórico de edições)
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.