TrickyTommy

getElementType?

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.

Share this post


Link to post
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

Share this post


Link to post
📋

    driveInAndGo = {[596] = true, [597] = true, [598] = true, [416] = true, [533] = true}
📋

    if driveInAndGo[getElementModel(Vehicle)] then

 

Share this post


Link to post

thanks... but why do i need the brackets and the other stuff? on vehicle id list page there are no brackets and equalation marks and booleans just vehicle ids...

Share this post


Link to post

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

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.