Jump to content

Qustion


Best-Killer

Recommended Posts

How to number rows of grid list ??

i'm making a Vehicle Spawners by clicking button to spawn the vehicle 

look at the code you will understand what i want 

window = guiCreateWindow(550,560,200,200,"SAEG Vehicle Spawner",false) 
guiWindowSetSizable(window,false) 
grid = guiCreateGridList(0,20,190,170,false,window) 
guiGridListAddColumn(vehicle_selector_grid, "Key", 0.20) 
guiGridListAddColumn(vehicle_selector_grid, "Name", 0.65) 
guiWindowSetSizable(window,false)
guiSetVisible(window,false)



addEvent("showVehicle",true)
addEventHandler("showVehicle",rootElement,
function (vehiclesTable,marker)
theMarker = marker
guiSetVisible(window,true)
showCursor(false)
guiGridListClear(window)
for i,v in pairs(vehiclesTable) do
local row = guiGridListAddRow(window)
guiGridListSetItemText(window, row, 2, getVehicleNameFromModel(v), false, false)
  end
end)

Now i have gui & gridlist with vehicles name what the next i have to do guys ?? 

Note : i don't know how to add numbers to grid 

any one tell me what i have to use right now pls

Link to comment

thx dude ^^ 

guys now i got numbers .. ect 

i'll use that 

 

function spawnveh(button, press) 
      if(press) then 
        if(button == tostring(i)) then 
        triggerServerEvent("vehicle_spawn",client,client,getVehicleModelFromName(v),theMarker)
        exports["SAEGMessages"]:sendClientMessage("You "..tonumber(getVehicleModelFromName(v)).."e.",client,255,100,0)
end
end   

i'm using the msg for test ^^ i'm not geting the model id from name what is the problem ??

that full code          

local client = getLocalPlayer()
local rootElement = getRootElement()
local theMarker = nil









addEvent("showVehicle",true)
addEventHandler("showVehicle",rootElement,
function (vehiclesTable,marker)
theMarker = marker
guiSetVisible(window ,true)
showCursor(false)
guiGridListClear(grid )
for i,v in pairs(vehiclesTable) do
function spawnveh(button, press) 
      if(press) then 
        if(button == tostring(i)) then 
        triggerServerEvent("vehicle_spawn",client,client,getVehicleModelFromName(v),theMarker)
		exports["SAEGMessages"]:sendClientMessage("You "..tonumber(getVehicleModelFromName(v)).."e.",client,255,100,0)
end
end			
end
local row = guiGridListAddRow(grid )
guiGridListSetItemText(grid , row, 1, tostring(i), false, true)
guiGridListSetItemText(grid , row, 2, getVehicleNameFromModel(v), false, false)
addEventHandler("onClientKey", rootElement,spawnveh)
end
end)

 

Link to comment

I would check the names of variables (i would avoid "marker", "client" for example)

I also suggest a full rewrite of the code aligning it like this:

function someFunction(someParameter)
  local someVariable = doSomethingWith(someParameter)
  if someCondition then
    someVariable = doSomethingMoreWith(someVariable)
  end
  return someVariable
end

It will be readable and it will make our work much faster, easier and with fewer errors caused by not understanding the code, so more reliable

So your aligned code is: 

local client = getLocalPlayer()
local rootElement = getRootElement()
local theMarker = nil

addEvent("showVehicle",true)
addEventHandler("showVehicle",rootElement,
	function (vehiclesTable,marker)
		theMarker = marker
		guiSetVisible(window ,true)
		showCursor(false)
		guiGridListClear(grid )
		for i,v in pairs(vehiclesTable) do
			function spawnveh(button, press) 
      			if(press) then 
        			if(button == tostring(i)) then 
        				triggerServerEvent("vehicle_spawn",client,client,getVehicleModelFromName(v),theMarker)
						exports["SAEGMessages"]:sendClientMessage("You "..tonumber(getVehicleModelFromName(v)).."e.",client,255,100,0)
					end
				end			
			end
			local row = guiGridListAddRow(grid )
			guiGridListSetItemText(grid , row, 1, tostring(i), false, true)
			guiGridListSetItemText(grid , row, 2, getVehicleNameFromModel(v), false, false)
			addEventHandler("onClientKey", rootElement,spawnveh)
		end
	end
)

You are making a gui, use it instead of "onClientKey" !

What will happen if #vehiclesTable is more than 10 (0-9)? you won't be able to reach those.

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