cokacola Posted May 7, 2012 Share Posted May 7, 2012 Hey guys, I quickly made up a little script to damage players in car accidents but the problem is it simply takes the vehicles damage of the player. The main problem with this is, if the player has 1 health and then breaks a headlight whilst the car is barely moving, the player will still be killed. I have a function(found it in my script, I think it came from the wiki) that can get the cars speed, but I am not entirely sure how to work it into this little script. Script for car damage: function vehicleLoss(loss) local thePlayer = getVehicleOccupant(source) if(thePlayer) then -- Check there is a player in the vehicle if(getElementData(thePlayer,"kcar") ~= true) then local th = getElementHealth(thePlayer)-tonumber(loss) if(th <= 0) then setElementHealth(thePlayer,0) else setElementHealth(thePlayer,th) end end end end addEventHandler("onVehicleDamage", getRootElement(), vehicleLoss) function kCar(plr,cmd) if(plr) then if(getElementData(plr,"kcar") == true) then setElementData(plr,"kcar","no") outputChatBox("You will now die in car accidents",plr) else setElementData(plr,"kcar",true) outputChatBox("You will no longer die in car accidents",plr) end end end addCommandHandler("kc",kCar) Little speed function I think I found on the wiki long ago: function getPlayerSpeed(player,mph) local velX,velY,velZ=getElementVelocity(getPedOccupiedVehicle(player) or player) return (velX^2+velY^2+velZ^2)^0.5*(mph and 100 or 161) end Now, while I might be able to work that out if I try some more, I'd also like to take rolling into consideration, so even if the vehicle isn't going incredibly fast, rolling down a hill could still kill the driver of the vehicle. Now, I am going to try some ideas if I can...right after I code the part that actually damages passengers(Don't worry, I know how to do this). Now, onto something slightly less important; I was playing on a server that added extra seats and such to the Nevada plane(probably a whole bunch of other vehicles too) I'd like to do something similar and was wondering how people go about coding this custom seats?(glue the player inside and work a mouse-movable camera script or something?) Link to comment
arezu Posted May 7, 2012 Share Posted May 7, 2012 If you use onClientVehicleCollision, then you can get the impact force. Look on wiki example. Link to comment
cokacola Posted May 7, 2012 Author Share Posted May 7, 2012 I tried this(one of many kinds of randomness) : function vehicleDamage(theHitElement, force, bodypart, collisionX, collisionY, collisionZ, velocityX, velocityY, velocityZ, hitElementForce, model) if(getElementData(player,"kcar") ~= true) then local fDamageMultiplier = getVehicleHandling(source).collisionDamageMultiplier local damage = force * fDamageMultiplier local perc = (damage/1000) * 100 local player = getVehicleOccupant(source) local newHealth = getElementHealth(player) - perc setElementHealth(player,newHealth) end end addEventHandler("onClientVehicleCollision", root, vehicleDamage) But I just die, even if I am stopped and reversing into a wall. Plus I cannot figure out a good ratio for damage to player damage. Any idea? Link to comment
X-SHADOW Posted May 7, 2012 Share Posted May 7, 2012 you want if the car hit wall or something let the player die ? -100 health ? Link to comment
cokacola Posted May 7, 2012 Author Share Posted May 7, 2012 Basically I want the player to be damaged a certain amount based on how fast the car is going(not at all if it isn't going to fast), whether or not it is rolling, how damaged the car is, etc. Link to comment
ben_wright Posted May 7, 2012 Share Posted May 7, 2012 https://forum.multitheftauto.com/viewtop ... 91&t=33798 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