Jump to content

destroy the marker - destroyElement


BartiCoderNoob

Recommended Posts

I have the ambition to write all the missions from GTA SA on the MTA server for two people, but I can not write scripts very well yet.
What I was able to write is that after entering the server, a bike appears with marker [where the first mission in SA]. Now I wanted after entering the bike, the marker disappeared. Here are my scraps that absolutely do not work.
Could someone give me a helpfull hand?

meta.xml

<meta>
	<info author="Barti" title="missions" version="0.1"/>
	<script src="missions.lua" type="server"/>
	<cop>true</cop>
</meta>

 


missions.lua

local x1, y1, z1, rx1, ry1, rz1  = 2243.2, -1263.2, 23.5, 0, 0, 270 -- I set the coordinates of the vehicle's spawn

addEventHandler ( "onPlayerJoin", getRootElement(),function() 
	local Bike = createVehicle ( 481, 0, 0, 0 ) -- set the type of vehicle
    setVehicleColor( Bike, 88,142,110 ) -- set the color
    spawnVehicle( Bike, x1, y1, z1, rx1, ry1, rz1)
    local spawnVeh = spawnVehicle ( Bike, x1, y1, z1, rx1, ry1, rz1 ) -- spawns the vehicle
		local xb1, yb1, zb1 = getElementPosition ( Bike ) -- taking the vehicle's coordinates
		local theMarker = createMarker ( xb1, yb1, zb1, "arrow", 0.4, 255, 255, 0, 170 ) -- create a marker over the vehicle
		attachElements ( theMarker, Bike, 0, 0, 1.5 ) -- that is attached to it
		local driver = getVehicleOccupant (source) -- wanted to read if someone is sitting on the bike
		if driver then -- and if he is sitting
			destroyElement(element theMarker)  -- destroy the marker
		end
		
end)

 

Link to comment
local x1, y1, z1, rx1, ry1, rz1  = 2243.2, -1263.2, 23.5, 0, 0, 270 -- I set the coordinates of the vehicle's spawn

addEventHandler ( "onPlayerJoin", getRootElement(),function() 
	local Bike = createVehicle ( 481, 0, 0, 0 ) -- set the type of vehicle
    setVehicleColor( Bike, 88,142,110 ) -- set the color
    spawnVehicle( Bike, x1, y1, z1, rx1, ry1, rz1)
    local spawnVeh = spawnVehicle ( Bike, x1, y1, z1, rx1, ry1, rz1 ) -- spawns the vehicle
		local xb1, yb1, zb1 = getElementPosition ( Bike ) -- taking the vehicle's coordinates
		local theMarker = createMarker ( xb1, yb1, zb1, "arrow", 0.4, 255, 255, 0, 170 ) -- create a marker over the vehicle
		attachElements ( theMarker, Bike, 0, 0, 1.5 ) -- that is attached to it
		local driver = getVehicleOccupant (source) -- wanted to read if someone is sitting on the bike
		if driver then -- and if he is sitting
			destroyElement(theMarker)  -- destroy the marker
		end
		
end)

 

Link to comment

If I did not understand wrong, what you want is when the player gets on the bike the marker is destroyed(Google translator):

local x1, y1, z1, rx1, ry1, rz1  = 2243.2, -1263.2, 23.5, 0, 0, 270 -- I set the coordinates of the vehicle's spawn

addEventHandler ( "onPlayerJoin", getRootElement(),
	function() 
		setElementPosition( source, x1, y1, z1 )
		Bike = createVehicle ( 481, 0, 0, 0 ) -- set the type of vehicle
	   	setVehicleColor( Bike, 88,142,110 ) -- set the color
	   	spawnVehicle( Bike, x1, y1, z1, rx1, ry1, rz1)
	    local spawnVeh = spawnVehicle ( Bike, x1, y1, z1, rx1, ry1, rz1 ) -- spawns the vehicle
		local xb1, yb1, zb1 = getElementPosition ( Bike ) -- taking the vehicle's coordinates
		theMarker = createMarker ( xb1, yb1, zb1, "arrow", 0.4, 255, 255, 0, 170 ) -- create a marker over the vehicle
		attachElements ( theMarker, Bike, 0, 0, 1.5 ) -- that is attached to it
	end 
)


addEventHandler("onVehicleEnter", root,
	function ( player )
		if ( source == Bike ) then 
			destroyElement( theMarker )
		end
	end)

 

  • Thanks 1
Link to comment
32 minutes ago, Melbourne said:

If I did not understand wrong, what you want is when the player gets on the bike the marker is destroyed(Google translator):


local x1, y1, z1, rx1, ry1, rz1  = 2243.2, -1263.2, 23.5, 0, 0, 270 -- I set the coordinates of the vehicle's spawn

addEventHandler ( "onPlayerJoin", getRootElement(),
	function() 
		setElementPosition( source, x1, y1, z1 )
		Bike = createVehicle ( 481, 0, 0, 0 ) -- set the type of vehicle
	   	setVehicleColor( Bike, 88,142,110 ) -- set the color
	   	spawnVehicle( Bike, x1, y1, z1, rx1, ry1, rz1)
	    local spawnVeh = spawnVehicle ( Bike, x1, y1, z1, rx1, ry1, rz1 ) -- spawns the vehicle
		local xb1, yb1, zb1 = getElementPosition ( Bike ) -- taking the vehicle's coordinates
		theMarker = createMarker ( xb1, yb1, zb1, "arrow", 0.4, 255, 255, 0, 170 ) -- create a marker over the vehicle
		attachElements ( theMarker, Bike, 0, 0, 1.5 ) -- that is attached to it
	end 
)


addEventHandler("onVehicleEnter", root,
	function ( player )
		if ( source == Bike ) then 
			destroyElement( theMarker )
		end
	end)

 

O DUUUUUDE YOU ARE MY GOD FROM NOW!! IT WORKS!!

Link to comment

But, what if I want to destroy a marker by hit in it?

I just wrote something like this, but it works only when i hit it with bike and "bFirstMis" does not desapear 

 

addEventHandler("onVehicleEnter", root,
	function ( player )
		if ( source == Bike1 ) then 
			destroyElement( mBike1 )
			mFirstMis = createMarker ( 2495.2, -1687.3, 12.5, "cylinder", 1, 255, 0, 0, 255 )
			bFirstMis = createBlip ( 2495.2, -1687.3, 12.5, 15)
		end
	end)

addEventHandler("onPlayerMarkerHit", getRootElement(),
	function( mFirstMis, matchingDimension )
		if (matchingDimension) then
			destroyElement( mFirstMis )
			destroyElement( bFirstMis )
		end
	end)

 

Link to comment
16 minutes ago, Melbourne said:

addEventHandler("onMarkerHit", getRootElement(),
	function( hitter, matchingDimension )
		if ( source == mFirstMis ) then
			destroyElement( source )
			destroyElement( bFirstMis )
		end
	end)

This could work... Test it

Saddly, it doesn't :(

 

My scraps also dont work:

 

addEventHandler("onMarkerHit", getRootElement(),
	function( player, matchingDimension )
		if ( player == mFirstMis ) then
			destroyElement( mFirstMis )
			destroyElement( bFirstMis )
		end
	end)

 

Edited by BartiCoderNoob
Link to comment

Well, then try this

addEventHandler("onMarkerHit", getRootElement(),
	function( hitter, matchingDimension )
		if ( source == mFirstMis ) then
			if ( getElementType( hitter ) == "player" ) then
				destroyElement( mFirstMis )
				destroyElement( bFirstMis )
			end
		end
	end)

If it still doesn't work, try changing the marker size to 1.5

  • Confused 1
Link to comment
3 hours ago, BartiCoderNoob said:

Maybe we could do something with "matchingDimension"?

Nope, if the element is in the same marker's dimension. Otherwise if you're not it would not work.

addEventHandler("onVehicleEnter", root,
	function ( player )
		if ( source == Bike1 ) then
			--destroyElement( mBike1 ) > is mBike1 also a variable ?
			if not mFirstMis then
				mFirstMis = createMarker ( 2495.2, -1687.3, 12.5, "cylinder", 1, 255, 0, 0, 255 )
				bFirstMis = createBlip ( 2495.2, -1687.3, 12.5, 15)			
			end
		end
	end
)
	
addEventHandler("onPlayerMarkerHit", getRootElement(),
	function( marker, matchingDimension )
		if (matchingDimension) then
			if isElement(mFirstMis) and isElement(bFirstMis) and marker == mFirstMis then
				destroyElement( mFirstMis )
				destroyElement( bFirstMis )
				mFirstMis, bFirstMis = nil, nil
			end
		end
	end
)

 

  • Thanks 1
Link to comment

Oh finally, thank you Enargy

Spoiler
8 minutes ago, Enargy, said:

Nope, if the element is in the same marker's dimension. Otherwise if you're not it would not work.



addEventHandler("onVehicleEnter", root,
	function ( player )
		if ( source == Bike1 ) then
			--destroyElement( mBike1 ) > is mBike1 also a variable ?
			if not mFirstMis then
				mFirstMis = createMarker ( 2495.2, -1687.3, 12.5, "cylinder", 1, 255, 0, 0, 255 )
				bFirstMis = createBlip ( 2495.2, -1687.3, 12.5, 15)			
			end
		end
	end
)
	
addEventHandler("onPlayerMarkerHit", getRootElement(),
	function( marker, matchingDimension )
		if (matchingDimension) then
			if isElement(mFirstMis) and isElement(bFirstMis) and marker == mFirstMis then
				destroyElement( mFirstMis )
				destroyElement( bFirstMis )
				mFirstMis, bFirstMis = nil, nil
			end
		end
	end
)

 

 

 

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