roaddog Posted February 25, 2015 Posted February 25, 2015 Due to this https://wiki.multitheftauto.com/wiki/On ... WeaponFire event does not work on melee weapon. How can I make a simple function that does the trick for it? I want to detect a player who hits an element using shovel weapon. Thanks. You gone learn today. I work my ass off, but I still can't pay tho.
JR10 Posted February 25, 2015 Posted February 25, 2015 Use onClientPlayerDamage. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
xeon17 Posted February 25, 2015 Posted February 25, 2015 Maybe onClientPlayerDamage? EDIT: JR10 was faster A unique GangWar gamemode waiting for you!Click here for more information.
roaddog Posted February 25, 2015 Author Posted February 25, 2015 No, I mean, The source of this event is the element that got damaged. You gone learn today. I work my ass off, but I still can't pay tho.
JR10 Posted February 25, 2015 Posted February 25, 2015 onClientPlayerDamage provides the attacker and his weapon as an argument. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
xeon17 Posted February 25, 2015 Posted February 25, 2015 And what's the problem? A unique GangWar gamemode waiting for you!Click here for more information.
roaddog Posted February 25, 2015 Author Posted February 25, 2015 the element is an object. I found this https://wiki.multitheftauto.com/wiki/On ... jectDamage, and I got an error says source is nil? eventho the element was created. function outputLoss(loss) if not isElement(source) then return end if getElementModel(source) ~= 897 then return end local oldHealth = getElementHealth(source) local hitX, hitY, hitZ = getElementPosition(source) setTimer(function() local newHealth = getElementHealth(source) outputChatBox("Real loss: "..(newHealth-oldHealth)) outputChatBox("Theoretical loss: "..loss) if getElementHealth(source) == 0 then destroyElement(source) createExplosion(hitX, hitY, hitZ, 8, true, -1.0, false) end end,100,1) end addEventHandler("onClientObjectDamage", root, outputLoss) You gone learn today. I work my ass off, but I still can't pay tho.
JR10 Posted February 25, 2015 Posted February 25, 2015 You're using source inside the timer function, source is only defined inside the handler function. Just define a player variable that points to the source. Or you can send the source as an argument to the timer function. function outputLoss(loss) if not isElement(source) then return end if getElementModel(source) ~= 897 then return end local oldHealth = getElementHealth(source) local hitX, hitY, hitZ = getElementPosition(source) local object = source setTimer(function() local newHealth = getElementHealth(object) outputChatBox("Real loss: "..(newHealth-oldHealth)) outputChatBox("Theoretical loss: "..loss) if getElementHealth(object) == 0 then destroyElement(object) createExplosion(hitX, hitY, hitZ, 8, true, -1.0, false) end end,100,1) end addEventHandler("onClientObjectDamage", root, outputLoss) Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
roaddog Posted February 25, 2015 Author Posted February 25, 2015 Thanks, It works o/ You gone learn today. I work my ass off, but I still can't pay tho.
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