Jump to content

getElementType?


TrickyTommy

Recommended Posts

Hi!
If i hit a marker an if node should run. It runs, but it is very strange, and i don't know what the problem is.  I would like to make a script, that if i hit the marker(s) with a vehicle that is given in the table, it would just put something into debugscript 3, i can continue from there.
What i have done so far:
 

driveInAndGo = {596, 597, 598, 416, 533}

function borderMarkerHit(client) --if driveInAndGo[getElementModel(client)]?
	if getElementType (client) == "vehicle" then
		outputDebugString ("the hit element was a vehicle")
	else
		outputDebugString ("the hit element was not a vehicle")
	end --getVehicleSirensOn
end
addEventHandler ("onMarkerHit", borderMarkerLeaveLS, borderMarkerHit)
addEventHandler ("onMarkerHit", borderMarkerLeaveSF, borderMarkerHit)

The strange thing is, that either the message that says hit element was a vehicle and hit element was not a vehicle gets displayed...
I would continue it like this:
if hit element was vehicle and it's ID is in the driveInAndGo table, something would happen.

Link to comment
driveInAndGo = {596, 597, 598, 416, 533}

function borderMarkerHit(client) --if driveInAndGo[getElementModel(client)]?
	if getElementType (client) == "player" then
		local Vehicle = getPedOccupiedVehicle(client)
		if Vehicle then
			outputDebugString ("the hit element was a vehicle")
		else
			outputDebugString ("the hit element was not a vehicle")
		end
	end	 --getVehicleSirensOn
end
addEventHandler ("onMarkerHit", borderMarkerLeaveLS, borderMarkerHit)
addEventHandler ("onMarkerHit", borderMarkerLeaveSF, borderMarkerHit)

 

  • Thanks 1
Link to comment
  • Moderators

Because this:

driveInAndGo = {596, 597, 598, 416, 533}

Is the same as:

driveInAndGo = {[1] = 596, [2] = 597, [3] = 598, [4] = 416, [5] = 533}

 

You only don't see the index fields.

[<index>] = <data>

 

local data = driveInAndGo[index] 

print(data)

 

true = yes, false = no
 

if true then

--do stuff

else -- false or nil

--do other stuff

end

 

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