Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding "onElementHealthChange" event #3136

Open
1 task done
Ad1mx opened this issue Jul 30, 2023 · 5 comments
Open
1 task done

adding "onElementHealthChange" event #3136

Ad1mx opened this issue Jul 30, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@Ad1mx
Copy link

Ad1mx commented Jul 30, 2023

Is your feature request related to a problem? Please describe.

When we setElementHealth to an element we should handle the event onElementHealthChange, but this event is not exist!
we have problems with this when we're using onPlayerDamage or onPlayerWasted on some features like respawn panel on player wasted, but when you use setElementHealth from another resource or a command you cant handle this with youre feature

Describe the solution you'd like

adding an event named onElementHealthChange (shared) handling setElementHealth function.

Describe alternatives you've considered

No response

Additional context

No response

Security Policy

  • I have read and understood the Security Policy and this issue is not about a cheat or security vulnerability.
@Ad1mx Ad1mx added the enhancement New feature or request label Jul 30, 2023
@gtkvba
Copy link

gtkvba commented Aug 1, 2023

There is no need for that. U can overwrite lua defined function to trigger your own event. Just like this:

_setElementHealth = setElementHealth 
-- wrapper
function setElementHealth(element,newHealth)
   _setElementHealth(element,newHealth)
   triggerEvent("yourCustomEvent",element,newHealth)
end 

--event somewhere else
local function handleElementHealthChange(newHealth)
   --stub
end 
addEvent("yourCustomEvent",true)
addEventHandler("yourCustomEvent",root,handleElementHealthChange)

Each call to setElementHealth will result firing an event.

@TracerDS
Copy link
Contributor

TracerDS commented Aug 2, 2023

the wrapper isn't a good idea since he will have to use exports to call setElementHealth from other resources... it's better if mta implement the event instead.

or just call triggerEvent whenever setElementHealth is used. No need to overwrite anything

@Xenius97
Copy link
Contributor

Xenius97 commented Aug 2, 2023

There is no need for that. U can overwrite lua defined function to trigger your own event. Just like this:

This is a wrong idea, events and exports are slower (and degrades performance more) compared to implementing it directly into MTA:SA.

@gtkvba
Copy link

gtkvba commented Aug 2, 2023

There is no need for that. U can overwrite lua defined function to trigger your own event. Just like this:

This is a wrong idea, events and exports are slower (and degrades performance more) compared to implementing it directly into MTA:SA.

In this case is not much computing on Lua VM side but reaching to MTA API, exports can be slow by the manner of how their work but events used properly are not slow and its better to use them instead. Measure performance by yourself and u will find it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants
@Xenius97 @TracerDS @Ad1mx @gtkvba and others