Jump to content

[Help] Damage


Recommended Posts

So hey there, it's me again :D, how to make a guns (ex. deagle, sniper) damage, like if you hit the head you do 50 damage, if you hit in the legs you do 20 damage, chest 30 damage, arms 10 damage ? 

Edited by Skarbonke
Word correction :c
Link to comment
2 hours ago, xMKHx said:

local BodyPart = -- Add you Body part here for the shot part, Ex: Head, Leg
if bodypart == BodyPart then
if ( getPlayerWeapon(theAttacker) == wepID )
setElementHealth(theVectim, health )

 

local BodyPart = Head
if bodypart == BodyPart then
if ( getPlayerWeapon(theAttacker) == 24 )
then setElementHealth(theVectim, 50 ) end end

That gave me an error: 3: Bad argument "getPlayerWeapon"[expected ped at argument 1, got nil]

 

Link to comment

I didn't give you a full or working functions

If you want a working one use this

Its Server Side

addEvent "onPlayerHeadshot"

addEventHandler("onPlayerDamage", getRootElement(),
	function (attacker, weapon, bodypart, loss)
		if bodypart == 9 then
			if ( getPlayerWeapon(attacker) == wepID )
				killPed(source, attacker, weapon, bodypart)
			end
		end
	end
)

 

Link to comment
3 minutes ago, xMKHx said:

I didn't give you a full or working functions

If you want a working one use this

Its Server Side


addEvent "onPlayerHeadshot"

addEventHandler("onPlayerDamage", getRootElement(),
	function (attacker, weapon, bodypart, loss)
		if bodypart == 9 then
			if ( getPlayerWeapon(attacker) == wepID )
				killPed(source, attacker, weapon, bodypart)
			end
		end
	end
)

 

I don't need 1 shot kill :|

 

Link to comment

Try This

addEvent "onPlayerHeadshot"

addEventHandler("onPlayerDamage", getRootElement(),
	function (attacker, weapon, bodypart, loss)
		if bodypart == 9 then
			if ( getPlayerWeapon(attacker) == wepID 
        		setElementHealth(source -50)
			end
		end
	end
)

 

Link to comment
addEvent "onPlayerHeadshot"

addEventHandler("onPlayerDamage", getRootElement(),
	function (attacker, weapon, bodypart, loss)
		if bodypart == 9 then 
		     if then ( getPlayerWeapon(attacker) == 24 
        		setElementHealth(source -50)
			end
		end
	end
)

I get an error that says:5: unexpected symbol near "then" , and i can't get it right

Link to comment
addEventHandler("onPlayerDamage", getRootElement(),
	function (attacker, weapon, bodypart, loss)
		if bodypart == 9 then 
		     if getPlayerWeapon(attacker) == 24 then
        		setElementHealth(source, getElementHealth(source) -50)
			end
		end
	end
)

 

15 minutes ago, xMKHx said:

Try This


addEvent "onPlayerHeadshot"

addEventHandler("onPlayerDamage", getRootElement(),
	function (attacker, weapon, bodypart, loss)
		if bodypart == 9 then
			if ( getPlayerWeapon(attacker) == wepID 
        		setElementHealth(source -50)
			end
		end
	end
)

 

Man, please at least look at your code again and double check it, I know you're trying to help but try to make sure you're not making at least syntax mistakes..

Edited by pa3ck
  • Like 2
Link to comment
4 minutes ago, pa3ck said:

addEventHandler("onPlayerDamage", getRootElement(),
	function (attacker, weapon, bodypart, loss)
		if bodypart == 9 then 
		     if getPlayerWeapon(attacker) == 24 then
        		setElementHealth(source, getElementHealth(source) -50)
			end
		end
	end
)

 

Man, please at least look at your code again and double check it, I know you're trying to help but try to make sure you're not making at least syntax mistakes..

Thank u, it worked :3

Link to comment
local weaponTable = {
-- populate this list by adding weapons:
-- [weap_id] = { torso, ass, left_arm, right_arm, left_leg, right_leg, head }
 [24] = { 45, 35, 30, 30, 25, 25, 70 },
}


addEventHandler("onPlayerDamage", getRootElement(),
	function (attacker, weapon, bodypart, loss)
		if getElementType(attacker) == "player" and getPlayerWeapon(attacker) and weaponTable[ getPlayerWeapon(attacker) ] then
			setElementHealth(source, getElementHealth(source) - weaponTable[ getPlayerWeapon(attacker) ] [ bodyPart - 2] + loss)
		end
	end
)

You're welcome, you can use the following code to create a fully dynamic system. You can set each body part for each weapon using the weaponTable, just follow the current layout of weapon ID 24. 

Edited by pa3ck
  • Like 1
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...