Jump to content

GUIGridList Help?


Xeno

Recommended Posts

Posted

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 :)

Posted

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
-- 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?

Posted

Yes, it does, do this, move the event handler down the button, into the function.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 

My in-game name: Jaysds1

Retired CMG Scripter

World Of Tanks GameMode (Open-Source): https://github.com/Jaysds1/mtasa-wot-gamemode

Online GUI-Editor (WIP): https://forum.mtasa.com/topic/47678-online-gui-editor/

 

sE5Qm.png

TiV3C.png

img.php?id=0&text=Lua%20Scripter

Posted

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.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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

Posted

You welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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