
Nego Tchuca
Membro
-
Registro em
-
Última visita
Histórico de Curtidas
-
Nego Tchuca deu reputação a MatteusDeli em Conexão de MOD Reputation com NPC@Nego Tchuca Boa tarde, eu testei em um servidor 8.6 com tfs 0.4, acho que vai funcionar no seu.
1° Vá em data/lib e crie um arquivo chamado rep_seller_items.lua e adicione isto dentro: (as configurações estão comentadas nele)
-- Caso a coluna "REP" da tabela de players for diferente coloque o nome dela aqui rep_coluna_database = "rep" -- As falas do npc rep_falas_npc = { conversa = { ['trocar'] = 'Veja nossa {lista de items} e confira quantos reps cada um vale.', ['lista_de_items'] = 'Agora, me diga o nome do item que voce quer trocar.', }, sucesso = { ['item_comprado'] = 'Otimo, aqui esta o seu novo item.', }, falha = { ['rep_points_insuficientes'] = 'Desculpe, mais voce nao possui rep points suficientes para trocar por este item.', ['item_nao_encontrado'] = 'Nao encontrei este item, por favor tente outro.' } } -- Items que o npc irá vender rep_items = { { item_id = 2124, quantidade_rep_points = 5}, { item_id = 2472, quantidade_rep_points = 30}, { item_id = 2520, quantidade_rep_points = 10}, }
2° Vá na pasta dos npcs em data/npc e crie um arquivo chamado Rep.xml e adicione isto nele:
<npc name="Rep" script="data/npc/scripts/repseller.lua" floorchange="0" access="5"> <health now="150" max="150"/> <look type="143" head="2" body="112" legs="78" feet="116" addons="2" corpse="2212"/> <parameters> <parameter key="message_greet" value="Ola! Voce posso {trocar} seus rep points por itens."/> </parameters></npc>
3° Agora crie um arquivo de script chamado repseller.lua na pasta data/npc/scripts e adicione isto nele:
dofile(getDataDir() .. "lib/rep_seller_items.lua") 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) local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if(not npcHandler:isFocused(cid)) then return false end if msgcontains(msg, 'trocar') then npcHandler:say(rep_falas_npc.conversa.trocar, cid) talkState[talkUser] = 1 end if msgcontains(msg, 'lista de items') and talkState[talkUser] == 1 then mostrarListaItems(cid) npcHandler:say(rep_falas_npc.conversa.lista_de_items, cid) talkState[talkUser] = 2 end if talkState[talkUser] == 2 then local item = buscarItemPeloNome(msg) if item == nil then return; end trocarRepPointsPeloItem(cid, item) talkState[talkUser] = 1 end return TRUE end function trocarRepPointsPeloItem(cid, item) local playerRepPoints = buscarRepPoints(cid) if item.quantidade_rep_points > playerRepPoints then npcHandler:say(rep_falas_npc.falha.rep_points_insuficientes, cid) return; end local quantidadeRepPointsParaRemover = playerRepPoints - item.quantidade_rep_points if quantidadeRepPointsParaRemover < 0 then npcHandler:say(rep_falas_npc.falha.rep_points_insuficientes, cid) return; end if removerRepPoints(cid, quantidadeRepPointsParaRemover) then adicionarItemAoPlayer(cid, item) npcHandler:say(rep_falas_npc.sucesso.item_comprado, cid) end end function buscarRepPoints(cid) local sql = "SELECT `"..rep_coluna_database.."` FROM `players` WHERE id = " ..getPlayerGUID(cid)..";" local result = db.getResult(sql) if result:getID() <= -1 then return; end return result:getDataInt(rep_coluna_database) end function removerRepPoints(cid, quantidade) local sql = "UPDATE `players` SET `"..rep_coluna_database.."` = "..quantidade.." WHERE id = "..getPlayerGUID(cid)..";" local result = db.executeQuery(sql) if result == -1 then return false end return true end function mostrarListaItems(cid) local message = '' for index = 1, #rep_items, 1 do local item = rep_items[index] local item_nome = getItemNameById(item.item_id) message = item_nome .. " - " .. item.quantidade_rep_points .. " REP Point(s)" .. "\n" .. message end doPlayerPopupFYI(cid, message) end function adicionarItemAoPlayer(cid, item) doPlayerAddItem(cid, item.item_id) end function buscarItemPeloNome(nome) for index = 1, #rep_items, 1 do local item = rep_items[index] local item_nome = getItemNameById(item.item_id) if (string.lower(nome) == string.lower(item_nome)) then return item end end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new())
Espero ter ajudado