FatalTerror Posted October 31, 2011 Share Posted October 31, 2011 Hi community users, I start make a script for my server and I realized something. I will seek help on the wiki to find an event when two vehicles to touch. But I found nothing. If you know how do if a vehicle was touch by another and have the element of the other vehicle. Thx to help me Thanks ! Link to comment
12p Posted October 31, 2011 Share Posted October 31, 2011 You can create a variable (element data) on the vehicle called "colliding". Then, use a timer or onClientRender, and set its handler function to check if there is any element else in a rectangle colshape than the vehicle itself, and if that element is a vehicle. If the variable colliding was false, then set it to true and trigger the event you wish. Link to comment
FatalTerror Posted October 31, 2011 Author Share Posted October 31, 2011 Okay thanks, I thought there was something easier but it does not matter Link to comment
12p Posted November 1, 2011 Share Posted November 1, 2011 Oh. I remember something. May not be exactly what you want but it can help you: https://wiki.multitheftauto.com/wiki/OnVehicleDamage Link to comment
Phat Looser Posted November 4, 2011 Share Posted November 4, 2011 The colshape doesn't really work, since its bigger than the object itself. Link to comment
FatalTerror Posted November 4, 2011 Author Share Posted November 4, 2011 So how i do? Let me explain the idea from the beginning ... When the script starts, I have a random player. He will be the mouse. And all others will be cats, which first hit the mouse earns a certain amount. And I need the player who hit the mouse. Possible or not? Link to comment
arezu Posted November 4, 2011 Share Posted November 4, 2011 You can use mine which i made for DD once.. http://www.mediafire.com/?8nz9fjr1tcchiev you can study it if you want to learn and improve it (its not perfect), or just edit it a bit to fit your needs. Link to comment
Charlie_Jefferson Posted November 4, 2011 Share Posted November 4, 2011 onPlayerDamage. https://wiki.multitheftauto.com/wiki/OnPlayerDamage Link to comment
arezu Posted November 4, 2011 Share Posted November 4, 2011 onPlayerDamage.https://wiki.multitheftauto.com/wiki/OnPlayerDamage The player doesn't get damaged when crashing with vehicle. Link to comment
Charlie_Jefferson Posted November 4, 2011 Share Posted November 4, 2011 onPlayerDamage.https://wiki.multitheftauto.com/wiki/OnPlayerDamage The player doesn't get damaged when crashing with vehicle. So how i do?Let me explain the idea from the beginning ... When the script starts, I have a random player. He will be the mouse. And all others will be cats, which first hit the mouse earns a certain amount. And I need the player who hit the mouse. He didn't mention the vehicle here, so I thought he wanted the script different, instead. Link to comment
Phat Looser Posted November 4, 2011 Share Posted November 4, 2011 So how i do?Let me explain the idea from the beginning ... When the script starts, I have a random player. He will be the mouse. And all others will be cats, which first hit the mouse earns a certain amount. And I need the player who hit the mouse. Possible or not? Hard to say. It would require a lot of math. Link to comment
FatalTerror Posted November 5, 2011 Author Share Posted November 5, 2011 (edited) Hm i will test with onPlayerDamage()... When the mouse is damage, I need to know which player is closest to the mouse, but for her I'm lost addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() theMouse = getRandomPlayer() end) addEventHandler("onPlayerDamage", getRootElement(), function() if (source == theMouse)then local mX, mY, mZ = getElementPosition(theMouse) for i, thePlayer in ipairs ( getElementsByType("player") ) do local pX, pY, pZ = getElementPosition(thePlayer) local distance = getDistanceBetweenPoints3D ( mX, mY, mZ, pX, pY, pZ ) -- And after this i'm lost o_O end end end) I don't find other solution Edited November 5, 2011 by Guest Link to comment
Charlie_Jefferson Posted November 5, 2011 Share Posted November 5, 2011 It's onPlayerDamage, not onPlayerDomage. Link to comment
FatalTerror Posted November 5, 2011 Author Share Posted November 5, 2011 Oups noob fail ^^' Link to comment
arezu Posted November 5, 2011 Share Posted November 5, 2011 Hm i will test with onPlayerDamage()...When the mouse is damage, I need to know which player is closest to the mouse, but for her I'm lost addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() theMouse = getRandomPlayer() end) addEventHandler("onPlayerDamage", getRootElement(), function() if (source == theMouse)then local mX, mY, mZ = getElementPosition(theMouse) for i, thePlayer in ipairs ( getElementsByType("player") ) do local pX, pY, pZ = getElementPosition(thePlayer) local distance = getDistanceBetweenPoints3D ( mX, mY, mZ, pX, pY, pZ ) -- And after this i'm lost o_O end end end) I don't find other solution did you see my other post? i put a download link to my script that works the same way. Download it and use it... In my script i check which players gets damaged between each 50ms' and compare distances between the players that got damaged to the length of both vehicles being compared. Link to comment
50p Posted November 5, 2011 Share Posted November 5, 2011 ...In my script i check which players gets damaged between each 50ms' and compare distances between the players that got damaged to the length of both vehicles being compared. What about if there are 2 vehicles close to the hit player and the one that didn't hit is closer to the one that did hit? As you probably know by now, vehicle's position is the pivot position of the vehicle (most of the cars have it in the middle). So, distance between vehicle hitting from the front is longer than vehicle hitting from the side. Also, remember, vehicle size varies. Link to comment
FatalTerror Posted November 5, 2011 Author Share Posted November 5, 2011 You make the script even harder to do! It could possibly work if I detect two vehicles on the lives lost at the same time and if is close? Link to comment
arezu Posted November 5, 2011 Share Posted November 5, 2011 ...In my script i check which players gets damaged between each 50ms' and compare distances between the players that got damaged to the length of both vehicles being compared. What about if there are 2 vehicles close to the hit player and the one that didn't hit is closer to the one that did hit? As you probably know by now, vehicle's position is the pivot position of the vehicle (most of the cars have it in the middle). So, distance between vehicle hitting from the front is longer than vehicle hitting from the side. Also, remember, vehicle size varies. Yes, but its still pretty accurate because if the vehicle that was closer did not hit the vehicle, then its unlikely that it got damaged, which would mean that the vehicle that was further away and hit the "mouse" would be counted as the one that hit it. And still, using getElementBoundingBox is and calculating distance with rotation in 3d would still not be accurate because the vehicles are not rectangles, so the way i used is probably the best way without destroying ones brain. Link to comment
karlis Posted November 6, 2011 Share Posted November 6, 2011 The colshape doesn't really work, since its bigger than the object itself. not sure, but may work, how getElementColShape() works? if it doesn't, just use two processLineOfSight targeted at opposite vehicle ignoring your vehicle, and add up the vector length you got. if the added vector length is not much longer(+/-20cm) then distance between vehicles, you have got a hit. PS:as this is cpu intense, you should still use copshapes/watever to detect what vehicles to check. this should work on 90% of cases, that is when collision point in the line between vehicles is closest to opposite vehicle. Link to comment
Phat Looser Posted November 6, 2011 Share Posted November 6, 2011 The idea which checks the damage of both vehicles with a check if the damage could be done is the best. A fairly different idea is of course to do it client side, so that every cat checks whats in front of it (as seen above) which triggers when the line of sight gets disturbed. And the most cheater-and-lagger proof idea should be to create a collision check server side (for vehicles only, of course) which finds out which element hit which just by checking a 3D col shape. 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