Jump to content

math.random npc


Recommended Posts

Posted (edited)

Olá como sabem eu sou novo , ando criando algumas coisas simples e aprendendo a cada dia, eu estou com um pouco de dificuldade em um script meu que estou desenvolvendo

Eu criei um ped por tabela assim gerando em lugares diferentes, agora que a cereja do bolo vem, como faço para que em 5 em 5 minutos ele possar gerar o npc em lugares diferentes dessa tabela

 

local NPCS = {
    pos = {
        -- POSIÇÂO DO NPC = x,y,z
        {2164.52686, -1000.97644, 62.79298},
        {2199.82104, -1010.65930, 61.88739}
    },

}

local npcPos = NPCS.pos[math.random(#NPCS.pos)]
local NPC2x,NPC2y,NPC2z = npcPos[1], npcPos[2], npcPos[3]
local Ped_VICIADO = createPed(240, NPC2x,NPC2y,NPC2z)

 

Edited by LucasMTA
  • Moderators
Posted

Não entendi a necessidade de uma sub-tabela dentro da tabela NPCs.

Pq vc simplesmente não fez 1 tabela de posições?

E também pelo que vejo, vc ainda não está tentando fazer nada com setTimer.

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanks! spacer.png

Minhas contribuições para a comunidade: LordHenry - MTA Wiki Profile
Inscreva-se no meu canal do YouTube: Lord Henry - Entertainment
Discord Oficial do MTA: https://mtasa.com/discord
Blacklist e Whitelist de Scripters: Planilha

Por favor, não me envie mensagens privadas solicitando suporte. Crie um tópico no fórum em vez disso.

Posted
NPCS = {
    -- POSIÇÂO DO NPC = x,y,z
    {2164.52686, -1000.97644, 62.79298},
    {2199.82104, -1010.65930, 61.88739}
},

local r = math.random(1, #NPCS)
local Ped_VICIADO = createPed(240, NPCS[r][1], NPCS[r][2], NPCS[r][3])

timer = setTimer(function()
    if Ped_VICIADO then
        local nr = math.random(1, #NPCS)
        setElementPosition(Ped_VICIADO, NPCS[nr][1], NPCS[nr][2], NPCS[nr][3])
    end
end, 300000, 0)

EDIT: Não testei!

? DID I HELP YOU? 

Tsd6e1t.png

________________________________________________________________________

ム MY STEAM

76561198321211115.png

________________________________________________________________________

? MY SITE

cGejgxz.png

www.tommy.br.com

Posted (edited)

Pra longos periodos assim é válido declarar uma variável pra controlar o timer, assim é mais fácil e rápido de fazer alterações sem precisar calcular x segundos.

Exemplo:

NPCS = {
      {2164.52686, -1000.97644, 62.79298}, --  x, y, z
      {2199.82104, -1010.65930, 61.88739}
},

local r = math.random(1, #NPCS)
local Ped_VICIADO = createPed(240, NPCS[r][1], NPCS[r][2], NPCS[r][3])
local timerTotal = 5

timer = setTimer(function ()
	if Ped_VICIADO then
		local nr = math.random(1, #NPCS)
		setElementPosition(Ped_VICIADO, NPCS[nr][1], NPCS[nr][2], NPCS[nr][3])
	end
end, 60000 * timerTotal, 0) -- 60000 = 1 minuto x var timerTotal = 5 minutos.

 

Edited by Jonas^
Posted (edited)
Position = {
{1,0,0}, -- CORD DE EXP
{2,0,0}, -- CORD DE EXP
{3,0,0}, -- CORD DE EXP
{4,0,0}, -- CORD DE EXP
{5,0,0}, -- CORD DE EXP
}

function getRandomPosition ()
local Cord = Position[ math.random( #Position )]
return Cord[1],Cord[2],Cord[3] end


local x,y,z = getRandomPosition()

 

Edited by brunob22

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...