Jump to content

[HELP] onMarkerHit


Recommended Posts

Hi, in the table there is an outside positons (x y z, dim, int) and inside pos's (inx y, z, dim, int). But when player hit the second marker , nothing happen, but when player hit the first marker it's work.

local Markers = {
   --  outX, outY, outZ, outInt, outDim, inX, inY, inZ, inInt, inDim
    {1852.8375244141, -1752.1379394531, 13.3828125, 0, 0, 1839.7073974609, -1745.7852783203, 13.546875, 0, 0},
    {1825.2690429688, -1758.576171875, 13.3828125, 0, 0, 1815.5324707031, -1769.6801757813, 13.546875, 0, 0},
}


addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function()

    
    for k, v in pairs(Markers) do
    

        local outX, outY, outZ, outDim, outInt, inX, inY, inZ, inDim, inInt = v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10]

    
    
        
        insideMarker = createMarker(inX, inY, inZ, "cylinder", 1, 0, 255, 0, 180)
        outsideMarker = createMarker(outX, outY, outZ, "cylinder", 1, 255, 0, 0, 150)        
    end
    

    
    
    addEventHandler( "onMarkerHit", outsideMarker, function ( hitElement, matchingDimension ) 
        setElementPosition(hitElement, inX, inY, inZ)
    end)


    
    addEventHandler( "onMarkerHit", insideMarker, function ( hitElement, matchingDimension ) 
        setElementPosition(hitElement, outX, outY + 3, outZ)
    end)    
    
end)

 

Link to comment

So this is something for teleporting from one position to another. The problem is the second marker doesn't do anything for some reason. 

local Markers = {
   --  outX, outY, outZ, outInt, outDim, inX, inY, inZ, inInt, inDim
    {--[[ From here the inside marker]] 1852.8375244141, -1752.1379394531, 13.3828125, 0, 0, --[[ From here the outside marker]] 1839.7073974609, -1745.7852783203, 13.546875, 0, 0},  -- Marker 1 [IN / OUT]
    
    {--[[ From here the inside marker]] 1825.2690429688, -1758.576171875, 13.3828125, 0, 0, --[[ From here the outside marker]] 1815.5324707031, -1769.6801757813, 13.546875, 0, 0},   -- Marker 2 [IN / OUT]
}

 

Link to comment

Because the variable will be assigned to only one marker. An easy solution is storing the markers in a table:

local teleportMarkers = {}

teleportMarkers[k] = {
	createMarker(inX, inY, inZ, "cylinder", 1, 0, 255, 0, 180), -- inside
	createMarker(outX, outY, outZ, "cylinder", 1, 255, 0, 0, 150) -- outside
}

addEventHandler( "onMarkerHit", teleportMarkers[k][1], function ( hitElement, matchingDimension ) 
	setElementPosition(hitElement, outX, outY + 3, outZ)
end)

addEventHandler( "onMarkerHit", teleportMarkers[k][2], function ( hitElement, matchingDimension ) 
	setElementPosition(hitElement, inX, inY, inZ)
end)
-- * everything except the table inside the loop * --

 

Edited by DNL291
  • Thanks 1
Link to comment

Thank you, one more question.

 

How can i make that, when the player came out of the interior, it's spawning inside the marker, and the marker instead teleporting back the player..

 

Any idea?

        addEventHandler( "onMarkerHit", teleportMarkers[k][1], function ( hitElement, matchingDimension ) 
            setElementPosition(hitElement, outX, outY + 2, outZ)
            setElementDimension(hitElement, v[4])
            setElementInterior(hitElement, v[5])    
        end)

    
        addEventHandler( "onMarkerHit", teleportMarkers[k][2], function ( hitElement, matchingDimension ) 
            setElementPosition(hitElement, inX, inY + 2, inZ)
            setElementDimension(hitElement, v[9])
            setElementInterior(hitElement, v[10])    
        end)

 

Link to comment

Add to the table the player coordinates of entrance/exit:


local Markers = {
	--  outX, outY, outZ, outInt, outDim, inX, inY, inZ, inInt, inDim
	{1852.8375244141, -1752.1379394531, 13.3828125, 0, 0, 1839.7073974609, -1745.7852783203, 13.546875, 0, 0,
		entrancePos = { x, y, z, rot }, exitPos = { x, y, z, rot }
	},
	{1825.2690429688, -1758.576171875, 13.3828125, 0, 0, 1815.5324707031, -1769.6801757813, 13.546875, 0, 0
		entrancePos = { x, y, z, rot }, exitPos = { x, y, z, rot }
	}
}
local teleportMarkers = {}

addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function()    
	for k, v in pairs(Markers) do

		local outX, outY, outZ, outDim, outInt, inX, inY, inZ, inDim, inInt = v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10]
	
		teleportMarkers[k] = {
			createMarker(inX, inY, inZ, "cylinder", 1, 0, 255, 0, 180), -- inside
			createMarker(outX, outY, outZ, "cylinder", 1, 255, 0, 0, 150) -- outside
		}
		setElementInterior( teleportMarkers[k][1], inDim )
		setElementPosition( teleportMarkers[k][1], inInt )

		addEventHandler( "onMarkerHit", teleportMarkers[k][2], function ( hitElement, matchingDimension )
			if getElementType(hitElement) == "player" and matchingDimension then
				local px,py,pz,rot = unpack( Markers[k].entrancePos )
				
				setElementPosition( hitElement, px, py, pz+1 )
				setElementRotation( hitElement, 0, 0, rot )
				setElementDimension( hitElement, Markers[k][10] )
				setElementInterior( hitElement, Markers[k][9] )
			end
		end)

		addEventHandler( "onMarkerHit", teleportMarkers[k][1], function ( hitElement, matchingDimension )
			if getElementType(hitElement) == "player" and matchingDimension then
				local px,py,pz,rot = unpack( Markers[k].exitPos )
				
				setElementPosition( hitElement, px, py, pz+1 )
				setElementRotation( hitElement, 0, 0, rot )
				setElementDimension( hitElement, Markers[k][5] )
				setElementInterior( hitElement, Markers[k][4] )
			end
		end)
end)

 

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