LoPollo Posted October 30, 2016 Share Posted October 30, 2016 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
Gravestone Posted October 31, 2016 Share Posted October 31, 2016 I don't know if there is any other way to detect the fall but I know that fall from bike does not always cause damage. Link to comment
LoPollo Posted October 31, 2016 Author Share Posted October 31, 2016 So i will use the second concept. Thank you for the information and the reply Link to comment
pa3ck Posted October 31, 2016 Share Posted October 31, 2016 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
LoPollo Posted October 31, 2016 Author Share Posted October 31, 2016 Using onClientVehicleExit works! As you said it gets called when falling from the bike. Thanks for you help too! Link to comment
pa3ck Posted October 31, 2016 Share Posted October 31, 2016 Yes, it gets called when falling from a bike, but onClientVehicleStartExit isn't. So basically if someone exits the bike and onClientVehicleStartExit never got executed, you know that they fell of the bike (or it got destroyed etc). Link to comment
2kristof2 Posted November 5, 2016 Share Posted November 5, 2016 (edited) 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 November 5, 2016 by 2kristof2 Link to comment
LoPollo Posted November 5, 2016 Author Share Posted November 5, 2016 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
2kristof2 Posted November 5, 2016 Share Posted November 5, 2016 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
LoPollo Posted November 6, 2016 Author Share Posted November 6, 2016 (edited) 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 November 6, 2016 by LoPollo bad english Link to comment
2kristof2 Posted November 6, 2016 Share Posted November 6, 2016 I was checking the collisions in exactly the same way. The handler doesn't trigger for example when I jump on an object with ID 3095. Anyway I don't really need this handler anymore. Thanks for your answer. Link to comment
FernandoMTA Posted December 15, 2017 Share Posted December 15, 2017 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! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now