Jump to content

Modify directly player loss dmg


Recommended Posts

  • Administrators

You could cancel the onPlayerDamage event and then deal damage based on attacker weapon / damage type.

This should give you a decent idea.

local damageTypes = { --table of damage types / weapons of which you want to adjust player damage dealt.
  {"Fall", 50}, --damage type, -health to deal
  {"Ranover", 75},
  {"Dildo", 500}
}

function customPlayerDamage(attacker, weapon, bodypart, loss)
  for i=1,#damageTypes do
    if weapon == damageTypes[i][1] then --if the current attacker's weapon/damage type is in damageTypes
       cancelEvent() --stops MTA handling of damage
       local playerHealth = getElementHealth(source) --get the players health (player is source of the event)
       setElementHealth(source, playerHealth - damageTypes[i][2]) --set it to current health minus the value in damageTypes
    end
  end
end
addEventHandler ( "onPlayerDamage", getRootElement (), customPlayerDamage )

For the damageTypes table, you can refer to the attacker weapon and damage types on the wiki.

Edited by LopSided_
Link to comment
1 hour ago, LopSided_ said:

You could cancel the onPlayerDamage event and then deal damage based on attacker weapon / damage type.

This should give you a decent idea.


local damageTypes = { --table of damage types / weapons of which you want to adjust player damage dealt.
  {"Fall", 50}, --damage type, -health to deal
  {"Ranover", 75},
  {"Dildo", 500}
}

function customPlayerDamage(attacker, weapon, bodypart, loss)
  for i=1,#damageTypes do
    if weapon == damageTypes[i][1] then --if the current attacker's weapon/damage type is in damageTypes
       cancelEvent() --stops MTA handling of damage
       local playerHealth = getElementHealth(source) --get the players health (player is source of the event)
       setElementHealth(source, playerHealth - damageTypes[i][2]) --set it to current health minus the value in damageTypes
    end
  end
end
addEventHandler ( "onPlayerDamage", getRootElement (), customPlayerDamage )

For the damageTypes table, you can refer to the attacker weapon and damage types on the wiki.

you can't cancel this event on server side to stop damage, you have to do this through client side.

Link to comment
  • Administrators

@Fist oh, wasn't aware of that.

Simple fix.

Also weapon/damage needed to be the ID not name

local damageTypes = { --table of damage types / weapons of which you want to adjust player damage dealt.
  {54, 50}, --damage type id/weapon id, -health to deal
  {50, 75},
  {10, 500}
}

function customPlayerDamage(attacker, weapon, bodypart, loss)
  for i=1,#damageTypes do
    if weapon == damageTypes[i][1] then --if the current attacker's weapon/damage type is in damageTypes
       cancelEvent() --stops MTA handling of damage
       local playerHealth = getElementHealth(source) --get the players health (player is source of the event)
       setElementHealth(source, playerHealth - damageTypes[i][2]) --set it to current health minus the value in damageTypes
    end
  end
end
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), customPlayerDamage )

 

Edited by LopSided_
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...