Jump to content

guiGridListGetItemData is nil


Recommended Posts

Hey,

I have this GUI and try to get a grid 0variable with guiGridListGetItemData.

But the target (which is localed as the grid data - line 33) is always nil even if i select a item

Can somebody help?

function create_grid(player)
if getElementType(player) == "player" and player == g_Player then	
GUIEditor_Window = {}
GUIEditor_Button = {}
GUIEditor_Grid = {}
 
GUIEditor_Window[1] = guiCreateWindow(0.0113,0.1644,0.2804,0.3772,"Police Jobs",true)
guiWindowSetSizable(GUIEditor_Window[1],false)
GUIEditor_Grid[1] = guiCreateGridList(12,27,301,260,false,GUIEditor_Window[1])
guiGridListSetSelectionMode(GUIEditor_Grid[1],2)
playername = guiGridListAddColumn(GUIEditor_Grid[1],"Player",0.5)
wantedlevel = guiGridListAddColumn(GUIEditor_Grid[1],"Wanted Level",0.5)
GUIEditor_Button[1] = guiCreateButton(13,297,110,20,"Set as target",false,GUIEditor_Window[1])
addEventHandler("onClientGUIClick", GUIEditor_Button[1], doit, false)
GUIEditor_Button[2] = guiCreateButton(201,297,110,20,"Cancel",false,GUIEditor_Window[1])
addEventHandler("onClientGUIClick", GUIEditor_Button[2], doit, false)
showCursor(true)
end
 
end
 
 
addEvent( "show_grid", true )
addEventHandler( "show_grid", getRootElement(), create_grid)
 
local target
local row,col
function doit ()
   row,col = guiGridListGetSelectedItem(GUIEditor_Grid[1])
outputChatBox(tostring(row).. " " ..tostring(col))
if row and col and row ~= -1 and col ~= -1 then
 
        target = guiGridListGetItemData(GUIEditor_Grid[1],row,col)
local myBlip = createBlipAttachedTo ( test, 41,0,0,0,255,g_Player)
outputChatBox(tostring(target))
outputChatBox(getPlayerName(target))
outputChatBox("The target was set as a waypoint icon on the map",255,0,0,g_Player)
triggerServerEvent ( "setTarget", getRootElement(),getLocalPlayer(), target ) 
guiSetVisible(GUIEditor_Window[1], false)	
showCursor(false)
     openend = false
end
end

Link to comment

Ah, i forget the SetItemData part ;)

Okay now i have this code to fill my grid:

function fill_list(thePlayer,level)
local row = guiGridListAddRow (grid)
guiGridListSetItemText ( grid, row, playername, getPlayerName(thePlayer), false, false )
guiGridListSetItemText ( grid, row, wantedlevel, tostring(level), false, false )
guiGridListSetItemData(grid,row,playername,getPlayerName(thePlayer))
guiGridListSetItemData(grid,row,wantedlevel,tostring(level))
 
 
end

It's not nil :)

But now i have another problem:

function doit ()
local row,col = guiGridListGetSelectedItem(grid)
outputChatBox(tostring(row).. " " ..tostring(col)) --Print the row and the col
if row and col and row ~= -1 and col ~= -1 then
 
local target = guiGridListGetItemData(grid,row,col) --Set the target
 
local myBlip = createBlipAttachedTo ( tostring(target), 41,0,0,0,255,g_Player)  
outputChatBox(tostring(target).. " was set as a waypoint icon on the map",255,0,0,g_Player)
triggerServerEvent ( "setTarget", getRootElement(),getLocalPlayer(), target ) 
guiSetVisible(GUIEditor_Window[1], false)	
showCursor(false)
     openend = false
end
end

I got a bad argument at line 8, in the myBlip line.

Idk if (tostring(target)) is right...

Maybe one of you have a idea?

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