Sorata_Kanda

Tieing function to onMarkerHit results in looping teleport

Recommended Posts

Hey everyone,

again, I have a problem. I want to teleport the player whenever it hits the entry/exit marker of a Burger Shot. However, whenever I add the functions to the "onMarkerHit" event, I keep teleporting back and forth. Script is server-sided.

--Entry/Exit marker grabbed from .map file
local burgershotEnter = getElementByID("burgershotEnter")
local burgershotExit = getElementByID("burgershotExit")

-- Table of spawn location when entering/leaving Burger Shot
local burgershotSpawn = {
  enter = {
    x = 364.4189453125,
    y = -74.154296875,
    z = 1001.5078125,
    rot = 313.42001342773
  },

  exit = {
    x = -2334.7392578125,
    y = -166.7958984375,
    z = 35.5546875,
    rot = 221.95193481445
  }
}

-- Debug stuff whether coordinates of entry/exit markers are the same as defined in .map (which in this case, it is)
local enterPosX, enterPosY, enterPosZ = getElementPosition(burgershotEnter)
local exitPosX, exitPosY, exitPosZ = getElementPosition(burgershotExit)

outputChatBox ( "Enter: " .. tostring(burgershotEnter) .. " " .. enterPosX .. ", " .. enterPosY .. ", " .. enterPosZ )
outputChatBox ( "Exit: " .. tostring(burgershotExit) .. " " .. exitPosX .. ", " .. exitPosY .. ", " .. exitPosZ )
---------------------------------------

function burgershotEnterHit( player )
  outputChatBox("Welcome to Burger Shot! If you want to order something, click on the ped.")
  setElementInterior( player, 10, burgershotSpawn["enter"]["x"], burgershotSpawn["enter"]["y"], burgershotSpawn["enter"]["z"])
  --setPlayerRotation( burgershotSpawn["enter"]["rot"] )
end

function burgershotExitHit( player )
  outputChatBox("Thanks for visiting Burger Shot! Come again soon!")
  setElementInterior( player, 0, burgershotSpawn["exit"]["x"], burgershotSpawn["exit"]["y"], burgershotSpawn["exit"]["z"])
  --setPlayerRotation( burgershotSpawn["exit"]["rot"] )
end

addEventHandler( "onMarkerHit", burgershotEnter, burgershotEnterHit )
addEventHandler( "onMarkerHit", burgershotExit, burgershotExitHit )

Do I still have to check if the player is in the marker or not? Because I thought I don't need to do that when I tie the function to an event with the according marker.

Thanks in advance!

Share this post


Link to post

So something I've examined is that there's a certain detection range which goes beyond the marker itself. Can you specifically set that range?

Edited by Sorata_Kanda

Share this post


Link to post
14 minutes ago, DiGiTal said:

Your code dont have a sense . 

GetElementPosition(here element not table)

Why? 'burgershotEnter' and 'burgershotExit' are elements.

The table 'burgershotSpawn' contains coordinates where the player are supposed to be teleported when they hit the marker respectively.

  • Like 1

Share this post


Link to post

when you teleport inside, you instantly hit another marker which teleports you back. You can teleport a player a little bit forward OR make a little delay between marker hits using set/getElementData

@Sorata_Kanda

Share this post


Link to post
2 hours ago, JeViCo said:

when you teleport inside, you instantly hit another marker which teleports you back. You can teleport a player a little bit forward OR make a little delay between marker hits using set/getElementData

@Sorata_Kanda

I actually set the coordinates so you don't tp into the marker. What's strange is that it even triggers onMarkerHit when you are nearby of the marker and not when you "only" hit the marker.

Share this post


Link to post
30 minutes ago, Sorata_Kanda said:

I actually set the coordinates so you don't tp into the marker. What's strange is that it even triggers onMarkerHit when you are nearby of the marker and not when you "only" hit the marker.

as i said you teleport to the next marker and hit it even if you nearby so it causes a loop


-- Table of spawn location when entering/leaving Burger Shot
local burgershotSpawn = {
  enter = {
    x = 364.4189453125,
    y = -74.154296875,
    z = 1001.5078125,
    rot = 313.42001342773
  },

  exit = {
    x = -2334.7392578125,
    y = -166.7958984375,
    z = 35.5546875,
    rot = 221.95193481445
  }
}

--Entry/Exit marker grabbed from .map file

local burgershotEnter = getElementByID("burgershotEnter")
local burgershotExit = getElementByID("burgershotExit")



-- i created markers to test it
--[[
local ent = burgershotSpawn.enter
local exi = burgershotSpawn.exit

local burgershotEnter = createMarker(exi.x,exi.y,exi.z,"cylinder",1)

local burgershotExit = createMarker(ent.x,ent.y,ent.z,"cylinder",1)
setElementInterior(burgershotExit,10)
--]]

-- Debug stuff whether coordinates of entry/exit markers are the same as defined in .map (which in this case, it is)
local enterPosX, enterPosY, enterPosZ = getElementPosition(burgershotEnter)
local exitPosX, exitPosY, exitPosZ = getElementPosition(burgershotExit)

outputChatBox ( "Enter: " .. tostring(burgershotEnter) .. " " .. enterPosX .. ", " .. enterPosY .. ", " .. enterPosZ )
outputChatBox ( "Exit: " .. tostring(burgershotExit) .. " " .. exitPosX .. ", " .. exitPosY .. ", " .. exitPosZ )
---------------------------------------

function burgershotEnterHit( player )
	if not getElementData(player,"player:denyMarker") then -- can player interact with marker or not
		outputChatBox("Welcome to Burger Shot! If you want to order something, click on the ped.")
		setElementInterior( player, 10, burgershotSpawn["enter"]["x"], burgershotSpawn["enter"]["y"], burgershotSpawn["enter"]["z"])
		--setPlayerRotation( burgershotSpawn["enter"]["rot"] )
		setElementData(player,"player:denyMarker",true) -- disable that loop
		setTimer(removeElementData,2000,1,player,"player:denyMarker") -- return ability to interact with markers ( 2 seconds delay)
	end
end

function burgershotExitHit( player )
	if not getElementData(player,"player:denyMarker") then -- can player interact with marker or not
		outputChatBox("Thanks for visiting Burger Shot! Come again soon!")
		setElementInterior( player, 0, burgershotSpawn["exit"]["x"], burgershotSpawn["exit"]["y"], burgershotSpawn["exit"]["z"])
		--setPlayerRotation( burgershotSpawn["exit"]["rot"] )
		setElementData(player,"player:denyMarker",true) -- disable that loop
		setTimer(removeElementData,2000,1,player,"player:denyMarker") -- return ability to interact with markers
	end
end

addEventHandler( "onMarkerHit", burgershotEnter, burgershotEnterHit )
addEventHandler( "onMarkerHit", burgershotExit, burgershotExitHit )

@Sorata_Kanda

Share this post


Link to post
23 minutes ago, JeViCo said:

as i said you teleport to the next marker and hit it even if you nearby so it causes a loop


-- Table of spawn location when entering/leaving Burger Shot
local burgershotSpawn = {
  enter = {
    x = 364.4189453125,
    y = -74.154296875,
    z = 1001.5078125,
    rot = 313.42001342773
  },

  exit = {
    x = -2334.7392578125,
    y = -166.7958984375,
    z = 35.5546875,
    rot = 221.95193481445
  }
}

--Entry/Exit marker grabbed from .map file

local burgershotEnter = getElementByID("burgershotEnter")
local burgershotExit = getElementByID("burgershotExit")



-- i created markers to test it
--[[
local ent = burgershotSpawn.enter
local exi = burgershotSpawn.exit

local burgershotEnter = createMarker(exi.x,exi.y,exi.z,"cylinder",1)

local burgershotExit = createMarker(ent.x,ent.y,ent.z,"cylinder",1)
setElementInterior(burgershotExit,10)
--]]

-- Debug stuff whether coordinates of entry/exit markers are the same as defined in .map (which in this case, it is)
local enterPosX, enterPosY, enterPosZ = getElementPosition(burgershotEnter)
local exitPosX, exitPosY, exitPosZ = getElementPosition(burgershotExit)

outputChatBox ( "Enter: " .. tostring(burgershotEnter) .. " " .. enterPosX .. ", " .. enterPosY .. ", " .. enterPosZ )
outputChatBox ( "Exit: " .. tostring(burgershotExit) .. " " .. exitPosX .. ", " .. exitPosY .. ", " .. exitPosZ )
---------------------------------------

function burgershotEnterHit( player )
	if not getElementData(player,"player:denyMarker") then -- can player interact with marker or not
		outputChatBox("Welcome to Burger Shot! If you want to order something, click on the ped.")
		setElementInterior( player, 10, burgershotSpawn["enter"]["x"], burgershotSpawn["enter"]["y"], burgershotSpawn["enter"]["z"])
		--setPlayerRotation( burgershotSpawn["enter"]["rot"] )
		setElementData(player,"player:denyMarker",true) -- disable that loop
		setTimer(removeElementData,2000,1,player,"player:denyMarker") -- return ability to interact with markers ( 2 seconds delay)
	end
end

function burgershotExitHit( player )
	if not getElementData(player,"player:denyMarker") then -- can player interact with marker or not
		outputChatBox("Thanks for visiting Burger Shot! Come again soon!")
		setElementInterior( player, 0, burgershotSpawn["exit"]["x"], burgershotSpawn["exit"]["y"], burgershotSpawn["exit"]["z"])
		--setPlayerRotation( burgershotSpawn["exit"]["rot"] )
		setElementData(player,"player:denyMarker",true) -- disable that loop
		setTimer(removeElementData,2000,1,player,"player:denyMarker") -- return ability to interact with markers
	end
end

addEventHandler( "onMarkerHit", burgershotEnter, burgershotEnterHit )
addEventHandler( "onMarkerHit", burgershotExit, burgershotExitHit )

@Sorata_Kanda

I'll try that one. But I don't know if you understand the problem or not. :D Take this picture as an example:

1437518174.png

I would expect "onMarketHit" to trigger only when you really enter the marker. Instead, it happens only when your nearby. I suspect it's related with the type of marker. I'll try the corona one.

Share this post


Link to post

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.