Jump to content

Vehicle spawn from inside


Wananazo

Recommended Posts

Hello friends I have a question about this fragment of code, the marker is in the department of the saints (interior 6) its function is to be able to choose a vehicle which I want to appear in the police garage (interior 0) my question is how I would do so that the interior can be invoked 0

 

veh3 = {}
function spawnVehicle()
	if veh3[source] and isElement( veh3[source] ) then destroyElement(veh3[source])
		veh3[source] = nil
	end     
    veh3[source] = createVehicle(523, 1586.75207, -1671.39477, 6.61896)
    setElementInterior(spawnVehicle,0)
    warpPedIntoVehicle(source, veh3[source])

 

Edited by Wananazo
Link to comment
11 hours ago, Wananazo said:

Hello friends I have a question about this fragment of code, the marker is in the department of the saints (interior 6) its function is to be able to choose a vehicle which I want to appear in the police garage (interior 0) my question is how I would do so that the interior can be invoked 0

 


veh3 = {}
function spawnVehicle()
	if veh3[source] and isElement( veh3[source] ) then destroyElement(veh3[source])
		veh3[source] = nil
	end     
    veh3[source] = createVehicle(523, 1586.75207, -1671.39477, 6.61896)

    setElementInterior(spawnVehicle,0) -- ???

    warpPedIntoVehicle(source, veh3[source])

 

aren't you setting interior of a function name? try replacing with the veh3[source] if u mean u want to set the interior of the car to 0.

veh3 = {}
function spawnVehicle()
	if veh3[source] and isElement( veh3[source] ) then destroyElement(veh3[source])
		veh3[source] = nil
	end     
    veh3[source] = createVehicle(523, 1586.75207, -1671.39477, 6.61896)
    setElementInterior(veh3[source], 0) 
    warpPedIntoVehicle(source, veh3[source])

 

Edited by Bean666
  • Like 1
Link to comment
4 hours ago, Bean666 said:

aren't you setting interior of a function name? try replacing with the veh3[source] if u mean u want to set the interior of the car to 0.


veh3 = {}
function spawnVehicle()
	if veh3[source] and isElement( veh3[source] ) then destroyElement(veh3[source])
		veh3[source] = nil
	end     
    veh3[source] = createVehicle(523, 1586.75207, -1671.39477, 6.61896)
    setElementInterior(veh3[source], 0) 
    warpPedIntoVehicle(source, veh3[source])

 

the truth still keeps throwing me inside 6 and not inside 0 as I want it to work, the marker is supposed to be inside 6 and I want the vehicle to appear inside 0
 

6 hours ago, Tekken said:

Hello, I’ve moved your topic to scripting section for best results!

I cannot understand your question will you please develop?

what I really want is for that marker that is inside 6 to send me inside 0 I'm going to share the complete fragment here

 

local mrk = createMarker(254.03366, 78.57809, 1003.64062 -1, "cylinder", 1.5, 70,130,85) 
setElementInterior(mrk,6)
local destroyM = createMarker(-2408.79712, -590.94116, 132.64844 -1, "cylinder", 3, 255, 0, 0)


-- Abrir painel
addEventHandler("onMarkerHit", mrk, function(onHit)
    if getElementType(onHit) == "player" then
        triggerClientEvent(onHit, "LS:AbrirMarkerPOL", onHit)
    end
end)
--

-- Destroy Function
function destroy(player)
	if isElementWithinMarker(player, destroyM) then
	if isPedInVehicle(player) == true then
		destroyElement(veh[player])
		destroyElement(veh2[player])
		destroyElement(veh3[player])
		destroyElement(veh4[player])
		outputChatBox("", player, 255,255,255,true)
	else
		outputChatBox("", player, 255,255,255,true)
	end
end
end
addEventHandler("onMarkerHit", destroyM, destroy)
--

-- Give Viatura 01
veh = {}
function spawnVehicle()
	if veh[source] and isElement( veh[source] ) then destroyElement(veh[source])
		veh[source] = nil
	end     
    veh[source] = createVehicle(490, -2421.15649, -608.30200, 132.56250)
    warpPedIntoVehicle(source, veh[source])
    outputChatBox("#00FF00 Jefatura | #FFFFFF Patrulla 1 Seleccionada.", source, 255, 255, 255, true)
end
addEvent("LS:GiveVTR", true)
addEventHandler("LS:GiveVTR", getRootElement(), spawnVehicle)
--

-- Give Rocam
veh3 = {}
function spawnVehicle()
	if veh3[source] and isElement( veh3[source] ) then destroyElement(veh3[source])
		veh3[source] = nil
	end     
    veh3[source] = createVehicle(523, 1586.75207, -1671.39477, 6.61896)
    setElementInterior(veh3[source], 0)
    warpPedIntoVehicle(source, veh3[source])
    outputChatBox("#00FF00 Jefatura | #FFFFFF Patrulla Seleccionado.", source, 255, 255, 255, true)
end
addEvent("LS:GiveRocam", true)
addEventHandler("LS:GiveRocam", getRootElement(), spawnVehicle)

 

Link to comment
26 minutes ago, Wananazo said:

the truth still keeps throwing me inside 6 and not inside 0 as I want it to work, the marker is supposed to be inside 6 and I want the vehicle to appear inside 0
 

what I really want is for that marker that is inside 6 to send me inside 0 I'm going to share the complete fragment here

 

 

local mrk = createMarker(254.03366, 78.57809, 1003.64062 -1, "cylinder", 1.5, 70,130,85) 
setElementInterior(mrk,6)
local destroyM = createMarker(-2408.79712, -590.94116, 132.64844 -1, "cylinder", 3, 255, 0, 0)


-- OPEN PANEL --

addEventHandler("onMarkerHit", mrk,
function(onHit)
    if isElement(onHit) and getElementType(onHit) == "player" then
        triggerClientEvent(onHit, "LS:AbrirMarkerPOL", onHit)
    end
end
)
--

-- Destroy Function

function destroy(player)
	if isElementWithinMarker(player, destroyM) then
		local theVehicle = getPedOccupiedVehicle(player)
		if theVehicle then 
			if isElement(veh[player]) then 
				destroyElement(veh[player])
			elseif isElement(veh[player]) then 
				destroyElement(veh2[player])
			elseif isElement(veh3[player]) then 
				destroyElement(veh3[player])
			elseif isElement(veh4[player]) then 
				destroyElement(veh4[player])
			end 
			outputChatBox("", player, 255,255,255,true)
		else
			outputChatBox("", player, 255,255,255,true)
		end
	end
end
addEventHandler("onMarkerHit", destroyM, destroy)

--

-- Give Viatura 01

veh = {}

function spawnVehicleVTR()
	if veh[source] and isElement( veh[source] ) then destroyElement(veh[source])
		veh[source] = nil
	end     
    veh[source] = createVehicle(490, -2421.15649, -608.30200, 132.56250)
	local x, y, z = getElementPosition(veh[source])
	setElementInterior(source, 0)
	setElementPosition(source, x, y, z+2)
    warpPedIntoVehicle(source, veh[source])
    outputChatBox("#00FF00 Jefatura | #FFFFFF Patrulla 1 Seleccionada.", source, 255, 255, 255, true)
end
addEvent("LS:GiveVTR", true)
addEventHandler("LS:GiveVTR", root, spawnVehicleVTR)
--

-- Give Rocam

veh3 = {}

function spawnVehicleRocam()
	if veh3[source] and isElement( veh3[source] ) then destroyElement(veh3[source])
		veh3[source] = nil
	end     
    veh3[source] = createVehicle(523, 1586.75207, -1671.39477, 6.61896)
	local x, y, z = getElementPosition(veh3[source])
	setElementInterior(source, 0)
	setElementPosition(source, x, y, z+2)
    warpPedIntoVehicle(source, veh3[source])
    outputChatBox("#00FF00 Jefatura | #FFFFFF Patrulla Seleccionado.", source, 255, 255, 255, true)
end
addEvent("LS:GiveRocam", true)
addEventHandler("LS:GiveRocam", root, spawnVehicleRocam)

Here, i dont think the setElementPosition is necessary, but just put that so i can make sure you'll arrive at your car. it's just a checker if it will work, later on you can try to remove the setElementPosition see if it still works. anyways you had two functions that had the same name, I changed the two function names. make sure to add checks on the destroyElements.

also I suggest using getPedOccupiedVehicle check instead of isPedInVehicle.

Edited by Bean666
Link to comment
7 minutes ago, Bean666 said:



local mrk = createMarker(254.03366, 78.57809, 1003.64062 -1, "cylinder", 1.5, 70,130,85) 
setElementInterior(mrk,6)
local destroyM = createMarker(-2408.79712, -590.94116, 132.64844 -1, "cylinder", 3, 255, 0, 0)


-- OPEN PANEL --

addEventHandler("onMarkerHit", mrk,
function(onHit)
    if isElement(onHit) and getElementType(onHit) == "player" then
        triggerClientEvent(onHit, "LS:AbrirMarkerPOL", onHit)
    end
end
)
--

-- Destroy Function

function destroy(player)
	if isElementWithinMarker(player, destroyM) then
		if isPedInVehicle(player) == true then
			destroyElement(veh[player])
			destroyElement(veh2[player])
			destroyElement(veh3[player])
			destroyElement(veh4[player])
			outputChatBox("", player, 255,255,255,true)
		else
			outputChatBox("", player, 255,255,255,true)
		end
	end
end
addEventHandler("onMarkerHit", destroyM, destroy)

--

-- Give Viatura 01

veh = {}

function spawnVehicleVTR()
	if veh[source] and isElement( veh[source] ) then destroyElement(veh[source])
		veh[source] = nil
	end     
    veh[source] = createVehicle(490, -2421.15649, -608.30200, 132.56250)
	local x, y, z = getElementPosition(veh[source])
	setElementInterior(source, 0)
	setElementPosition(source, x, y, z+2)
    warpPedIntoVehicle(source, veh[source])
    outputChatBox("#00FF00 Jefatura | #FFFFFF Patrulla 1 Seleccionada.", source, 255, 255, 255, true)
end
addEvent("LS:GiveVTR", true)
addEventHandler("LS:GiveVTR", root, spawnVehicleVTR)
--

-- Give Rocam

veh3 = {}

function spawnVehicleRocam()
	if veh3[source] and isElement( veh3[source] ) then destroyElement(veh3[source])
		veh3[source] = nil
	end     
    veh3[source] = createVehicle(523, 1586.75207, -1671.39477, 6.61896)
	local x, y, z = getElementPosition(veh3[source])
	setElementInterior(source, 0)
	setElementPosition(source, x, y, z+2)
    warpPedIntoVehicle(source, veh3[source])
    outputChatBox("#00FF00 Jefatura | #FFFFFF Patrulla Seleccionado.", source, 255, 255, 255, true)
end
addEvent("LS:GiveRocam", true)
addEventHandler("LS:GiveRocam", root, spawnVehicleRocam)

‎Aquí, no creo que el setElementPosition sea necesario, pero sólo ponlo para que pueda asegurarme de que llegarás a tu auto. es sólo un comprobador si va a funcionar, más adelante se puede tratar de quitar el setElementPosition ver si todavía funciona. De todos modos tenías dos funciones que tenían el mismo nombre, cambié los dos nombres de función. ‎

ok, it worked for me so it was badly structured the code really worked now I'm putting it into practice with the other scripts

  • Like 1
Link to comment

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