johny46 Posted May 22, 2013 Share Posted May 22, 2013 Hi. I've made a resource, which adds a Health column to the scoreboard. It gets updated on onPlayerSpawn and onPlayerDamage events. It works quite well, but it doesn't react to slapping, simply Slap doesn't call the onPlayerDamage event. Is there any other way to check whether player's health has changed? Of course other than getting the player's health every second and comparing it for changes If not, maybe you could consider adding such event to MTA? Link to comment
Castillo Posted May 22, 2013 Share Posted May 22, 2013 There isn't an event, but you could trigger one each time you change health ( e.g: on slap ). Link to comment
Jacob Lenn Posted May 22, 2013 Share Posted May 22, 2013 onClientRender getElementHealth setElementData Isnt it better to use this functions? Link to comment
johny46 Posted May 22, 2013 Author Share Posted May 22, 2013 Wouldn't it spam my server a lot? I guess onClientRender is triggered very often. Solidsnake, I didn't know that we are able to create our own events, thanks! I'll have to look further into it tomorrow. PS. Cześć Link to comment
Moderators IIYAMA Posted May 23, 2013 Moderators Share Posted May 23, 2013 Wouldn't it spam my server a lot? I guess onClientRender is triggered very often. and use getTickcount() to reduce data overclow. getTickCount() Link to comment
Schlammy Posted May 23, 2013 Share Posted May 23, 2013 Using Table Try this (but debug first i made it in 2 Minutes without checking for bugs or else) -- Pleas add [TiLex Produkt] as commentary to your script while using this addEvent("onPlayerHealthChange", true) local playerOldHealthTable = {} function healthChangedTriggerFunction() setTimer(function() local playerTable = getElementsByType("player") for index, player in ipairs(playerTable) do local oldLive = playerOldHealthTable[player] if oldLive and (oldLive > 0) then local curLive = getElementHealth(player) if not (curLive == oldLive) then local changedlive = 0 if (curLive > oldLive) then changedlive = (curLive - oldLive) else changedlive = (oldLive - curLive) end triggerEvent ( "onPlayerHealthChange", player, player, curLive, oldLive, changedlive) -- trigger Event playerOldHealthTable[player] = curLive end else playerOldHealthTable[player] = (getElementHealth(player)) end end end, 500, 0) end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), healthChangedTriggerFunction) -- EXAMPEL FUNKTION FOR EVENT function healthChanged(player, newHealth, oldHealth, changedLive) -- Live changed. Here some stuff outputChatBox("Your Live had changed from " ..tostring(oldHealth).. " to " ..tostring(newHealth)), player, 255, 0, 0) end addEventHandler("onPlayerHealthChange", getRootElement(), healthChanged) EventName: onPlayerHealthChange Parameters: element Player, int newhealth, int oldHealth, int howManyHealthChanged [sERVERSIDE] Link to comment
johny46 Posted May 25, 2013 Author Share Posted May 25, 2013 Thanks for help. I appreciate your solutions, especially Schlammy's one, but it's too much overcomplicated for my simple needs. I followed the Solidsnake14's idea and I just do setElementData(player,"Health",getElementHealth(player)) every time I slap a player. Works without any problem as of now Again thanks for your replies Link to comment
waves Posted August 16, 2023 Share Posted August 16, 2023 On 22/05/2013 at 23:18, Jacob Lenn said: onClientRender getElementHealth setElementData Isnt it better to use this functions? onClientRender in combination with setElementData is never good. 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