Jump to content

Need HElp !!


3B00DG4MER

Recommended Posts

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 
  

Link to comment
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) 
  
  
  

Link to comment
  • Moderators

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) 

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