Jump to content

Problems :/


xeon17

Recommended Posts

Hello there,

Trying already two days to fix a problem with markers of my fast food shop. Markers are created but there is a bug with the event handler,when a player hit the marker nothing happen.

function addMarkers ( res ) 
        for k=1, #markers do 
  
                local lower = 0 
                if markers[k][5] == 0 then 
                        lower = 1 
                end 
        marker[k] = createMarker ( markers[k][1], markers[k][2], markers[k][3]-lower, "cylinder", 1, 255, 0, 0, 200 ) 
        setElementDimension(marker[k], markers[k][4]) 
                setElementInterior(marker[k], markers[k][5])    
        end 
        for k=1, #blips do      
  
                createBlip( blips[k][1], blips[k][2], blips[k][3], blips[k][4], 1, 0, 0, 0, 255, 111, 180 ) 
                ped[k] = createPed ( peds[k][7], peds[k][1], peds[k][2], peds[k][3] ) 
  
                setElementDimension( ped[k], peds[k][4] ) 
                setElementInterior( ped[k], peds[k][5] ) 
                setPedRotation ( ped[k], peds[k][6] ) 
                setTimer( setElementHealth, 50, 0, ped[k], 100 ) 
    end 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), addMarkers ) 
  
function showT( hitPlayer ,matchingDimension) 
        local counter = 1 
        for k=1, #markers do 
                if source == marker[k] then 
                        counter = k 
                end 
        end 
        if matchingDimension then 
                triggerClientEvent( hitPlayer, "showGUI", getRootElement(), hitPlayer, markers[counter][6] ) 
         end 
end 
addEventHandler( "onMarkerHit", marker[k], showT ) 

Error at line 36 , attempt to index global ''''marker'' (a nil value)

Hope someone can help me please.

EDIT: Forgot to share the markers script

marker = {} 
ped = {} 
markers = { 
  
    { 373.9, -118.8, 1000.4, 5, 5 }, 
    { 373.9, -118.8, 1000.4, 11, 5 }, 
    { 373.9, -118.8, 1000.4, 10, 5 }, 
    { 373.9, -118.8, 1000.4, 9, 5 }, 
    { 373.9, -118.8, 1000.4, 7, 5 }, 
    { 373.9, -118.8, 1000.4, 6, 5 }, 
    { 373.9, -118.8, 1000.4, 4, 5 }, 
    { 373.9, -118.8, 1000.4, 0, 5 }, 
    { 373.9, -118.8, 1000.4, 1, 5 }, 
    { 373.9, -118.8, 1000.4, 8, 5 }, 
     
    { 369, -6, 1000.8515625, 2, 9 }, 
    { 369, -6, 1000.8515625, 1, 9 }, 
    { 369, -6, 1000.8515625, 5, 9 }, 
    { 369, -6, 1000.8515625, 9, 9 }, 
    { 369, -6, 1000.8515625, 10, 9 }, 
    { 369, -6, 1000.8515625, 11, 9 }, 
    { 369, -6, 1000.8515625, 8, 9 }, 
    { 369, -6, 1000.8515625, 6, 9 }, 
    { 369, -6, 1000.8515625, 7, 9 }, 
    { 369, -6, 1000.8515625, 4, 9 }, 
    { 369, -6, 1000.8515625, 3, 9 }, 
    { 369, -6, 1000.8515625, 0, 9 }, 
     
    { 375.6, -67.5, 1000.5, 0, 10 }, 
    { 375.6, -67.5, 1000.5, 1, 10 }, 
    { 375.6, -67.5, 1000.5, 5, 10 }, 
    { 375.6, -67.5, 1000.5, 6, 10 }, 
    { 375.6, -67.5, 1000.5, 7, 10 }, 
    { 375.6, -67.5, 1000.5, 8, 10 }, 
    { 375.6, -67.5, 1000.5, 9, 10 }, 
    { 375.6, -67.5, 1000.5, 2, 10 }, 
    { 375.6, -67.5, 1000.5, 3, 10 }, 
    { 375.6, -67.5, 1000.5, 4, 10 }, 
} 
  
peds = { 
  
    { 373.8, -117.27, 1000.4, 5, 5, 180, 155,  }, 
    { 373.8, -117.27, 1000.4, 11, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 10, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 9, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 7, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 6, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 4, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 0, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 1, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 8, 5, 180, 155 }, 
  
    { 369, -4.4, 1001.8, 2, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 1, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 5, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 9, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 10, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 11, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 8, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 6, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 7, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 4, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 3, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 0, 9, 180, 167 }, 
  
    { 376, -66, 1000.5, 0, 10, 180, 205 }, 
    { 376, -66, 1000.5, 1, 10, 180, 205 }, 
    { 376, -66, 1000.5, 5, 10, 180, 205 }, 
    { 376, -66, 1000.5, 6, 10, 180, 205 }, 
    { 376, -66, 1000.5, 7, 10, 180, 205 }, 
    { 376, -66, 1000.5, 8, 10, 180, 205 }, 
    { 376, -66, 1000.5, 9, 10, 180, 205 }, 
    { 376, -66, 1000.5, 2, 10, 180, 205 }, 
    { 376, -66, 1000.5, 3, 10, 180, 205 }, 
    { 376, -66, 1000.5, 4, 10, 180, 205 }, 
} 
  
blips = { 
  
    { 2105, -1808, 14, 29 }, 
    { 2084, 2224, 12, 29 }, 
    { 2352, 2532, 12, 29 }, 
    { -1721, 1359, 8, 29 }, 
    { -1809, 946, 25, 29 }, 
    { 203, -202, 2, 29 }, 
    { 2756, 2477, 12, 29 }, 
    { 1367, 249, 20, 29 }, 
    { 2333, 75, 26, 29 }, 
    { 2638, 1850, 12, 29 }, 
  
    { -2155, -2460, 31, 14 }, 
    { -1214, 1830, 42, 14 }, 
    { 929, -1353, 14, 14 }, 
    { 2393, 2042, 12, 14 }, 
    { 2838, 2407, 12, 14 }, 
    { 2102, 2229, 12, 14 }, 
    { 2638, 1671, 12, 14 }, 
    { -1816, 619, 36, 14 }, 
    { -2671, 258, 5, 14 }, 
    { 2398, -1899, 14, 14 }, 
    { 2420, -1510, 25, 14 }, 
    { 173, 1177, 15, 14 }, 
  
    { 812, -1616, 14, 10 }, 
    { 1199, -918, 44, 10 }, 
    { 2367, 2071, 12, 10 }, 
    { 2473, 2034, 12, 10 }, 
    { 1872, 2042, 12, 10 }, 
    { 2170, 2796, 12, 10 }, 
    { 1158, 2072, 12, 10 }, 
    { -1912, 828, 36, 10 }, 
    { -2356, 1008, 51, 10 }, 
    { -2336, -167, 36, 10 }, 
} 

Link to comment
function addMarkers ( res ) 
            for k=1, #markers do 
      
                    local lower = 0 
                    if markers[k][5] == 0 then 
                            lower = 1 
                    end 
            marker[k] = createMarker ( markers[k][1], markers[k][2], markers[k][3]-lower, "cylinder", 1, 255, 0, 0, 200 ) 
            addEventHandler( "onMarkerHit", marker[k], showGUI ) 
            setElementDimension(marker[k], markers[k][4]) 
                    setElementInterior(marker[k], markers[k][5])   
            end 
            for k=1, #blips do     
      
                    createBlip( blips[k][1], blips[k][2], blips[k][3], blips[k][4], 1, 0, 0, 0, 255, 111, 180 ) 
                    ped[k] = createPed ( peds[k][7], peds[k][1], peds[k][2], peds[k][3] ) 
      
                    setElementDimension( ped[k], peds[k][4] ) 
                    setElementInterior( ped[k], peds[k][5] ) 
                    setPedRotation ( ped[k], peds[k][6] ) 
                    setTimer( setElementHealth, 50, 0, ped[k], 100 ) 
        end 
    end 
    addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), addMarkers ) 
      
    function showT( hitPlayer ,matchingDimension) 
            local counter = 1 
            for k=1, #markers do 
                    if source == marker[k] then 
                            counter = k 
                    end 
            end 
            if matchingDimension then 
                    triggerClientEvent( hitPlayer, "showGUI", getRootElement(), hitPlayer, markers[counter][6] ) 
             end 
    end 
    addEventHandler( "onMarkerHit", marker[k], showT ) 

This will work, maybe try it.

Link to comment
function showGUI( hitPlayer, matchingDimension ) 
    local counter = 1 
    for k=1, #markers do 
        if source == marker[k] then 
            counter = k 
        end 
            triggerClientEvent( hitPlayer, "showGUI", getRootElement(), hitPlayer, markers[counter][6] ) 
        end 
    end 
addEventHandler( "onMarkerHit", marker[k], showGUI ) 
  

try this replace it with ShowT

Link to comment
triggerClientEvent( hitPlayer, "showGUI", getRootElement(), hitPlayer, markers[counter][6] ) 

[counter] and [6] are not defined in the table

I fixed it already.

triggerClientEvent( "showGUI", resourceRoot,hitPlayer) 

should work good

But this still no fix my problem...

Link to comment

I did it at the moment :)

--[[---------------------------------------------------- 
-- server script main 
-- @author Banex & XeoN 
-- @update 22/09/2014 
----------------------------------------------------]]-- 
  
  
--local Health = getElementHealth(source) 
  
addEvent("Low",true)  
addEventHandler("Low",root,  
function() 
--  if Helth < 100 then 
        if ( getPlayerMoney (source) >= 2 ) then 
            takePlayerMoney(source, 2) 
            playSoundFrontEnd ( source, 1   ) 
            outputChatBox("Small snack purchased for $ 2!",source,0,255,0) 
            setElementHealth ( source, getElementHealth(source) + 20 ) 
        else 
            playSoundFrontEnd ( source,6 ) 
            outputChatBox("You do not have enough money!",source,255,0,0) 
        end 
--      else 
--          playSoundFrontEnd ( source, 1 ) 
--          outputChatBox("His life is already full!",source,255,0,0)    
--end 
end) 
  
addEvent("Medium",true)  
addEventHandler("Medium",root,  
function() 
--  if Helth < 100 then 
        if ( getPlayerMoney (source) >= 6 ) then 
            takePlayerMoney(source, 6) 
            playSoundFrontEnd ( source, 6   ) 
            outputChatBox("Medium snack purchased for $ 6!",source,0,255,0) 
            setElementHealth ( source, getElementHealth(source) + 20 ) 
        else 
            playSoundFrontEnd ( source, 1 ) 
            outputChatBox("You do not have enough money!",source,255,0,0) 
        end 
--      else 
--          playSoundFrontEnd ( source, 1 ) 
--          outputChatBox("His life is already full!",source,255,0,0)    
--end 
end) 
  
addEvent("Big",true)  
addEventHandler("Big",root,  
function() 
--  if Helth < 100 then 
        if ( getPlayerMoney (source) >= 10 ) then 
            takePlayerMoney(source, 10) 
            playSoundFrontEnd ( source, 6 ) 
            outputChatBox("big snack purchased for $ 2!",source,0,255,0) 
            setElementHealth ( source, getElementHealth(source) + 20 ) 
        else 
            playSoundFrontEnd ( source, 1 ) 
            outputChatBox("You do not have enough money!",source,255,0,0) 
        end 
--      else 
--          playSoundFrontEnd ( source, 1 ) 
--          outputChatBox("His life is already full!",source,255,0,0)    
--end 
end) 
  
  
function addMarkers ( res ) 
    for k=1, #markers do 
  
        local lower = 0 
        if markers[k][5] == 0 then 
            lower = 1 
        end 
        marker[k] = createMarker ( markers[k][1], markers[k][2], markers[k][3]-lower, "cylinder", 1, 255, 0, 0, 200 ) 
        setElementDimension(marker[k], markers[k][4]) 
        setElementInterior(marker[k], markers[k][5])     
    end 
    for k=1, #blips do   
  
        createBlip( blips[k][1], blips[k][2], blips[k][3], blips[k][4], 1, 0, 0, 0, 255, 111, 180 ) 
        ped[k] = createPed ( peds[k][7], peds[k][1], peds[k][2], peds[k][3] ) 
  
        setElementDimension( ped[k], peds[k][4] ) 
        setElementInterior( ped[k], peds[k][5] ) 
        setPedRotation ( ped[k], peds[k][6] ) 
                addEventHandler( "onMarkerHit", marker[k], showGUI ) 
    end 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), addMarkers ) 
  
  
function showGUI( hitPlayer, matchingDimension ) 
    local counter = 1 
    for k=1, #markers do 
        if source == marker[k] then 
            counter = k 
        end 
            triggerClientEvent( hitPlayer, "showGUI", getRootElement(), hitPlayer, markers[counter][6] ) 
        end 
    end 
  

This is the the full server script,without errors,but when player hit the marker nothing happen.

The util script is now:

--------------------------------------------------------------------------------------- 
-- Name:        Fastfood 
-- Developer:   mrbrutus 
-- Last edit:   2014-09-23 
-- License:     GNU (General public license) 
--------------------------------------------------------------------------------------- 
  
 marker = {} 
ped = {} 
markers = { 
  
    { 373.9, -118.8, 1000.4, 5, 5 }, 
    { 373.9, -118.8, 1000.4, 11, 5 }, 
    { 373.9, -118.8, 1000.4, 10, 5 }, 
    { 373.9, -118.8, 1000.4, 9, 5 }, 
    { 373.9, -118.8, 1000.4, 7, 5 }, 
    { 373.9, -118.8, 1000.4, 6, 5 }, 
    { 373.9, -118.8, 1000.4, 4, 5 }, 
    { 373.9, -118.8, 1000.4, 0, 5 }, 
    { 373.9, -118.8, 1000.4, 1, 5 }, 
    { 373.9, -118.8, 1000.4, 8, 5 }, 
     
    { 369, -6, 1000.8515625, 2, 9 }, 
    { 369, -6, 1000.8515625, 1, 9 }, 
    { 369, -6, 1000.8515625, 5, 9 }, 
    { 369, -6, 1000.8515625, 9, 9 }, 
    { 369, -6, 1000.8515625, 10, 9 }, 
    { 369, -6, 1000.8515625, 11, 9 }, 
    { 369, -6, 1000.8515625, 8, 9 }, 
    { 369, -6, 1000.8515625, 6, 9 }, 
    { 369, -6, 1000.8515625, 7, 9 }, 
    { 369, -6, 1000.8515625, 4, 9 }, 
    { 369, -6, 1000.8515625, 3, 9 }, 
    { 369, -6, 1000.8515625, 0, 9 }, 
     
    { 375.6, -67.5, 1000.5, 0, 10 }, 
    { 375.6, -67.5, 1000.5, 1, 10 }, 
    { 375.6, -67.5, 1000.5, 5, 10 }, 
    { 375.6, -67.5, 1000.5, 6, 10 }, 
    { 375.6, -67.5, 1000.5, 7, 10 }, 
    { 375.6, -67.5, 1000.5, 8, 10 }, 
    { 375.6, -67.5, 1000.5, 9, 10 }, 
    { 375.6, -67.5, 1000.5, 2, 10 }, 
    { 375.6, -67.5, 1000.5, 3, 10 }, 
    { 375.6, -67.5, 1000.5, 4, 10 }, 
} 
  
peds = { 
  
    { 373.8, -117.27, 1000.4, 5, 5, 180, 155,  }, 
    { 373.8, -117.27, 1000.4, 11, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 10, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 9, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 7, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 6, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 4, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 0, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 1, 5, 180, 155 }, 
    { 373.8, -117.27, 1000.4, 8, 5, 180, 155 }, 
  
    { 369, -4.4, 1001.8, 2, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 1, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 5, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 9, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 10, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 11, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 8, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 6, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 7, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 4, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 3, 9, 180, 167 }, 
    { 369, -4.4, 1001.8, 0, 9, 180, 167 }, 
  
    { 376, -66, 1000.5, 0, 10, 180, 205 }, 
    { 376, -66, 1000.5, 1, 10, 180, 205 }, 
    { 376, -66, 1000.5, 5, 10, 180, 205 }, 
    { 376, -66, 1000.5, 6, 10, 180, 205 }, 
    { 376, -66, 1000.5, 7, 10, 180, 205 }, 
    { 376, -66, 1000.5, 8, 10, 180, 205 }, 
    { 376, -66, 1000.5, 9, 10, 180, 205 }, 
    { 376, -66, 1000.5, 2, 10, 180, 205 }, 
    { 376, -66, 1000.5, 3, 10, 180, 205 }, 
    { 376, -66, 1000.5, 4, 10, 180, 205 }, 
} 
  
blips = { 
  
    { 2105, -1808, 14, 29 }, 
    { 2084, 2224, 12, 29 }, 
    { 2352, 2532, 12, 29 }, 
    { -1721, 1359, 8, 29 }, 
    { -1809, 946, 25, 29 }, 
    { 203, -202, 2, 29 }, 
    { 2756, 2477, 12, 29 }, 
    { 1367, 249, 20, 29 }, 
    { 2333, 75, 26, 29 }, 
    { 2638, 1850, 12, 29 }, 
  
    { -2155, -2460, 31, 14 }, 
    { -1214, 1830, 42, 14 }, 
    { 929, -1353, 14, 14 }, 
    { 2393, 2042, 12, 14 }, 
    { 2838, 2407, 12, 14 }, 
    { 2102, 2229, 12, 14 }, 
    { 2638, 1671, 12, 14 }, 
    { -1816, 619, 36, 14 }, 
    { -2671, 258, 5, 14 }, 
    { 2398, -1899, 14, 14 }, 
    { 2420, -1510, 25, 14 }, 
    { 173, 1177, 15, 14 }, 
  
    { 812, -1616, 14, 10 }, 
    { 1199, -918, 44, 10 }, 
    { 2367, 2071, 12, 10 }, 
    { 2473, 2034, 12, 10 }, 
    { 1872, 2042, 12, 10 }, 
    { 2170, 2796, 12, 10 }, 
    { 1158, 2072, 12, 10 }, 
    { -1912, 828, 36, 10 }, 
    { -2356, 1008, 51, 10 }, 
    { -2336, -167, 36, 10 }, 
} 

Client

  
--[[---------------------------------------------------- 
-- client script main 
-- @author Banex 
-- @update 22/09/2014 
----------------------------------------------------]]-- 
  
  
local sx,sy = guiGetScreenSize() 
local px,py = 1600,900 
local x,y =  (sx/px), (sy/py) 
local Menus = {  
{ "gfx/images/menu.png" }, 
{ "gfx/images/menu2.png" }, 
{ "gfx/images/menu3.png" } 
} 
local random = math.random(#Menus) 
local interiors = { [5] = true,[9] = true,[10] = true,[7] = true,[6] = true } 
  
function ShowGUI( hitPlayer ) 
    Background = guiCreateStaticImage(x*200, y*240, 606, 340,table.concat(Menus[random]), false) 
     
    Button2 = guiCreateStaticImage(370, 80, 130.32, 61.92,"gfx/images/button-low.png",false,Background) 
    Button3 = guiCreateStaticImage(320, 150, 213.96096, 61.9704, "gfx/images/button-mediun.png", false, Background) 
    Button4 = guiCreateStaticImage(380, 220, 100.2, 75.6, "gfx/images/button-big.png", false, Background) 
         
    Button22 = guiCreateStaticImage(370, 80, 130.32, 61.92,"gfx/images/button-low2.png",false,Background) 
    Button33 = guiCreateStaticImage(320, 150, 213.96096, 61.9704, "gfx/images/button-mediun2.png", false, Background) 
    Button44 = guiCreateStaticImage(380, 220, 100.2, 75.6, "gfx/images/button-big2.png", false, Background) 
         
    Close2 = guiCreateLabel(578,10,15,15,"✖", false, Background ) 
    Close = guiCreateLabel(580,8,15,15,"✖", false, Background ) 
         
    Button222 = guiCreateStaticImage(370, 80, 130.32, 61.92,"gfx/images/button.png",false,Background) 
    Button333 = guiCreateStaticImage(320, 150, 213.96096, 61.9704, "gfx/images/button.png", false, Background) 
    Button444 = guiCreateStaticImage(380, 220, 100.2, 75.6, "gfx/images/button.png", false, Background) 
         
    guiLabelSetColor(Close2,0,0,0) 
         
    guiSetVisible (Button22, false ) 
    guiSetVisible (Button33, false ) 
    guiSetVisible (Button44, false ) 
    guiSetVisible (Close2, false ) 
    showCursor( true ) 
end 
addEvent("showGUI",true) 
addEventHandler("showGUI",getRootElement(),ShowGUI) 

Link to comment

I tried only the client side, and now works perfectly

for k,v in ipairs (markers) do 
z = v[3] -1 
Marker = createMarker ( v[1], v[2], z, "cylinder", 1, 255, 0, 0, 200 ) 
addEventHandler('onClientMarkerHit', Marker, 
    function ( hitPlayer ) 
        if ( hitPlayer == localPlayer ) then 
            ShowGUI() 
        end 
    end 
) 
end 

but now I have another problem problem, when I click the button ✖ only hide the cursor.

    if ( source == Close ) or ( source == Close2 ) then 
        guiSetVisible (Background, false ) 
        showCursor ( false )  

Edited by Guest
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...