Galactix Posted June 24, 2018 Share Posted June 24, 2018 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 Patrick Posted June 24, 2018 Moderators Share Posted June 24, 2018 addEventHandler ( "onClientPlayerDamage", getRootElement(), playerdamaged ) to addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), playerdamaged ) 1 Link to comment
Moderators IIYAMA Posted June 24, 2018 Moderators Share Posted June 24, 2018 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
Galactix Posted June 25, 2018 Author Share Posted June 25, 2018 On 24/06/2018 at 17:33, Patrick2562 said: addEventHandler ( "onClientPlayerDamage", getRootElement(), playerdamaged ) to addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), playerdamaged ) Thanks, that worked! Link to comment
Moderators Patrick Posted June 25, 2018 Moderators Share Posted June 25, 2018 19 minutes ago, Galactix said: Thanks, that worked! You are welcome! 1 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