GERgta Posted December 1, 2013 Share Posted December 1, 2013 Hello forums, I've made a script that makes all the damage clientside and multiplies it by 2. But something doesn't seem to work (player still recieves normal damage). The XML file is 100% okay, I think its the script. Can you guys help me? function damage ( attacker, weapon, bodypart, loss ) if attacker == localPlayer then local playerHealth = getElementHealth ( source ) local damageMult = loss * 2 local newHealth = playerHealth - damageMult if newHealth > 0 then cancelEvent() setElementHealth ( source, newHealth ) else cancelEvent() setElementHealth ( source, 0 ) end end end addEventHandler ( "onClientPlayerDamage", getRootElement(), damage ) Link to comment
tosfera Posted December 1, 2013 Share Posted December 1, 2013 Hello Forumuser, That's true, because you're checking if the newHealth is bigger than 0 so lets say... it is 15. Then you're cancel the event, and set its health. Try switching the setElementHealth and cancelEvent(). Link to comment
DiSaMe Posted December 1, 2013 Share Posted December 1, 2013 if attacker == localPlayer then Therefore the rest of the function is only executed if local player is the one who inflicted damage. And since client-side scripts can only control the health of local player, this results in script actually taking effect if player causes damage to himself/herself. Link to comment
GERgta Posted December 1, 2013 Author Share Posted December 1, 2013 Therefore the rest of the function is only executed if local player is the one who inflicted damage. I had to make it like this, cause else its not really clientside. And since client-side scripts can only control the health of local player, this results in script actually taking effect if player causes damage to himself/herself. Oh man, I forgot about it... Well that's unfortunate. I also tried to connect this with some serverside events (triggerServerEvent), but it didn't seem to work right (Event not found?). I could make this completely serverside, but then it wouldn't be a clientside hit-detection. Is there any solution for this? Link to comment
Chronic Posted December 1, 2013 Share Posted December 1, 2013 Did you use addEvent addEventHandler on server side? If you didn't, that's the reason the event isn't found. Link to comment
GERgta Posted December 1, 2013 Author Share Posted December 1, 2013 (edited) Did you use addEvent addEventHandler I will try this now, thanks for the fast reply. EDIT: Oh my god, thank you. Everything seems to work now! Source: You are allowed to claim it as yours, etc, etc. But don't sell it, not this little piece of coding! Have fun! Client.lua: function damage ( attacker, weapon, bodypart, loss ) if attacker == localPlayer then local playerHealth = getElementHealth ( source ) local damageMult = loss * 2 local newHealth = playerHealth - damageMult triggerServerEvent ( "damage", source, attacker, weapon, bodypart, loss, newHealth ) cancelEvent() end end addEventHandler ( "onClientPlayerDamage", getRootElement(), damage ) function pedDamage ( attacker, weapon, bodypart, loss ) if attacker == localPlayer then local playerHealth = getElementHealth ( source ) local normalDamage = playerHealth - loss if bodypart == 9 and normalDamage > 0 then setElementHealth ( source, 1 ) else if normalDamage > 0 then local damageMult = loss * 10 local newHealth = playerHealth - damageMult triggerServerEvent ( "damage", source, attacker, weapon, bodypart, loss, newHealth ) cancelEvent() end end end end Server.lua: addEvent ( "damage", true ) function damage ( attacker, weapon, bodypart, loss, newHealth ) if newHealth > 0 then setElementHealth ( source, newHealth ) else killPed ( source, attacker, weapon, bodypart ) end end addEventHandler ( "damage", getRootElement(), damage ) Edited December 1, 2013 by Guest 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