Jump to content

[HELP] Weapon damage multiplier bug


Galactix

Recommended Posts

Hello everyone, I am using a damage multiplying table for my server and I just modified the script so that it works on both players and zombies, but I noticed a weird bug: I added an outputchatbox function and saw that the function triggers itself 1-3 times for a single shot, which results in ridiculous damage dealt (you almost oneshot a player using colt shooting him in the torso). How can I avoid that?

CLIENT SIDE

function playerdamaged ( attacker, weapon, bodypart )
	if getElementType ( source ) == "player" then
		if (getElementData (source, "zombie") == false) then
			triggerServerEvent ("multiplierplr", source, source, attacker, weapon, bodypart )			
		end
	end
end
addEventHandler ( "onClientPlayerDamage", getRootElement(), playerdamaged )

SERVER SIDE

local weaponTable = {
-- populate this list by adding weapons:
-- [weap_id] = { torso, ass, left_arm, right_arm, left_leg, right_leg, head }
 [1] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
 [22] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
  [23] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
   [24] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
    [25] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
	 [26] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
	  [27] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
	   [28] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
	    [29] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
		 [30] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
		  [31] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
		   [32] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
		    [33] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
			 [34] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25},
			  [38] = { 1.00, 0.80, 0.80, 0.80, 0.80, 0.80, 1.25}
				 
}

local weaponDmg = {
[1] = {999999}, --brassknuckles
[22] = {25}, --colt
 [23] = {40}, --silenced
  [24] = {70}, --deagle
   [25] = {10}, --shotgun
    [26] = {10}, --sawed-off
     [27] = {15}, --spaz
	  [28] = {20}, --uzi
	   [29] = {25}, --mp5
	    [30] = {30}, --ak47
		 [31] = {30}, --m4
		  [32] = {20}, --tec9
		   [33] = {75}, --rifle
			[34] = {125}, --sniper rifle
			 [38] = {140} --minigun
}

addEvent( "multiplierplr", true )
function Pheadhit ( player,attacker, weapon, bodypart)
if not (getElementData (attacker, "zombie") == true) then
		local bodyPartsDamageTable = weaponTable[ getPedWeapon (attacker) ] 
		local weaponDmgTable = weaponDmg [ getPedWeapon (attacker)]
		local damageMultiplier = bodyPartsDamageTable [ bodypart - 2]
				if ((damageMultiplier * weaponDmgTable [1]) > getElementHealth(player)) then
					killPed(player, attacker)
					outputChatBox("Hit!")
				else
					outputChatBox("Hit!")
					setElementHealth ( player, getElementHealth(player) -  (damageMultiplier * weaponDmgTable [1] ) )
					return
				end		
	end
end
addEventHandler( "multiplierplr", getRootElement(), Pheadhit )

 

Link to comment
  • Moderators

The health loss is already removed of the player his health data when this even is fired(not from the visual representation). Make sure you add the loss to the health data before you make your calculations.

Parameters

element attacker, int weapon, int bodypart [, float loss ]

LOSS

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