Jump to content

[HELP] attachElement


Ekko

Recommended Posts

local siren = false


function undercover (player)
	local vehicle = getPedOccupiedVehicle(player)
	local id = getElementModel(vehicle)
		if isPedInVehicle(player) then
		if id == 560 then
				if siren == false then 
					local Object = createObject(1668,5,5,5)
					attachElements ( Object, vehicle, -0.4, 0.5, 0.868 )
					siren = true
			elseif siren == true then
					local attachedElements = getAttachedElements (vehicle)
					for i,v in ipairs (attachedElements) do
					detachElements (v, vehicle)
					siren = false
				end
			end
		end
	end
end

addCommandHandler("taxion",undercover)

Hello basically this script attach taxi sing in vehicle ID 560 but the problem just one can use it in the server pls help me , make it many players can use it 

Link to comment
17 minutes ago, IIYAMA said:

A very quick and basic solution, would be:


local siren = #getAttachedElements (vehicle) > 0


Place it where you think it would make sense in your code.

 

And if you do not know where to place it, you can always try it at all 24 lines till the code finally does what you want... ?‍♂️

 

 

@Ekko

i did like you said it didn't work explain more pls

Edited by Ekko
Link to comment
1 minute ago, IIYAMA said:

getAttachedElements (vehicle)

This returns a table with attached elements.

 


#table

# gets the length of a table.

 


value > 0

This returns true or false depending if the value is higher than 0.

 


local serin = result

This saves the result in to serin.

 

 

 

Ok man but i tryied the code at all 24 lanes didn't work i dont know what to do now 

Link to comment

 

function undercover (player)
	local vehicle = getPedOccupiedVehicle(player)
	local id = getElementModel(vehicle)
  	local siren = getElementData(vehicle, "siren")
		if isPedInVehicle(player) then
			if id == 560 then
				if not siren then 
					local Object = createObject(1668,5,5,5)
					attachElements ( Object, vehicle, -0.4, 0.5, 0.868 )
					setElementData(vehicle, "siren", true)
				else
					local attachedElements = #getAttachedElements (vehicle)
					for i,v in ipairs (attachedElements) do
					detachElements (v, vehicle)
					setElementData(vehicle, "siren", false)
				end
			end
		end
	end
end

addCommandHandler("taxion",undercover)

try this

or you can make a function to getVehicleByType, then make a db reference

Edited by LyricalMM
Link to comment
13 hours ago, LyricalMM said:

 


function undercover (player)
	local vehicle = getPedOccupiedVehicle(player)
	local id = getElementModel(vehicle)
  	local siren = getElementData(vehicle, "siren")
		if isPedInVehicle(player) then
			if id == 560 then
				if not siren then 
					local Object = createObject(1668,5,5,5)
					attachElements ( Object, vehicle, -0.4, 0.5, 0.868 )
					setElementData(vehicle, "siren", true)
				else
					local attachedElements = #getAttachedElements (vehicle)
					for i,v in ipairs (attachedElements) do
					detachElements (v, vehicle)
					setElementData(vehicle, "siren", false)
				end
			end
		end
	end
end

addCommandHandler("taxion",undercover)

try this

or you can make a function to getVehicleByType, then make a db reference

:( didn't work

 

Link to comment
function undercover (player)
	local vehicle = getPedOccupiedVehicle(player)
	local id = getElementModel(vehicle)
  	local siren = getElementData(vehicle, "siren")
		if isPedInVehicle(player) then
			if id == 560 then
				if not siren then 
					local Object = createObject(1668,5,5,5)
					attachElements ( Object, vehicle, -0.4, 0.5, 0.868 )
					setElementData(vehicle, "siren", true)
				else
					
					for i,v in ipairs (getAttachedElements(vehicle) ) do
					detachElements (v, vehicle)
					setElementData(vehicle, "siren", false)
				end
			end
		end
	end
end

addCommandHandler("taxion",undercover)

Try this 

Link to comment
4 minutes ago, Dimos7 said:

function undercover (player)
	local vehicle = getPedOccupiedVehicle(player)
	local id = getElementModel(vehicle)
  	local siren = getElementData(vehicle, "siren")
		if isPedInVehicle(player) then
			if id == 560 then
				if not siren then 
					local Object = createObject(1668,5,5,5)
					attachElements ( Object, vehicle, -0.4, 0.5, 0.868 )
					setElementData(vehicle, "siren", true)
				else
					
					for i,v in ipairs (getAttachedElements(vehicle) ) do
					detachElements (v, vehicle)
					setElementData(vehicle, "siren", false)
				end
			end
		end
	end
end

addCommandHandler("taxion",undercover)


Try this 

damn you are so good wow , can you make it when i enter elevetor the object dont disappear pls !! ?

 

Link to comment
function undercover (player)
	local vehicle = getPedOccupiedVehicle(player)
	local id = getElementModel(vehicle)
  	local siren = getElementData(vehicle, "siren")
		if isPedInVehicle(player) then
			if id == 560 then
				if not siren then 
					local Object = createObject(1668,5,5,5)
					attachElements ( Object, vehicle, -0.4, 0.5, 0.868 )
					setElementData(vehicle, "siren", true)
        setElementInterior(Object, getElementInterior(vehicle)) 
        setElementDimension(Object, getElementDimension(vehicle)) 
				else
					
					for i,v in ipairs (getAttachedElements(vehicle) ) do
					detachElements (v, vehicle)
					setElementData(vehicle, "siren", false)
				end
			end
		end
	end
end

addCommandHandler("taxion",undercover)

This should work

Link to comment
5 hours ago, Dimos7 said:

function undercover (player)
	local vehicle = getPedOccupiedVehicle(player)
	local id = getElementModel(vehicle)
  	local siren = getElementData(vehicle, "siren")
		if isPedInVehicle(player) then
			if id == 560 then
				if not siren then 
					local Object = createObject(1668,5,5,5)
					attachElements ( Object, vehicle, -0.4, 0.5, 0.868 )
					setElementData(vehicle, "siren", true)
        setElementInterior(Object, getElementInterior(vehicle)) 
        setElementDimension(Object, getElementDimension(vehicle)) 
				else
					
					for i,v in ipairs (getAttachedElements(vehicle) ) do
					detachElements (v, vehicle)
					setElementData(vehicle, "siren", false)
				end
			end
		end
	end
end

addCommandHandler("taxion",undercover)


This should work

the object still dont show inside the garage (dimension/interior) :/

Edited by Ekko
Link to comment
1 hour ago, Dimos7 said:

go to tp script and do getAttachedElements and make it go with the element  go to interior

when i add it specifically pls her is the tp 

marker = {}
marker[1] = createMarker(1906.501953125, -2294.4736328125, 13.75768661499, "corona", 1.5, 100, 0, 100, 100)
setElementInterior(marker[1], 56)
setElementDimension (marker[1], 44 )
function TelePort(Element, hitElement)
setElementInterior(Element, 0)
setElementDimension (Element, 0)
setElementInterior(hitElement, 0)
setTimer(setElementInterior, 10, 1, Element, 0)
setTimer(setElementInterior, 10, 1, hitElement, 0)
setElementPosition(Element, 1335.4150390625, 446.3466796875, 20.284374237061, true)
setElementFrozen(Element, true)
setTimer(setElementFrozen, 1000, 1,Element, false)
setElementRotation ( Element, 0, 0, 248.84687805176 )
end
addEventHandler("onMarkerHit",marker[1], function (player)  
if getElementType(player)=="player" then
local vehicle = getPedOccupiedVehicle(player)
if vehicle then 
local pTeam = getPlayerTeam(player)
if pTeam and getTeamName(pTeam) == 'Gendarmerie Royale' then TelePort(vehicle, player) return end  
outputChatBox ('You are not in this Faction!',player, 255, 0, 0 ) 
else
outputChatBox ('You need to be in Vehicle to enter this Garage!',player, 255, 0, 0 ) 
end 
end 
end) 

 

Link to comment
marker = {}
marker[1] = createMarker(1906.501953125, -2294.4736328125, 13.75768661499, "corona", 1.5, 100, 0, 100, 100)
setElementInterior(marker[1], 56)
setElementDimension (marker[1], 44 )
function TelePort(Element, hitElement)
  for k, v in ipairs(getAttachedElements(Element)) do
    setElementInterior(v, 0)
    setElementDimension(v, 0)
setElementInterior(Element, 0)
setElementDimension (Element, 0)
setElementInterior(hitElement, 0)
setTimer(setElementInterior, 10, 1, Element, 0)
setTimer(setElementInterior, 10, 1, hitElement, 0)
setElementPosition(Element, 1335.4150390625, 446.3466796875, 20.284374237061, true)
setElementFrozen(Element, true)
setTimer(setElementFrozen, 1000, 1,Element, false)
setElementRotation ( Element, 0, 0, 248.84687805176 )
    end
end
addEventHandler("onMarkerHit",marker[1], function (player)  
if getElementType(player)=="player" then
local vehicle = getPedOccupiedVehicle(player)
if vehicle then 
local pTeam = getPlayerTeam(player)
if pTeam and getTeamName(pTeam) == 'Gendarmerie Royale' then TelePort(vehicle, player) return end  
outputChatBox ('You are not in this Faction!',player, 255, 0, 0 ) 
else
outputChatBox ('You need to be in Vehicle to enter this Garage!',player, 255, 0, 0 ) 
end 
end 
end) 

try something like this

Link to comment
9 minutes ago, Dimos7 said:

marker = {}
marker[1] = createMarker(1906.501953125, -2294.4736328125, 13.75768661499, "corona", 1.5, 100, 0, 100, 100)
setElementInterior(marker[1], 56)
setElementDimension (marker[1], 44 )
function TelePort(Element, hitElement)
  for k, v in ipairs(getAttachedElements(Element)) do
    setElementInterior(v, 0)
    setElementDimension(v, 0)
setElementInterior(Element, 0)
setElementDimension (Element, 0)
setElementInterior(hitElement, 0)
setTimer(setElementInterior, 10, 1, Element, 0)
setTimer(setElementInterior, 10, 1, hitElement, 0)
setElementPosition(Element, 1335.4150390625, 446.3466796875, 20.284374237061, true)
setElementFrozen(Element, true)
setTimer(setElementFrozen, 1000, 1,Element, false)
setElementRotation ( Element, 0, 0, 248.84687805176 )
    end
end
addEventHandler("onMarkerHit",marker[1], function (player)  
if getElementType(player)=="player" then
local vehicle = getPedOccupiedVehicle(player)
if vehicle then 
local pTeam = getPlayerTeam(player)
if pTeam and getTeamName(pTeam) == 'Gendarmerie Royale' then TelePort(vehicle, player) return end  
outputChatBox ('You are not in this Faction!',player, 255, 0, 0 ) 
else
outputChatBox ('You need to be in Vehicle to enter this Garage!',player, 255, 0, 0 ) 
end 
end 
end) 


try something like this

thanks man it work perfectly your the best 

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