Jump to content

[help] Detect player fall from bike


LoPollo

Recommended Posts

I wanted to know the ways to detect when a player falls from a bike.

After some research i found 2 ways to detect it (both are untested, errors may occur: that's only the concept):

addEventHandler( "onClientPlayerDamage", root, 
	function(attacker, weapon, bodypart, loss)
		if getElementType( attacker ) == "vehicle" then
			--thus player has fallen
		end
	end
)

but i'm not sure if falling from a motorbike/bike ALWAYS damage the player (or ped if with "onClientPedDamage")

and

addEventHandler("onClientVehicleCollision", root,
    function(theHitElement, force, bodypart, collisionX, collisionY, collisionZ, normalX, normalY, normalZ, hitElementForce, model)
        local isSourceEqualToTheVehOfThePlayer = true --check for the localPlayer or the player or the ped etc
        if isSourceEqualToTheVehOfThePlayer then
        	--the event is called Before the fall if i remember correctly
        	--so check if after the event (50ms) the checked player has his vehicle
        	setTimer( 
				function(thePlayer, theVehicle) 
					if not getPedOccupiedVehicle( thePlayer ) then
						--our player is not a good driver
					end
				end
			, 50, 1, getVehicleOccupant( source ), source )
        end
    end
)

but i'm not sure if it is 100% correct and i'm sure it's not a "clean" way to solve the problem.

So the answer is: do falling from a bike always cause damage? and are there other ways to achieve this i'm not aware of? (maybe i didn't found the event for this)

also sorry for any english error

Link to comment

When a player "exits" the bike, the event onClientVehicleStartExit never gets called. I tried this and it worked: 

local startExit = false

addEventHandler("onClientVehicleStartExit", root, function(p)

	if p == localPlayer then
		if getVehicleType(source) == "BMX" then
			startExit = true
		else
			startExit = false
		end
	end
	
end)

addEventHandler("onClientVehicleExit", root, function(p)

	if p == localPlayer then
		if getVehicleType(source) == "BMX" and not startExit then
			outputChatBox("you just fell off")
		end		
		startExit = false
	end
	
end)

 

Link to comment

Hey,

I have a problem related to this topic. I want to detect collision when bmx hits an object. The problem is that handler "onClientVehicleCollision" not always works. Any suggestions? I was thinking about processLineOfSight but maybe there is better solution, Thanks in advance.

Edited by 2kristof2
Link to comment

 

28 minutes ago, 2kristof2 said:

The problem is that handler "onClientVehicleCollision" not always works.

What do you mean? The handler does not always detect collision, maybe with a particular kind of object? Do you think it could be a bug? I can't see any issue in the wiki page

29 minutes ago, 2kristof2 said:

I was thinking about processLineOfSight

Process line of sight require coordinates to work, how do you think you will get them?

 

Link to comment
Quote

What do you mean? The handler does not always detect collision, maybe with a particular kind of object? Do you think it could be a bug? I can't see any issue in the wiki page

It doesn't work on small jumps.

Quote

Process line of sight require coordinates to work, how do you think you will get them?

You attach the line near a player.

Link to comment
addEventHandler("onClientVehicleCollision", root,
	function(theHitElement, force, bodypart, collisionX, collisionY, collisionZ, normalX, normalY, normalZ, hitElementForce, model)
		if source == getPedOccupiedVehicle(localPlayer) then
			outputChatBox( "DBG ["..getTickCount().."]: Collision")
		end
	end
)

Using this function when i collide with my BMX with objects i always get the message in the chatbox. No matter if while jumping, falling etc. Tested with a BMX (lol) in Santa Maria Beach area. In the wiki page (i think when i am tired i am blind) there's this:

Issue ID Description
#7422 onClientVehicleCollision doesnt trigger when hitting some frozen objects

But i do not think this related to your problem.
 

So this bring me to think that maybe there's a condition in your event that prevents some code to be executed. Could you post your handler function?

Edited by LoPollo
bad english
Link to comment
  • 1 year later...
On 31/10/2016 at 12:18, pa3ck said:

When a player "exits" the bike, the event onClientVehicleStartExit never gets called. I tried this and it worked: 


local startExit = false

addEventHandler("onClientVehicleStartExit", root, function(p)

	if p == localPlayer then
		if getVehicleType(source) == "BMX" then
			startExit = true
		else
			startExit = false
		end
	end
	
end)

addEventHandler("onClientVehicleExit", root, function(p)

	if p == localPlayer then
		if getVehicleType(source) == "BMX" and not startExit then
			outputChatBox("you just fell off")
		end		
		startExit = false
	end
	
end)

 

 

 

Thank you!!! This helped me so much! :x

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