Jump to content

Ajuda aki


Recommended Posts

Posted (edited)

Olá, testei esta função porem queria que tivesse um spanw do veh aleatório para evitar bug de vehicles  se 2 players tetamcem fazer a missão ao mesmo tempo poderiam me ajudar ?

Mfim4 = createMarker ( -1875.0139160156, -1474.5141601563, 1 -1, "ring", 4, 0 ,255 ,0, 255)

Bfim4 = createBlipAttachedTo ( Mfim4, 20 )
setElementVisibleTo ( Bfim4, root, false )

veh4 = {}

localitionveh = {
{493, -615.03826904297, 1807.0825195313, 0.19021162390709, 0, 0, 76.391845703125},
{493, -2375.00317, 1741.60583, 0.36448, 0, 0, 76.391845703125},
{493, -2297.87598, 1644.67639, 0.61662, 0, 0, 76.391845703125},
{493, -2280.10376, 1577.25720, -0.03525, 0, 0, 76.391845703125},
{493, -2208.14648, 1486.88440, 0.68383, 0, 0, 76.391845703125},
}

function inicio4 ()
	if isElement (veh4[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh4[client])
		veh4[client] = nil
	end
	Trabalho = true
	veh4[client] = localitionveh
	setElementVisibleTo ( Bfim4, client, true )
	warpPedIntoVehicle (client, veh4[client])
	outputChatBox ("#ffff00Take this Flag Card without leaving the vehicle!", client, 0, 0, 0, true)
end
addEvent ("iniciaJob4", true) -- Cria o evento "iniciaJob e permite que ele seja chamado pelo client.
addEventHandler ("iniciaJob4", getRootElement(), inicio4) -- Executa essa função quando o evento "iniciaJob" for chamado

 

Edited by kevincouto6
Posted (edited)
local i = math.random( #localitionveh )
local vx vy, vz, vrot = localitionveh[ i ][ 2 ], localitionveh[ i ][ 3 ], localitionveh[ i ][ 4 ], localitionveh[ i ][ 7 ]

veh4[client] = createVehicle ( vehicleID, vx, vy, vz, 0, 0, vrot )

Use um nome apropriado pro tópico da próxima vez, por favor.

Edited by DNL291

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
On 01/06/2018 at 22:02, DNL291 said:

local i = math.random( #localitionveh )
local vx vy, vz, vrot = localitionveh[ i ][ 2 ], localitionveh[ i ][ 3 ], localitionveh[ i ][ 4 ], localitionveh[ i ][ 7 ]

veh4[client] = createVehicle ( vehicleID, vx, vy, vz, 0, 0, vrot )

Use um nome apropriado pro tópico da próxima vez, por favor.

Hey, Alguem poderia me ajudar, eu usei o fomarta que voçe me falou porem os veh ainda continuam a sair no mesmo local

Mfim = createMarker (-1828.72888, -1627.62219, 23.23001 -1, "cylinder", 2, 0 ,255 ,0, 255)

Bfim = createBlipAttachedTo ( Mfim, 19 )
setElementVisibleTo ( Bfim, root, false )

veh = {}

localitionveh = {
	{493, -615.03826904297, 1807.0825195313, 0.19021162390709, 0, 0, 76.391845703125},
	{493, -2375.00317, 1741.60583, 0.36448, 0, 0, 76.391845703125},
	{493, -2297.87598, 1644.67639, 0.61662, 0, 0, 76.391845703125},
	{493, -2280.10376, 1577.25720, -0.03525, 0, 0, 76.391845703125},
	{493, -2208.14648, 1486.88440, 0.68383, 0, 0, 76.391845703125},
}

function inicio ()
	if isElement (veh[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh[client])
		veh[client] = nil
	end
	
	local i = math.random( #localitionveh )
	local vx vy, vz, vrot = localitionveh[ i ][ 2 ], localitionveh[ i ][ 3 ], localitionveh[ i ][ 4 ], localitionveh[ i ][ 7 ]
	
	Trabalho = true
	veh4[client] = createVehicle ( 514, vx, vy, vz, 0, 0, vrot )
	setElementVisibleTo (Bfim, client, true)
	warpPedIntoVehicle (client, veh[client])
	outputChatBox ("#ffff00Take this Flag Card without leaving the vehicle!", client, 0, 0, 0, true)
	
	local player1 = client
	addEventHandler ( "onVehicleExplode", veh[client], function ()
		if (veh[player1]) and isElement(veh[player1]) then
			destroyElement (source)
			setElementVisibleTo ( Bfim, player1, false )
			outputChatBox("Mission failled, your vehicle blow.", player1 , 255, 0, 0)
		end
	end)
end
addEvent ("iniciaJob", true) -- Cria o evento "iniciaJob e permite que ele seja chamado pelo client.
addEventHandler ("iniciaJob", getRootElement(), inicio) -- Executa essa função quando o evento "iniciaJob" for chamado.

 

  • Moderators
Posted (edited)

Aleatório não vai funcionar, ele tem grandes chances de repetir a mesma posição.

Indexe a tabela das posições e use um contador incremental de 1 até #localitionveh, a posição a ser usada deve ser localitionveh[contador] e sempre que ele for usado, aumentará em +1, dessa forma a próxima vez que for usado, usará a posição seguinte da tabela sem chances de repetir.

Quando o contador ficar maior que o tamanho da tabela (5), volta a 1 e reinicia o ciclo.

Mfim = createMarker (-1828.72888, -1627.62219, 23.23001 -1, "cylinder", 2, 0 ,255 ,0, 255)

Bfim = createBlipAttachedTo ( Mfim, 19 )
setElementVisibleTo ( Bfim, root, false )

veh = {}

 -- Recomendo que evite posições decimais muito grandes. Use só até 3 casas decimais.
localitionveh = {
	[1] = {493, -615.03826904297, 1807.0825195313, 0.19021162390709, 0, 0, 76.391845703125},
	[2] = {493, -2375.00317, 1741.60583, 0.36448, 0, 0, 76.391845703125},
	[3] = {493, -2297.87598, 1644.67639, 0.61662, 0, 0, 76.391845703125},
	[4] = {493, -2280.10376, 1577.25720, -0.03525, 0, 0, 76.391845703125},
	[5] = {493, -2208.14648, 1486.88440, 0.68383, 0, 0, 76.391845703125},
 -- O primeiro, quinto e sexto valor das posições não estão sendo usados. Recomendo que delete-os.
}

i = 1 -- contador global

function inicio ()
	if isElement (veh[client]) then -- Client = localPlayer, somente neste caso.
		destroyElement (veh[client])
		veh[client] = nil
	end
	local vx vy, vz, vrot = localitionveh[ i ][ 2 ], localitionveh[ i ][ 3 ], localitionveh[ i ][ 4 ], localitionveh[ i ][ 7 ]
	i = i + 1
	if i > #localitionveh then -- se i > 5, então:
		i = 1
	end
	Trabalho = true
	veh4[client] = createVehicle ( 514, vx, vy, vz, 0, 0, vrot )
	setElementVisibleTo (Bfim, client, true)
	warpPedIntoVehicle (client, veh[client])
	outputChatBox ("#ffff00Take this Flag Card without leaving the vehicle!", client, 0, 0, 0, true)
	
	local player1 = client
	addEventHandler ( "onVehicleExplode", veh[client], function ()
		if (veh[player1]) and isElement(veh[player1]) then
			destroyElement (source)
			setElementVisibleTo ( Bfim, player1, false )
			outputChatBox("Mission failled, your vehicle blow.", player1 , 255, 0, 0)
		end
	end)
end
addEvent ("iniciaJob", true) -- Cria o evento "iniciaJob e permite que ele seja chamado pelo client.
addEventHandler ("iniciaJob", getRootElement(), inicio) -- Executa essa função quando o evento "iniciaJob" for chamado.

 

Edited by Lord Henry
  • Like 1

Eu te ajudei ou achou meu comentário útil? Não esqueça de deixar um Thanksspacer.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.

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...