Jump to content

[HELP] Attached colsphare to vehicle


Recommended Posts

so i did something like that but im to stupid to make it working 
 

local stop = createColRectangle ( 2541, 2557, 10, 25 )

function enter ( targetElem, matchingDimension )
	getElementModel(targetElem) == 537 then 	
						
		outputChatBox (  "Train Stopped", getRootElement(), 255, 255, 109 )
	end
end
addEventHandler ( "onColShapeHit", stop, enter )

and error is in this line @Lergen

getElementModel(targetElem) == 537 then 
unexpected symbol near '=='
 
Link to comment

You can give this a try (I think you just forgot the "if" statement):

local stop = createColRectangle ( 2541, 2557, 10, 25 )

function enter ( targetElem, matchingDimension )
	 if getElementModel(targetElem) == 537 then 	
						
		outputChatBox (  "Train Stopped", getRootElement(), 255, 255, 109 )
	end
end
addEventHandler ( "onColShapeHit", stop, enter )

 

Edited by Lergen
Link to comment

so there is no errors now when i add IF but this not working... this is video 

when my train ( cuboid ) hit rectangle there is no output on that :/ 

https://streamable.com/hlmvld

even try to do this on MARKER but not working too :/ 

 

local marker = createMarker(2548.81494, 2573.95142, 14.99850-5, "cylinder", 15, 255, 0, 0, 50)

function enter ( targetElem, matchingDimension )
	if  getElementModel(targetElem) == 537 then
		outputChatBox (  "Train Stopped", root(), 255, 255, 109 )
	end
end
addEventHandler ( "onMarkerHit", marker, enter )

 

Link to comment

Can you give this a try? I gave it a test on my local server and it worked:

local marker = createMarker(2548.81494, 2573.95142, 14.99850-5, "cylinder", 15, 255, 0, 0, 50)

function enter ( targetElem, matchingDimension )
	if  getElementModel(targetElem) == 537 then
		outputChatBox (  "Train Stopped", root, 255, 255, 109 )
	end
end
addEventHandler ( "onMarkerHit", marker, enter )

 

Edited by Lergen
Link to comment

If I'm understanding right, you want to have it only trigger the chatbox if it's not a player driving it? It's a bit ad-hoc but you could try this:

local marker = createMarker(2548.81494, 2573.95142, 14.99850-5, "cylinder", 15, 255, 0, 0, 50)

function isVehicleEmpty( vehicle )
if not isElement( vehicle ) or getElementType( vehicle ) ~= "vehicle" then
		return true
		end
if getVehicleOccupant( vehicle, 0 ) then
		return false
		end
	return true
end

function enter ( targetElem, matchingDimension )
	if isVehicleEmpty(targetElem) == true and getElementModel(targetElem) == 537 then
		outputChatBox (  "Train Stopped", root, 255, 255, 109 )
	end
end
addEventHandler ( "onMarkerHit", marker, enter )

There's probably a better way of going about this, but this should only trigger the chatbox if the train has no driver.

 

Link to comment

no errors no working :~... 

 

To be clear and everyone understands what I want to do, so I have a train that runs by itself on the tracks and keeps going all by itself, and I just want to do at each station in the LS / SF / LV Marker where the train would he stopped for X time, but the first thing I wants to do is that when he hits the marker, although I have a message about it in this case, "Train Stopped", although even it does not work, the earlier solutions would work if I was driving this train, but it drives by itself so here's the problem. I gave it a cuboid that is "stuck" to the train and I wanted to do something on the principle that if the cuboid would hit the marker, but such things can't be done either ... I don't know what to do...

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