Ir para conteúdo
  • Cadastre-se

(Resolvido)barqueiro com destino aleatorio


Ir para solução Resolvido por Vodkart,

Posts Recomendados

Bom dia, boa tarde, boa noite galera!

estou mais uma vez aqui pedindo a ajudar de vocês, dessa vez com um npc barqueiro que tenha uma chance aleatória

de levar o player para um destino x: 1746 y: 1218 z: 6, o qual não é possível ir normalmente a nao ser por essa "sorte" 

tipo no navio do global, agradeço muito se me ajudarem

esse é meu escript

 

Spoiler

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
local travelNode = keywordHandler:addKeyword({'baiak city'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Voce quer viajar para baiak city por 10k?'})
    travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 2, cost = 10000, destination = {x=119, y=51, z=6} })
    travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'I wouldn\'t go there either.'})

keywordHandler:addKeyword({'travel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Eu posso te levar para {baiak city}, {jugle sland}, {frozen sland}, {dwarven city} e {aslan city} por um pequeno custo.'})

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
local travelNode = keywordHandler:addKeyword({'jugle sland'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Voce quer viajar para jugle sland por 10k?'})
    travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 2, cost = 10000, destination = {x=143, y=170, z=6} })
    travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'I wouldn\'t go there either.'})

keywordHandler:addKeyword({'travel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to \'jugle sland\' for just a small fee.'})

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
local travelNode = keywordHandler:addKeyword({'frozen sland'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Voce quer viajar para frozen sland por 10k?'})
    travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 2, cost = 10000, destination = {x=307, y=136, z=6} })
    travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'I wouldn\'t go there either.'})

keywordHandler:addKeyword({'travel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to \'frozen sland\' for just a small fee.'})

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
local travelNode = keywordHandler:addKeyword({'dwarven city'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Voce quer viajar para dwarven city por 10k?'})
    travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 2, cost = 10000, destination = {x=235, y=512, z=6} })
    travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'I wouldn\'t go there either.'})

keywordHandler:addKeyword({'travel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to \'dwarven city\' for just a small fee.'})

-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
local travelNode = keywordHandler:addKeyword({'aslan city'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Voce quer viajar para aslan city por 10k?'})
    travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 2, cost = 10000, destination = {x=994, y=1029, z=6} })
    travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'I wouldn\'t go there either.'})

keywordHandler:addKeyword({'travel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to \'aslan city\' for just a small fee.'})


-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())

 

 

Link para o post
Compartilhar em outros sites
  • 2 weeks later...

Faz muito tempo que não programo lua, mas você pode usar algo parecido com isso

 

math.randomseed(0)
local function SORTEIO()
N = math.random()
return N
end
for I = 1, 5 do
    X = SORTEIO()
end

if X == 1 then
    caminho = 'x=119, y=51, z=6'
elseif X == 2 then
    caminho = 'x=143, y=170, z=6'
end


ai cada destino novo é só você adicionar um novo elseif e mudar as coordenadas da variavel caminho
Em seguida, subtitui os caminhos reais que devem ser aleatorios dentro do seu script, exclui os X= 109230912 Y= 21938123 Z = 12938912 pelo valor da variavel caminho

Link para o post
Compartilhar em outros sites
  • Solução

Data/NPC


Barqueiro John.xml

<?xml version="1.0"?>
<npc name="Barqueiro John" script="data/npc/scripts/johnb.lua" walkinterval="50000" floorchange="0">
<health now="100" max="100"/>
<look type="129" head="95" body="116" legs="121" feet="115" addons="3"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. You can {travel} with me!"/>
</parameters>
</npc>

 

Data/Npc/script

 
johnb.lua

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
function AddRandomTravel(cid, message, keywords, parameters, node) -- by vodka
  if(not npcHandler:isFocused(cid)) then
    return false
  end
  if (isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium == false) then
    if(parameters.level ~= nil and getPlayerLevel(cid) < parameters.level) then
      npcHandler:say('You must reach level ' .. parameters.level .. ' to travel.', cid)
    elseif not doPlayerRemoveMoney(cid, parameters.cost) then
      npcHandler:say('Sorry You need '..parameters.cost..' gps to travel!', cid)
    else
      local random = {x=1746, y=1218, z=6}
      local chance = 10 -- 10% de cair nessa ilha
      if chance <= math.random(1,100) then
        npcHandler:say('tchau, boa viagem!', cid)
        doTeleportThing(cid, parameters.destination)
      else
        npcHandler:say('parece que se perdemos por conta dos ventos, nao sei onde estamos!', cid)
        doTeleportThing(cid, random)
      end
      doSendMagicEffect(getPlayerPosition(cid), 10)
      npcHandler:resetNpc()
    end
  else
    npcHandler:say('I can only allow premium players to travel.', cid)
  end
  npcHandler:resetNpc()
  return true
end
local citys = {
  {"baiak city", cost = 10000, destination = {x=119, y=51, z=6}, level = 2, premium = true},
  {"jugle sland", cost = 10000, destination = {x=143, y=170, z=6}, level = 2, premium = true},
  {"frozen sland", cost = 10000, destination = {x=307, y=136, z=6}, level = 2, premium = true},
  {"dwarven city", cost = 10000, destination = {x=235, y=512, z=6}, level = 2, premium = true},
  {"aslan city", cost = 10000, destination = {x=994, y=1029, z=6}, level = 2, premium = true},
  {"travel", text = "Eu posso te levar para {baiak city}, {jugle sland}, {frozen sland}, {dwarven city} e {aslan city} por um pequeno custo!"}
}
for i = 1, #citys do local get = citys[i] if get.cost ~= nil and get.cost > 0 then
local node = keywordHandler:addKeyword({get[1]}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Voce quer viajar para " .. get[1] .. " por "..get.cost.." gps?"})
node:addChildKeyword({"yes"}, AddRandomTravel, {cost = get.cost, destination = get.destination, level = get.level, premium = get.premium})
node:addChildKeyword({"no"}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Ok, then.", reset = true})
else keywordHandler:addKeyword({get[1]}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = get.text}) end end
citys = nil npcHandler:addModule(FocusModule:new())

 

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Link para o post
Compartilhar em outros sites
Em 24/02/2022 em 13:29, Vodkart disse:

Data/NPC


Barqueiro John.xml



<?xml version="1.0"?>
<npc name="Barqueiro John" script="data/npc/scripts/johnb.lua" walkinterval="50000" floorchange="0">
<health now="100" max="100"/>
<look type="129" head="95" body="116" legs="121" feet="115" addons="3"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. You can {travel} with me!"/>
</parameters>
</npc>

 

Data/Npc/script

 
johnb.lua



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
function AddRandomTravel(cid, message, keywords, parameters, node) -- by vodka
  if(not npcHandler:isFocused(cid)) then
    return false
  end
  if (isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium == false) then
    if(parameters.level ~= nil and getPlayerLevel(cid) < parameters.level) then
      npcHandler:say('You must reach level ' .. parameters.level .. ' to travel.', cid)
    elseif not doPlayerRemoveMoney(cid, parameters.cost) then
      npcHandler:say('Sorry You need '..parameters.cost..' gps to travel!', cid)
    else
      local random = {x=1746, y=1218, z=6}
      local chance = 10 -- 10% de cair nessa ilha
      if chance >= math.random(1,100) then
        npcHandler:say('tchau, boa viagem!', cid)
        doTeleportThing(cid, parameters.destination)
      else
        npcHandler:say('parece que se perdemos por conta dos ventos, nao sei onde estamos!', cid)
        doTeleportThing(cid, random)
      end
      doSendMagicEffect(getPlayerPosition(cid), 10)
      npcHandler:resetNpc()
    end
  else
    npcHandler:say('I can only allow premium players to travel.', cid)
  end
  npcHandler:resetNpc()
  return true
end
local citys = {
  {"baiak city", cost = 10000, destination = {x=119, y=51, z=6}, level = 2, premium = true},
  {"jugle sland", cost = 10000, destination = {x=143, y=170, z=6}, level = 2, premium = true},
  {"frozen sland", cost = 10000, destination = {x=307, y=136, z=6}, level = 2, premium = true},
  {"dwarven city", cost = 10000, destination = {x=235, y=512, z=6}, level = 2, premium = true},
  {"aslan city", cost = 10000, destination = {x=994, y=1029, z=6}, level = 2, premium = true},
  {"travel", text = "Eu posso te levar para {baiak city}, {jugle sland}, {frozen sland}, {dwarven city} e {aslan city} por um pequeno custo!"}
}
for i = 1, #citys do local get = citys[i] if get.cost ~= nil and get.cost > 0 then
local node = keywordHandler:addKeyword({get[1]}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Voce quer viajar para " .. get[1] .. " por "..get.cost.." gps?"})
node:addChildKeyword({"yes"}, AddRandomTravel, {cost = get.cost, destination = get.destination, level = get.level, premium = get.premium})
node:addChildKeyword({"no"}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Ok, then.", reset = true})
else keywordHandler:addKeyword({get[1]}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = get.text}) end end
citys = nil npcHandler:addModule(FocusModule:new())

 

testei, mas ele so leva para o destino aleatorio

Editado por carloos (veja o histórico de edições)
Link para o post
Compartilhar em outros sites

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.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo