Dretax Posted May 1, 2017 Share Posted May 1, 2017 https://wiki.multitheftauto.com/wiki/OnPlayerDamage I wish to modify the value "loss" manually. Is that possible for me to do? Link to comment
Administrators Lpsd Posted May 1, 2017 Administrators Share Posted May 1, 2017 (edited) 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 May 1, 2017 by LopSided_ Link to comment
Dretax Posted May 1, 2017 Author Share Posted May 1, 2017 I thought I would possibly need to use setElementHealth, that's what i started now. Thanks. Link to comment
Fist Posted May 1, 2017 Share Posted May 1, 2017 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 Lpsd Posted May 1, 2017 Administrators Share Posted May 1, 2017 (edited) @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 May 1, 2017 by LopSided_ 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