Artisz Posted November 13, 2016 Share Posted November 13, 2016 Hi! I have a faction panel, and I want to do that I have a list of faction vehicles with label, and when I click one of these, give me informations of the clicked vehicle. With the members(players) I can do it, because there is a getPlayerFromName. But with vehicles how can I do this? Link to comment
Artisz Posted November 13, 2016 Author Share Posted November 13, 2016 But it's just the name. I need the vehicle. So what I can write after the getVehicleName? getVehicleName(WHAT?) Link to comment
iPrestege Posted November 13, 2016 Share Posted November 13, 2016 May you can explain that more clear? Link to comment
pa3ck Posted November 13, 2016 Share Posted November 13, 2016 Show us the code where you populate the list of the faction vehicles. Link to comment
Artisz Posted November 13, 2016 Author Share Posted November 13, 2016 Sorry I cant show you the code now, because I am in collage now. So. I have loop, where I have the vehicles. If it has an elementdata, what is: veh.faction = 1, then create a label with the string, what is the vehicle name(Inferno). It is like a gridlist. And I want to do that when I click on the gridlist's one label, show me some informations from the vehicle. I do it with the members. I use guiGetText, and getPlayerFromName, and I got the player, so I can get the clicked player's elementdata, etc. But with vehicles how can I do this. SorrySorry for my English. Link to comment
LoPollo Posted November 13, 2016 Share Posted November 13, 2016 (edited) So your labels are identified from the faction number? And the faction number of the veh is that number You can loop all the vehs looking for the one where the elementData about faction of the current veh is equal to the number of the faction clicked Here's an example local factionID = 3 --example of the id of the faction veh we have to find for k,theVehicle in pairs(factionsVehicles) do if getElementData( theVehicle, "faction" ) == factionID then --we got our veh break end end --enclosing this in a func: function getVehicleFromFactionID(theFactionID) for k,theVehicle in pairs(factionsVehicles) do if getElementData( theVehicle, "faction" ) == factionID then return theVehicle end end return false end let me know if this idea is correct Edited November 13, 2016 by LoPollo Link to comment
Artisz Posted November 17, 2016 Author Share Posted November 17, 2016 I have a label gridlist: for k, v in ipairs( getElementsByType( "vehicle" ) ) do local name = getVehicleName(v) lbl4[k] = {} ay4 = ay4 + 24 lbl4[k][1] = guiCreateLabel( 10, ay4, 150, 45, tostring(name), false, scrollpane4) end And I want that I click on the vehicle name, from the gridlist, get the vehicle, and it's elementdata addEventHandler( "onClientGUIClick", lbl4[k][1], function() local vehName = guiGetText(source) vehID = guiCreateLabel( 590, 200, 150, 45, "Vehicle ID:"..tostring(getElementData(vehName,"veh.dbID")), false, staticPanel) end) But It's of course, not working, because it don't give me the element, just it's name. How cen I get the element? Link to comment
LoPollo Posted November 17, 2016 Share Posted November 17, 2016 (edited) Just an idea, but if we bind the label element directly to the veh? Something like this for k, v in ipairs( getElementsByType( "vehicle" ) ) do local name = getVehicleName(v) lbl4[k] = {} ay4 = ay4 + 24 lbl4[k][1] = guiCreateLabel( 10, ay4, 150, 45, tostring(name), false, scrollpane4) lbl4[k][2] = v --"bind" it using tables end addEventHandler( "onClientGUIClick", lbl4[k][1], function() local vehName = guiGetText(source) local theVehicle = lbl4[k][2] --here's the veh vehID = guiCreateLabel( 590, 200, 150, 45, "Vehicle ID:"..tostring(getElementData(vehName,"veh.dbID")), false, staticPanel) end) Note: as always it's untested Edited November 17, 2016 by LoPollo Link to comment
Artisz Posted November 17, 2016 Author Share Posted November 17, 2016 It looks like that it's working. Thank you! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now