Xwad Posted August 26, 2015 Share Posted August 26, 2015 Hi i hahave made a script that changes the explosion demage on the skin 165 but its not working:/ pls help. function noob(attacker, weapon, loss, x, y, z, tyre) if (weapon == 51 and getElementModel(source) == 165) then setElementHealth(source,getElementHealth(source) - 5) cancelEvent() end end addEventHandler("onClientPlayerDamage", root, noob) Link to comment
KariiiM Posted August 26, 2015 Share Posted August 26, 2015 Try this addEventHandler("onClientPedDamage",root, function () if ( getElementModel(source) == 165) then cancelEvent() end end) Link to comment
Xwad Posted August 26, 2015 Author Share Posted August 26, 2015 its not working:/ But i dont want to cancel the event i just want to set that the explosion will make 5 hp demage on skin id 165 Link to comment
KariiiM Posted August 26, 2015 Share Posted August 26, 2015 Ah, my bad i understood you by wrong, try this i think thats what you need Do it ,at the client side because the event "onClientPlayerDamage" is client sided ! addEventHandler("onClientPlayerDamage", root, function (attacker, weapon, loss) if ( isElement ( attacker ) and weapon and attacker== localPlayer and getElementModel(source) == 165) then if (weapon == 51 and getElementModel(source) == 165) then cancelEvent() setElementHealth(source,getElementHealth(source) - 5) end end end) Link to comment
Moderators IIYAMA Posted August 26, 2015 Moderators Share Posted August 26, 2015 You have to add the health loss, before you set the new health. local newHealth = getElementHealth(source) + loss - 5 if newHealth > 0 then setElementHealth(source,newHealth ) else setElementHealth(source,0) end And not to forget, put the handler on the localPlayer. addEventHandler("onClientPlayerDamage", localPlayer, You can't set the health of a remote player with success, only the localPlayer as source can give correct result. and attacker== localPlayer The attacker can also be a vehicle. getElementType(attacker) == "player" Link to comment
Xwad Posted August 26, 2015 Author Share Posted August 26, 2015 KariiiM i testet it but it still not works. IIYAMA you mean add to that script? addEventHandler("onClientPlayerDamage", root, function (attacker, weapon, loss) if ( isElement ( attacker ) and weapon and attacker== localPlayer and getElementModel(source) == 165) then if (weapon == 51 and getElementModel(source) == 165) then cancelEvent() setElementHealth(source,getElementHealth(source) - 5) end end end) Link to comment
Moderators IIYAMA Posted August 27, 2015 Moderators Share Posted August 27, 2015 Add(new stuff), replace(that look a like) and remove.(strike) Link to comment
Xwad Posted August 28, 2015 Author Share Posted August 28, 2015 is it now good? local newHealth = getElementHealth(source) + loss - 5 function setHP(attacker, weapon, loss) if getElementType(attacker) == "player" if (weapon == 51 and getElementModel(source) == 165) then if newHealth > 0 then setElementHealth(source,newHealth ) else setElementHealth(source,0) end end end addEventHandler("onClientPlayerDamage", localPlayer, setHP ) Link to comment
Moderators IIYAMA Posted August 28, 2015 Moderators Share Posted August 28, 2015 (edited) no, you missed placed it. Try this: (not tested) addEventHandler("onClientPlayerDamage", localPlayer, function (attacker, weapon, loss) -- source is the player that got damaged. if isElement ( attacker ) and weapon == 51 and getElementType(attacker) == "player" and getElementModel(source) == 165 then local oldHealth = getElementHealth(source) local newHealth = oldHealth + loss - 5 if newHealth > 0 then setElementHealth(source,newHealth ) cancelEvent() elseif oldHealth > 0 then setElementHealth(source,0) end end end) Make sure you are wearing skin 165, when somebody attacks you. Edited August 28, 2015 by Guest Link to comment
Xwad Posted August 28, 2015 Author Share Posted August 28, 2015 its working but there are sopme bugs. I changed the 51 id to 30 (ak47) and shooted the id 165 skin player with the gun. It was working but if i shoted the legs or the head then the player was healed not demaged pls help:/ Maybe need i define bodyparts? its only damaging on the torso. Link to comment
Moderators IIYAMA Posted August 28, 2015 Moderators Share Posted August 28, 2015 Yea, you should have. You can't just leave an argument open. Last time it was using the bodypart as loss. addEventHandler("onClientPlayerDamage", localPlayer, function (attacker, weapon,bodypart, loss) -- source is the player that got damaged. if isElement ( attacker ) and weapon == 51 and getElementType(attacker) == "player" and getElementModel(source) == 165 then local oldHealth = getElementHealth(source) local newHealth = oldHealth + loss - 5 if newHealth > 0 then setElementHealth(source,newHealth ) cancelEvent() elseif oldHealth > 0 then setElementHealth(source,0) end end end) Link to comment
Xwad Posted August 28, 2015 Author Share Posted August 28, 2015 Its working now! thanks a lot IIYAMA!!! Link to comment
Xwad Posted August 28, 2015 Author Share Posted August 28, 2015 Last question. why is it not working if add more weapons? if isElement ( attacker ) and weapon == 30 and weapon == 22 and weapon == 28 and weapon == 29 and getElementType(attacker) == "player" and getElementModel(source) == 165 then Link to comment
Moderators IIYAMA Posted August 28, 2015 Moderators Share Posted August 28, 2015 because the variable "weapon" can contain only one number. And "and" mean AND and not OR. Put it exactly like this: if isElement ( attacker ) and (weapon == 30 or weapon == 22 or weapon == 28 or weapon == 29) -- between (), because it have to be 1 result. and getElementType(attacker) == "player" and getElementModel(source) == 165 then 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