3B00DG4MER Posted August 13, 2014 Posted August 13, 2014 Hi Guys today i'm making a CnR system but there's a problem while creating and destroying the Marker !! debugscript : attempt to index global 'marker' (a nil value) Client : for index = 1, #jails do marker[index] = createMarker ( jails [ index ] [ 1 ], jails [ index ] [ 2 ], jails [ index ] [ 3 ], "cylinder", 6, 0, 0, 255, 55, getLocalPlayer() ) end ..... for index = 1, #jails do destroyElement ( marker[index] ) end
Bonsai Posted August 13, 2014 Posted August 13, 2014 If you are creating a gamemode, you should know what that error message means and how to fix it. Did you marker = {} somewhere?
3B00DG4MER Posted August 13, 2014 Author Posted August 13, 2014 If you are creating a gamemode, you should know what that error message means and how to fix it.Did you marker = {} somewhere? i tried not working
3B00DG4MER Posted August 14, 2014 Author Posted August 14, 2014 Script. Look again cuz i've edited it coptargets = 0 local jails = { {2246.1008300781, 2453.1953125, 9.8203125}, {-1406.9072265625, 2655.0927734375, 55.6875}, {-209.9542, 977.7558, 18.188976}, {-1628.2619628906, 676.62005615234, 6.1901206970215}, {624.66278076172, -605.72027587891, 15.923292160034}, {1565.3386230469, -1628.5202636719, 12.382812}, {-2164.3779296875, -2389.533203125, 29.617206573486} } marker = {} function getNearestDP ( x, y ) local temp = { } -- Define a table to store our data. for index = 1, #jails do -- Loop from 1 to the total items in "jails" table. local dist = getDistanceBetweenPoints2D ( x, y, jails [ index ] [ 1 ], jails [ index ] [ 2 ] ) -- Get the distance between the jail coordinates and the given coordinates. table.insert ( temp, { index = index, dist = dist } ) -- Insert it into our "temp" table. end table.sort ( -- Sort the "temp" table by lowest distance. temp, function ( a, b ) return ( ( a.dist or 0 ) < ( b.dist or 0 ) ) end ) return unpack ( jails [ temp [ 1 ].index ] ) -- Return coordinates from the nearest jail. end addEvent("copdirections", true) function copshops( ) if coptargets == 0 then coptargets = 1 for index = 1, #jails do marker[index] = createMarker ( jails [ index ] [ 1 ], jails [ index ] [ 2 ], jails [ index ] [ 3 ], "cylinder", 6, 0, 0, 255, 55, getLocalPlayer() ) end local x, y, z = getElementPosition ( source ) local hx, hy, hz = getNearestDP ( x, y ) blip = createBlip ( hx, hy, hz , 30, 3, 0, 0, 255, 255, 50 ) colshape = createColSphere ( hx, hy, hz, 6 ) setElementData ( colshape, "purpose", "copshop" ) end end addEventHandler("copdirections", getRootElement(), copshops) --REMOVES POLICE STATION BLIPS FROM COPS RADAR AND THE MARKERS addEvent("clearcopdirections", true) function clearcopshops() if coptargets == 1 then coptargets = 0 destroyElement ( blip ) for index = 1, #jails do destroyElement ( marker[index] ) end destroyElement ( colshape ) end end addEventHandler("clearcopdirections", getRootElement(), clearcopshops)
3B00DG4MER Posted August 14, 2014 Author Posted August 14, 2014 i don't need your help i fixed myself
Max+ Posted August 14, 2014 Posted August 14, 2014 i don't need your helpi fixed myself Great Job , See it's nice to depend to yourself ,
3B00DG4MER Posted August 14, 2014 Author Posted August 14, 2014 Great Job , See it's nice to depend to yourself , Ty
3B00DG4MER Posted August 14, 2014 Author Posted August 14, 2014 What was the problem? i've replaced "marker[4]" with "jails[index][4]" and i added on every row "jails" table index of the row
Moderators IIYAMA Posted August 15, 2014 Moderators Posted August 15, 2014 I wasn't able to find large bugs. Well what is the problem with it? coptargets = 0 local jails = { {2246.1008300781, 2453.1953125, 9.8203125}, {-1406.9072265625, 2655.0927734375, 55.6875}, {-209.9542, 977.7558, 18.188976}, {-1628.2619628906, 676.62005615234, 6.1901206970215}, {624.66278076172, -605.72027587891, 15.923292160034}, {1565.3386230469, -1628.5202636719, 12.382812}, {-2164.3779296875, -2389.533203125, 29.617206573486} } marker = {} function getNearestDP ( x, y ) local temp = { } -- Define a table to store our data. for index = 1, #jails do -- Loop from 1 to the total items in "jails" table. local dist = getDistanceBetweenPoints2D ( x, y, jails [ index ] [ 1 ], jails [ index ] [ 2 ] ) -- Get the distance between the jail coordinates and the given coordinates. table.insert ( temp, { index = index, dist = dist } ) -- Insert it into our "temp" table. end table.sort ( -- Sort the "temp" table by lowest distance. temp, function ( a, b ) return ( ( a.dist or 0 ) < ( b.dist or 0 ) ) end ) return unpack ( jails [ temp [ 1 ].index ] ) -- Return coordinates from the nearest jail. end local copDirectionsColshape addEvent("copdirections", true) function copshops( ) if coptargets == 0 then coptargets = 1 for index = 1, #jails do local jailData = jails[ index ] marker[#marker+1] = createMarker ( jailData[ 1 ], jailData[ 2 ], jailData[ 3 ], "cylinder", 6, 0, 0, 255, 55 ) end local x, y, z = getElementPosition ( source ) local hx, hy, hz = getNearestDP ( x, y ) if hx and hy and hz then local copDirectionsBlip = createBlip ( hx, hy, hz , 30, 3, 0, 0, 255, 255, 50 ) copDirectionsColshape = createColSphere ( hx, hy, hz, 6 ) setElementParent ( copDirectionsBlip,copDirectionsColshape)-- child > parent setElementData ( copDirectionsColshape, "purpose", "copshop",false ) end end end addEventHandler("copdirections", root, copshops) --REMOVES POLICE STATION BLIPS FROM COPS RADAR AND THE MARKERS addEvent("clearcopdirections", true) function clearcopshops() if coptargets == 1 then coptargets = 0 if isElement(copDirectionsColshape) then destroyElement (copDirectionsColshape) -- + child = blip end for index = 1, #marker do local element = marker[index] if isElement(element) then destroyElement (element) end end end end addEventHandler("clearcopdirections", root, clearcopshops)
Et-win Posted August 15, 2014 Posted August 15, 2014 ^ There is no jails[][4] index? There are only 3
Moderators IIYAMA Posted August 15, 2014 Moderators Posted August 15, 2014 oh so it was already fixed? He called me 5 times on skype + voicemail of 10 mins, so I thought it wasn't fixed yet.
Et-win Posted August 15, 2014 Posted August 15, 2014 I lol'd, yes it's fixed. But I still don't know how because I can't find 'marker[4]' in the script, or he didn't post the whole script
3B00DG4MER Posted August 15, 2014 Author Posted August 15, 2014 ^There is no jails[][4] index? There are only 3 i added it
Moderators IIYAMA Posted August 15, 2014 Moderators Posted August 15, 2014 why? There is nothing there.
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