aintaro Posted April 6, 2014 Posted April 6, 2014 Hello guys, Lets say you have 100 markers on the map, how would you go and write a code that checks if a CERTAIN marker has been hit by the player? thanks in advance, greetz aintaro
Castillo Posted April 6, 2014 Posted April 6, 2014 You can use one of these events: onMarkerHit --> server side onClientMarkerHit --> client side
aintaro Posted April 6, 2014 Author Posted April 6, 2014 those would only tell if we hit a marker, but not a CERTAIN marker
Castillo Posted April 6, 2014 Posted April 6, 2014 You can attach the event handler to the marker you want to trigger the function.
Arnold-1 Posted April 6, 2014 Posted April 6, 2014 use a loop, firstly make a table in all the positions: pos = { --{x,y,z} } for i,v in ipairs(pos) do local x,y,z = unpack(pos[i]) createMarker(x,y,z ......) end closestMarker = 9999999999999999 addEventHandler("onMarkerHit",root, function (player) for i,v in ipairs(pos) do local x,y,z = unpack(pos) x1 , y1,z1 = getElementPosition(player) distance2 = getDistanceBetweenPoints3D(x,y,z,x1,y1,z1) --tell me what do you want then? end end )
Mr_Moose Posted April 6, 2014 Posted April 6, 2014 addEventHandler("onMarkerHit",root, function (player) -- source is the marker that you hit when root is the attached element, to get the distance, use this local max,may,maz = getElementPosition(source) local px,py,pz = getElementPosition(player) local distance = getDistanceBetweenPoints3D( max,may,maz, px,py,pz ) end) Don't use loops where it's not needed, this will give you both the marker element and the distance from this marker element to the player or element that just hit it, I'm not sure what you are trying to do but this should cover anything you need in a way more efficient way.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now