Jump to content

Get vehicle from a label


Artisz

Recommended Posts

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

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

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 by LoPollo
Link to comment

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

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