Jump to content

ipairs


Mark0

Recommended Posts

so;e help guys

bad argument #1 to 'ipairs' (table expected,got nil)

local marker = createMarker( 1552.4996337891, -1677.3264160156, 15.1953125, "Cylinder", 1.5, 0, 0, 255, 150) 
     
function createskinGui()     
windowjob = guiCreateWindow(0.335,0.14,0.3963,0.6817,"Police job",true) 
infomemo = guiCreateMemo(0.0347,0.0611,0.9369,0.3667,"Job information",true,windowjob) 
skinsgrid = guiCreateGridList(0.0347,0.4841,0.9369,0.313,true,windowjob) 
guiGridListSetSelectionMode(skinsgrid,2) 
_skins = guiGridListAddColumn(skinsgrid,"Skins",0.-- s8) -->
takebtn = guiCreateButton(0.2492,0.8289,0.5047,0.0562,"Take Job",true,windowjob) 
Closebtn = guiCreateButton(0.2492,0.9095,0.5047,0.0562,"Close",true,windowjob) 
infolbl = guiCreateLabel(0.2681,0.4279,0.4637,0.0538,"Choose your skin :",true,windowjob) 
guiLabelSetColor(infolbl,0,0,255) 
guiLabelSetVerticalAlign(infolbl,"center") 
guiLabelSetHorizontalAlign(infolbl,"center",false) 
guiSetFont(infolbl,"default-bold-small") 
for index, skin in ipairs(skins) do 
        local row = guiGridListAddRow (skinsgrid) 
        guiGridListSetItemText ( skinsgrid, row, _skins, tostring(skin), false, false ) 
end 
showCursor(true) 
end  
  
addEventHandler("onClientGUIClick", root, 
function () 
        if (source == takebtn) then 
            local row,col = guiGridListGetSelectedItem(skinsgrid) 
            if (row and col and row ~= -1 and col ~= -1) then 
                local skinName = guiGridListGetItemText(skinsgrid, row, 1) 
                if skinName == "police 1" then 
                    setElementModel(getLocalPlayer(), 280) 
                elseif skinName == "police 2" then 
                    setElementModel(getLocalPlayer(),281)                             
                    end 
            else 
                outputChatBox("Please,select a skin of the list.",255,0,0) 
            end 
            elseif (source == closebtn) then 
             triggerEvent("closeWindow", localPlayer ) 
        end 
end 
) 
  
function SAPDjob( hitElement ) 
        if ( hitElement == localPlayer ) then 
                createskinGui ( hitElement ) 
                if ( windowjob ~= nil ) then 
                    guiSetVisible ( windowjob, true ) 
                    showCursor ( true ) 
                    guiSetInputEnabled ( true ) 
                end 
        end 
end 
        addEventHandler("onClientMarkerHit", marker, SAPDjob) 
          
        function FBIjobleave(leaveElement) 
             if getElementType(leaveElement) == "player" and (leaveElement == localPlayer) then 
                  if guiGetVisible(windowjob) then 
                       guiSetVisible(windowjob, false) 
                       showCursor(false) 
                        
                  end 
             end 
        end 
        addEventHandler("onClientMarkerLeave", marker, SAPDjobleave) 
          
        function joinTeam() 
             triggerServerEvent("setSAPD",localPlayer) 
             guiSetVisible(windowjob, false) 
             showCursor(false) 
        end 
        addEventHandler("onClientGUIClick", takebtn , joinTeam, false) 
          
        function removeSAPDWindow() 
             guiSetVisible(windowjob, false) 
             showCursor(false) 
        end 
        addEventHandler("onClientGUIClick", Closebtn , removeSAPDWindow, false) 
    

Link to comment
bad argument #1 to 'ipairs' (table expected,got nil) 

The error identifies itself, You don't have a table called "skins", that all.

Though you don't need to create the gui every time you hit the marker, just create it when the resource start and hide it with guiSetVisible, and when you hit the marker show it with guiSetVisible again.

Also setElementModel should be used server side, or only you will see your skin, other won't.

Link to comment

so this is not the table ??

addEventHandler("onClientGUIClick", root, 
function () 
        if (source == takebtn) then 
            local row,col = guiGridListGetSelectedItem(skinsgrid) 
            if (row and col and row ~= -1 and col ~= -1) then 
                local skinName = guiGridListGetItemText(skinsgrid, row, 1) 
                if skinName == "police 1" then 
                    setElementModel(getLocalPlayer(), 280) 
                elseif skinName == "police 2" then 
                    setElementModel(getLocalPlayer(),281)                             
                    end 
            else 
                outputChatBox("Please,select a skin of the list.",255,0,0) 
            end 
            elseif (source == closebtn) then 
             triggerEvent("closeWindow", localPlayer ) 
        end 
end 
) 

Link to comment

i have problems at join team too

100:bad argument @'addEventHandler' [expected element ar argument 2,got nil ]

94:bad argument @'addEventHandler' [expected element ar argument 2,got nil ]

local marker = createMarker( 1552.4996337891, -1677.3264160156, 15.1953125, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker1 = createMarker( 2241.8999023438, 2435.8999023438, 9.8000001907349, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker2 = createMarker( -2129, -2481.3999023438, 29.60000038147, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker3 = createMarker( -1616.9000244141, 681, 6.0999999046326, "Cylinder", 1.5, 0, 0, 255, 150)   
local marker4 = createMarker( -216.5, 978, 18.5, "Cylinder", 1.5, 0, 0, 255, 150) 
     
local skins = {"police 1", "police 2", "police 3", "police 4", "police 5", "police 6"} 
     
function createskinGui()     
windowjob = guiCreateWindow(0.335,0.14,0.3963,0.6817,"Police job",true) 
infomemo = guiCreateMemo(0.0347,0.0611,0.9369,0.3667,"Job information",true,windowjob) 
skinsgrid = guiCreateGridList(0.0347,0.4841,0.9369,0.313,true,windowjob) 
guiGridListSetSelectionMode(skinsgrid,2) 
_skins = guiGridListAddColumn(skinsgrid,"Skins",0.-- s8) -->
takebtn = guiCreateButton(0.2492,0.8289,0.5047,0.0562,"Take Job",true,windowjob) 
Closebtn = guiCreateButton(0.2492,0.9095,0.5047,0.0562,"Close",true,windowjob) 
infolbl = guiCreateLabel(0.2681,0.4279,0.4637,0.0538,"Choose your skin :",true,windowjob) 
guiLabelSetColor(infolbl,0,0,255) 
guiLabelSetVerticalAlign(infolbl,"center") 
guiLabelSetHorizontalAlign(infolbl,"center",false) 
guiSetFont(infolbl,"default-bold-small") 
for index, skin in ipairs(skins) do 
        local row = guiGridListAddRow (skinsgrid) 
        guiGridListSetItemText ( skinsgrid, row, _skins, tostring(skin), false, false ) 
end 
showCursor(true) 
end  
  
addEventHandler("onClientGUIClick", root, 
function () 
        if (source == takebtn) then 
            local row,col = guiGridListGetSelectedItem(skinsgrid) 
            if (row and col and row ~= -1 and col ~= -1) then 
                local skinName = guiGridListGetItemText(skinsgrid, row, 1) 
                if skinName == "police 1" then 
                    setElementModel(getLocalPlayer(), 280) 
                elseif skinName == "police 2" then 
                    setElementModel(getLocalPlayer(),281) 
                    elseif skinName == "police 3" then 
                        setElementModel(getLocalPlayer(), 282) 
                        elseif skinName == "police 4" then 
                            setElementModel(getLocalPlayer(), 283) 
                            elseif skinName == "police 5" then 
                                setElementModel(getLocalPlayer(),284) 
                                elseif skinName == "police 6" then 
                                 setElementModel(getLocalPlayer(), 288)                             
                    end 
                    triggerEvent("closeWindow", localPlayer ) 
            else 
                outputChatBox("Please,select a skin of the list.",255,0,0) 
            end 
            elseif (source == closebtn) then 
             triggerEvent("closeWindow", localPlayer ) 
        end 
end 
) 
  
function SAPDjob( hitElement ) 
        if ( hitElement == localPlayer ) then 
                createskinGui ( hitElement ) 
                if ( windowjob ~= nil ) then 
                    guiSetVisible ( windowjob, true ) 
                    showCursor ( true ) 
                    guiSetInputEnabled ( true ) 
                end 
        end 
end 
        addEventHandler("onClientMarkerHit", marker, SAPDjob) 
        addEventHandler("onClientMarkerHit", marker1, SAPDjob) 
        addEventHandler("onClientMarkerHit", marker2, SAPDjob) 
        addEventHandler("onClientMarkerHit", marker3, SAPDjob) 
        addEventHandler("onClientMarkerHit", marker4, SAPDjob) 
          
        function SAPDjobleave(leaveElement) 
             if getElementType(leaveElement) == "player" and (leaveElement == localPlayer) then 
                  if guiGetVisible(windowjob) then 
                       guiSetVisible(windowjob, false) 
                       showCursor(false) 
                        
                  end 
             end 
        end 
        addEventHandler("onClientMarkerLeave", marker, SAPDjobleave) 
        addEventHandler("onClientMarkerLeave", marker1, SAPDjobleave) 
        addEventHandler("onClientMarkerLeave", marker2, SAPDjobleave) 
        addEventHandler("onClientMarkerLeave", marker3, SAPDjobleave) 
        addEventHandler("onClientMarkerLeave", marker4, SAPDjobleave) 
          
        function joinTeam() 
             triggerServerEvent("setSAPD",localPlayer) 
             guiSetVisible(windowjob, false) 
             showCursor(false) 
        end 
        addEventHandler("onClientGUIClick", takebtn , joinTeam, false) 
          
        function removeSAPDWindow() 
             guiSetVisible(windowjob, false) 
             showCursor(false) 
        end 
        addEventHandler("onClientGUIClick", Closebtn , removeSAPDWindow, false) 
    

Link to comment

please note that Lua is case sensitive, try this:

local marker = createMarker( 1552.4996337891, -1677.3264160156, 15.1953125, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker1 = createMarker( 2241.8999023438, 2435.8999023438, 9.8000001907349, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker2 = createMarker( -2129, -2481.3999023438, 29.60000038147, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker3 = createMarker( -1616.9000244141, 681, 6.0999999046326, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker4 = createMarker( -216.5, 978, 18.5, "Cylinder", 1.5, 0, 0, 255, 150) 
    
local skins = {"police 1", "police 2", "police 3", "police 4", "police 5", "police 6"} 
    
function createskinGui()   
windowjob = guiCreateWindow(0.335,0.14,0.3963,0.6817,"Police job",true) 
infomemo = guiCreateMemo(0.0347,0.0611,0.9369,0.3667,"Job information",true,windowjob) 
skinsgrid = guiCreateGridList(0.0347,0.4841,0.9369,0.313,true,windowjob) 
guiGridListSetSelectionMode(skinsgrid,2) 
_skins = guiGridListAddColumn(skinsgrid,"Skins",0.35) -- 
takebtn = guiCreateButton(0.2492,0.8289,0.5047,0.0562,"Take Job",true,windowjob) 
Closebtn = guiCreateButton(0.2492,0.9095,0.5047,0.0562,"Close",true,windowjob) 
infolbl = guiCreateLabel(0.2681,0.4279,0.4637,0.0538,"Choose your skin :",true,windowjob) 
guiLabelSetColor(infolbl,0,0,255) 
guiLabelSetVerticalAlign(infolbl,"center") 
guiLabelSetHorizontalAlign(infolbl,"center",false) 
guiSetFont(infolbl,"default-bold-small") 
for index, skin in ipairs(skins) do 
        local row = guiGridListAddRow (skinsgrid) 
        guiGridListSetItemText ( skinsgrid, row, _skins, tostring(skin), false, false ) 
end 
showCursor(true) 
end 
  
addEventHandler("onClientGUIClick", root, 
function () 
        if (source == takebtn) then 
            local row,col = guiGridListGetSelectedItem(skinsgrid) 
            if (row and col and row ~= -1 and col ~= -1) then 
                local skinName = guiGridListGetItemText(skinsgrid, row, 1) 
                if skinName == "police 1" then 
                    setElementModel(getLocalPlayer(), 280) 
                elseif skinName == "police 2" then 
                    setElementModel(getLocalPlayer(),281) 
                    elseif skinName == "police 3" then 
                        setElementModel(getLocalPlayer(), 282) 
                        elseif skinName == "police 4" then 
                            setElementModel(getLocalPlayer(), 283) 
                            elseif skinName == "police 5" then 
                                setElementModel(getLocalPlayer(),284) 
                                elseif skinName == "police 6" then 
                                 setElementModel(getLocalPlayer(), 288)                             
                    end 
                    triggerEvent("closeWindow", localPlayer ) 
            else 
                outputChatBox("Please,select a skin of the list.",255,0,0) 
            end 
            elseif (source == closebtn) then 
             triggerEvent("closeWindow", localPlayer ) 
        end 
end 
) 
  
function SAPDjob( hitElement ) 
        if ( hitElement == localPlayer ) then 
                createskinGui ( hitElement ) 
                if ( windowjob ~= nil ) then 
                    guiSetVisible ( windowjob, true ) 
                    showCursor ( true ) 
                    guiSetInputEnabled ( true ) 
                end 
        end 
end 
        addEventHandler("onClientMarkerHit", marker, SAPDjob) 
        addEventHandler("onClientMarkerHit", marker1, SAPDjob) 
        addEventHandler("onClientMarkerHit", marker2, SAPDjob) 
        addEventHandler("onClientMarkerHit", marker3, SAPDjob) 
        addEventHandler("onClientMarkerHit", marker4, SAPDjob) 
          
        function SAPDjobleave(leaveElement) 
             if getElementType(leaveElement) == "player" and (leaveElement == localPlayer) then 
                  if guiGetVisible(windowjob) then 
                       guiSetVisible(windowjob, false) 
                       showCursor(false) 
                        
                  end 
             end 
        end 
        addEventHandler("onClientMarkerLeave", marker, SAPDjobleave) 
        addEventHandler("onClientMarkerLeave", marker1, SAPDjobleave) 
        addEventHandler("onClientMarkerLeave", marker2, SAPDjobleave) 
        addEventHandler("onClientMarkerLeave", marker3, SAPDjobleave) 
        addEventHandler("onClientMarkerLeave", marker4, SAPDjobleave) 
          
        function joinTeam() 
             triggerServerEvent("setSAPD",localPlayer) 
             guiSetVisible(windowjob, false) 
             showCursor(false) 
        end 
        addEventHandler("onClientGUIClick", takebtn , joinTeam, false) 
          
        function removeSAPDWindow() 
             guiSetVisible(windowjob, false) 
             showCursor(false) 
        end 
        addEventHandler("onClientGUIClick", closebtn , removeSAPDWindow, false) 
    

EDITED!!!

Edited by Guest
Link to comment

Try

local marker = createMarker( 1552.4996337891, -1677.3264160156, 15.1953125, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker1 = createMarker( 2241.8999023438, 2435.8999023438, 9.8000001907349, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker2 = createMarker( -2129, -2481.3999023438, 29.60000038147, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker3 = createMarker( -1616.9000244141, 681, 6.0999999046326, "Cylinder", 1.5, 0, 0, 255, 150) 
local marker4 = createMarker( -216.5, 978, 18.5, "Cylinder", 1.5, 0, 0, 255, 150) 
    
local skins = {"police 1", "police 2", "police 3", "police 4", "police 5", "police 6"} 
  
windowjob = guiCreateWindow(0.335,0.14,0.3963,0.6817,"Police job",true) 
guiSetVisible(windowjob, false) 
infomemo = guiCreateMemo(0.0347,0.0611,0.9369,0.3667,"Job information",true,windowjob) 
skinsgrid = guiCreateGridList(0.0347,0.4841,0.9369,0.313,true,windowjob) 
guiGridListSetSelectionMode(skinsgrid,2) 
_skins = guiGridListAddColumn(skinsgrid,"Skins",0.-- s8) -->
takebtn = guiCreateButton(0.2492,0.8289,0.5047,0.0562,"Take Job",true,windowjob) 
Closebtn = guiCreateButton(0.2492,0.9095,0.5047,0.0562,"Close",true,windowjob) 
infolbl = guiCreateLabel(0.2681,0.4279,0.4637,0.0538,"Choose your skin :",true,windowjob) 
guiLabelSetColor(infolbl,0,0,255) 
guiLabelSetVerticalAlign(infolbl,"center") 
guiLabelSetHorizontalAlign(infolbl,"center",false) 
guiSetFont(infolbl,"default-bold-small") 
  
for index, skin in ipairs(skins) do 
     local row = guiGridListAddRow (skinsgrid) 
     guiGridListSetItemText(skinsgrid, row, _skins, tostring(skin), false, false) 
end 
  
addEventHandler("onClientGUIClick", root, 
function () 
     if (source == takebtn) then 
          local row,col = guiGridListGetSelectedItem(skinsgrid) 
          if (row and col and row ~= -1 and col ~= -1) then 
               local skinName = guiGridListGetItemText(skinsgrid, row, 1) 
               if skinName == "police 1" then 
                    setElementModel(getLocalPlayer(), 280) 
               elseif skinName == "police 2" then 
                    setElementModel(getLocalPlayer(),281) 
               elseif skinName == "police 3" then 
                    setElementModel(getLocalPlayer(), 282) 
               elseif skinName == "police 4" then 
                    setElementModel(getLocalPlayer(), 283) 
               elseif skinName == "police 5" then 
                    setElementModel(getLocalPlayer(),284) 
               elseif skinName == "police 6" then 
                    setElementModel(getLocalPlayer(), 288)                             
               end 
               triggerEvent("closeWindow", localPlayer) 
          else 
                outputChatBox("Please,select a skin of the list.",255,0,0) 
          end 
     elseif (source == closebtn) then 
          triggerEvent("closeWindow", localPlayer) 
     end 
end) 
  
function SAPDjob(hitElement) 
     if (hitElement == localPlayer) then 
          if not guiGetVisible(windowjob) then 
               guiSetVisible(windowjob, true) 
               showCursor(true) 
          end 
     end 
end 
addEventHandler("onClientMarkerHit", marker, SAPDjob) 
addEventHandler("onClientMarkerHit", marker1, SAPDjob) 
addEventHandler("onClientMarkerHit", marker2, SAPDjob) 
addEventHandler("onClientMarkerHit", marker3, SAPDjob) 
addEventHandler("onClientMarkerHit", marker4, SAPDjob) 
          
function SAPDjobleave(leaveElement) 
     if getElementType(leaveElement) == "player" and (leaveElement == localPlayer) then 
          if guiGetVisible(windowjob) then 
               guiSetVisible(windowjob, false) 
               showCursor(false) 
          end 
     end 
end 
addEventHandler("onClientMarkerLeave", marker, SAPDjobleave) 
addEventHandler("onClientMarkerLeave", marker1, SAPDjobleave) 
addEventHandler("onClientMarkerLeave", marker2, SAPDjobleave) 
addEventHandler("onClientMarkerLeave", marker3, SAPDjobleave) 
addEventHandler("onClientMarkerLeave", marker4, SAPDjobleave) 
  
function joinTeam() 
     triggerServerEvent("setSAPD",localPlayer) 
     guiSetVisible(windowjob, false) 
     showCursor(false) 
end 
addEventHandler("onClientGUIClick", takebtn , joinTeam, false) 
          
function removeSAPDWindow() 
     guiSetVisible(windowjob, false) 
     showCursor(false) 
end 
addEventHandler("onClientGUIClick", closebtn , removeSAPDWindow, false) 

Link to comment
your's TABL work but error at

95:bad argument @'addEventHandler' [expected element ar argument 2,got nil ]

Change this (Line 16)

Closebtn = guiCreateButton(0.2492,0.9095,0.5047,0.0562,"Close",true,windowjob) 

to

closebtn = guiCreateButton(0.2492,0.9095,0.5047,0.0562,"Close",true,windowjob) 

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