Jump to content

[Solved]problem with tables and markers


Recommended Posts

local mm1 = {}
local mm2 = {}

local m1 = { 
[1] = {2491,-1665,12}, 
[2] = {2491,-1687,12}
} 

local m2 = { 
[1] = {2497,-1665,12}, 
[2] = {2497,-1687,12}
} 
  
for _,v in ipairs(m1) do 
mar = createMarker ( v[1],v[2],v[3], "cylinder",5.1,12,7,77,153)
mm1[mar] = true 
end 

for _,d in ipairs(m2) do 
  mar2 = createMarker ( d[1],d[2],d[3], "cylinder",5.1,100,6,77,153)
  mm2[mar2] = true  
end 

function sveven ( hitPlayer, matchingDimension )
 if (mm1[source] and matchingDimension and hitPlayer == localPlayer ) then
triggerServerEvent("event1", localPlayer)

 elseif  (mm2[source] and matchingDimension and hitPlayer == localPlayer ) then
   triggerServerEvent("even2", localPlayer) 
 
 end
end


addEventHandler("onClientMarkerHit", resourceRoot, sveven)

 

Link to comment

And the explanation: since you have more than one marker positions, if you run the loop number of times, the variable mar and mar2 will be replaced with the newly created marker, since a variable can have only one value, the values will be overridden. To fix that, you'll need to use tables, the way it's been done above. 

Link to comment

Solved Thanks

8 minutes ago, pa3ck said:

And the explanation: since you have more than one marker positions, if you run the loop number of times, the variable mar and mar2 will be replaced with the newly created marker, since a variable can have only one value, the values will be overridden. To fix that, you'll need to use tables, the way it's been done above. 

thanks man it really helped 

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