Postado Dezembro 3, 2014 10 anos olá, alguém consegue fazer um npc, que muda a vocação do player se ele tiver uma storage, e dará uma nova storage para o player. Ele também resetará o level, a vida e a mana do player deixando apenas as skills que ele tinha.
Postado Dezembro 3, 2014 10 anos vchanger.lua (data/npc/scripts): local tab = { voc = 5, -- newVocationID dctime = 5, -- segundos para desconectar o player stats = {1, 150, 5}, -- {newLevel, newHealth, newMana} novo level/hp/mana ao trocar a voc oldstor = {5432, 1}, -- {storage, value) <- necessários newstor = {6543, 2} -- {storage, value) <- que o player receberá } 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 function changeVoc(cid) local playerid, mh, mm = getPlayerGUID(cid), getCreatureMaxHealth(cid), getCreatureMaxMana(cid) if(npcHandler:isFocused(cid)) then npcHandler:releaseFocus(cid) end setCreatureMaxHealth(cid, tab.stats[2]) doCreatureAddHealth(cid, -(tab.stats[2] - mh)) setCreatureMaxMana(cid, tab.stats[3]) doCreatureAddMana(cid, -(tab.stats[3] - mm)) doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid))) doRemoveCreature(cid) db.executeQuery("UPDATE `players` SET `level`="..tab.stats[1]..",`experience`= 0 WHERE `players`.`id`= "..playerid.."") return true end if (msgcontains(msg, 'change')) then if (getPlayerStorageValue(cid, tab.oldstor[1]) == tab.oldstor[2]) then talkState[talkUser] = 1 selfSay('If you choose to change your vocation, your level, health and mana will return as a level '..tab.stats[1]..'..', cid) selfSay('Are you sure you want this?', cid) else talkState[talkUser] = 0 npcHandler:releaseFocus(cid) selfSay('I can not change your vocation. You are already a '..getPlayerVocationName(cid)..'!', cid) end elseif (msgcontains(msg, 'yes') and talkState[talkUser] == 1) then doPlayerSetVocation(cid, tab.voc) setPlayerStorageValue(cid, tab.oldstor[1], -1) setPlayerStorageValue(cid, tab.newstor[1], tab.newstor[2]) doSendMagicEffect(getThingPos(cid), CONST_ME_STUN) addEvent(function() if isPlayer(cid) then changeVoc(cid) end end, tab.dctime * 1000) talkState[talkUser] = 0 npcHandler:releaseFocus(cid) selfSay('Okay, now you will pass out and I will send you to the temple of your town in '..tab.dctime..' seconds.', cid) elseif (msgcontains(msg, 'no') and talkState[talkUser] == 1) then talkState[talkUser] = 0 npcHandler:releaseFocus(cid) selfSay('Sure, goodbye!', cid) end return true end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Vocation Changer.xml (data/npc): <npc name="Vocation Changer" script="data/npc/scripts/vchanger.lua" access="5" lookdir="1"> <health now="1000" max="1000"/> <look type="154" head="114" body="114" legs="113" feet="113" addons="3"/> <parameters> <parameter key="message_greet" value="Hello |PLAYERNAME|. I {change} the vocation of some mortals in special." /> </parameters> </npc> Editado Dezembro 5, 2014 10 anos por Suicide (veja o histórico de edições) The corrupt fear us. The honest support us. The heroic join us.
Postado Dezembro 4, 2014 10 anos Autor deu erro e ele n apareceu [Error - LuaScriptInterface::loadFile] data/npc/scripts/vchanger.lua:6: '}' expected near ')' [03/12/2014 23:34:20] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/vchanger.lua [03/12/2014 23:34:20] data/npc/scripts/vchanger.lua:6: '}' expected near ')'
Postado Dezembro 4, 2014 10 anos deu erro e ele n apareceu Alterei algumas funções do script e resolvi esse erro de atenção, post atualizado. Editado Dezembro 4, 2014 10 anos por Suicide (veja o histórico de edições) The corrupt fear us. The honest support us. The heroic join us.
Postado Dezembro 5, 2014 10 anos Autor deu erro novamente. Se eu não possuir a storage, o npc diz 'i can not change your vocation' (algo assim) se eu possuir a storage, ele não fala nada e aparece essa erro na distro [05/12/2014 01:45:35] [Error - Npc interface] [05/12/2014 01:45:35] data/npc/scripts/vchanger.lua:onCreatureSay [05/12/2014 01:45:35] Description: [05/12/2014 01:45:35] data/npc/scripts/vchanger.lua:45: attempt to compare number with string [05/12/2014 01:45:35] stack traceback: [05/12/2014 01:45:35] data/npc/scripts/vchanger.lua:45: in function 'callback' [05/12/2014 01:45:35] data/npc/lib/npcsystem/npchandler.lua:390: in function 'onCreatureSay' [05/12/2014 01:45:35] data/npc/scripts/vchanger.lua:16: in function <data/npc/scripts/vchanger.lua:16>
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.