Jump to content

GUIGridList Help?


Xeno

Recommended Posts

I'm scripting a a GUIGridList at the moment, and I'v become stuck. This is a bit confusing but I dont know any simply way too say it -

I need it like, you select what you want on the table, and then you click the button once your item is selected and it spawns it for you.

vehList = guiCreateGridList ( 0.05, 0.10, 0.90, 0.77, true, window ) 
vehCol = guiGridListAddColumn ( vehList, "Vehicle", 0.60  ) 
bullet = guiGridListAddRow ( vehList ) 
guiGridListSetItemText ( vehList, bullet, vehCol, "Bullet  ", false, false ) 
takebutton = guiCreateButton(0.25,0.90,0.20,0.10,"Buy Car",true,window) 

Sorry if this is confusing.

I'd really appreciated it if you gave me so help :)

Link to comment

-- client side

vehList = guiCreateGridList ( 0.05, 0.10, 0.90, 0.77, true, window ) 
vehCol = guiGridListAddColumn ( vehList, "Vehicle", 0.60  ) 
bullet = guiGridListAddRow ( vehList ) 
guiGridListSetItemText ( vehList, bullet, vehCol, "Bullet", false, false ) 
takebutton = guiCreateButton(0.25,0.90,0.20,0.10,"Buy Car",true,window) 
  
function spawnTheCar() 
   local row,col = guiGridListGetSelectedItem(vehList) 
   if row and col and row ~= -1 and col ~= -1 then 
   local vehicleName = guiGridListGetItemText(vehList, row, col) 
           triggerServerEvent("vehicle_spawn",getLocalPlayer(),getVehicleModelFromName(vehicleName)) 
      end 
end 
addEventHandler("onClientGUIClick",takeButton,spawnTheCar,false) 

-- server side

addEvent("vehicle_spawn",true) 
addEventHandler("vehicle_spawn",root, 
function (model) 
  local x, y, z = getElementPosition(source) 
  local theVehicle = createVehicle(tonumber(model), x, y, z) 
end) 

Try with that.

Link to comment
-- client side
vehList = guiCreateGridList ( 0.05, 0.10, 0.90, 0.77, true, window ) 
vehCol = guiGridListAddColumn ( vehList, "Vehicle", 0.60  ) 
bullet = guiGridListAddRow ( vehList ) 
guiGridListSetItemText ( vehList, bullet, vehCol, "Bullet", false, false ) 
takebutton = guiCreateButton(0.25,0.90,0.20,0.10,"Buy Car",true,window) 
  
function spawnTheCar() 
   local row,col = guiGridListGetSelectedItem(vehList) 
   if row and col and row ~= -1 and col ~= -1 then 
   local vehicleName = guiGridListGetItemText(vehList, row, col) 
           triggerServerEvent("vehicle_spawn",getLocalPlayer(),getVehicleModelFromName(vehicleName)) 
      end 
end 
addEventHandler("onClientGUIClick",takeButton,spawnTheCar,false) 

-- server side

addEvent("vehicle_spawn",true) 
addEventHandler("vehicle_spawn",root, 
function (model) 
  local x, y, z = getElementPosition(source) 
  local theVehicle = createVehicle(tonumber(model), x, y, z) 
end) 

Try with that.

addEventHandler("onClientGUIClick",takeButton,spawnTheCar,false) 

I get a bad argument at the onClientGUIClick. Sorry, I didn't mention , the GUI is in a function, does that matter?

Link to comment

I'm not sure, but it might work:

addEventHandler("onClientGUIClick",takeButton,spawnTheCar,false) 
function spawnTheCar() 
   local row,col = guiGridListGetSelectedItem(vehList) 
   if row and col and row ~= -1 and col ~= -1 then 
   local vehicleName = guiGridListGetItemText(vehList, row, col) 
           triggerServerEvent("vehicle_spawn",getLocalPlayer(),getVehicleModelFromName(vehicleName)) 
      end 
end 

Link to comment
Jaysd1, if you want to increase your post count, please don't do it here, you are confusing him, that's the same as I'd but moved the event handler before the function, which won't work.

Umm... I get no errors and the GUI works perfectly, everything looks normal. But the car isn't spawned when the Bullet Row is selected and the button is press :l

Shall I post my hole client side script?

EDIT: Never mind! I did it! :D

There was a problem with the createVehicle so I made it like this :

theVehicle = createVehicle ( 432, -706.60431, 965.87689, 12.39362 ) 

And it worked! Thank you very much Castillo :3

And thanks for putting input in Jay lawl.

<3

EDIT2: Fixed

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