Lorder Posted June 27, 2017 Share Posted June 27, 2017 How do I let a player get more damage from the head? @IIYAMA Link to comment
WorthlessCynomys Posted June 27, 2017 Share Posted June 27, 2017 You detect the hit, check if it was on the head, get the loss, multiply it for example then set the element's health. Link to comment
Lorder Posted June 27, 2017 Author Share Posted June 27, 2017 11 minutes ago, StormFighter said: You detect the hit, check if it was on the head, get the loss, multiply it for example then set the element's health. Give me wiki pls Link to comment
SheriFF Posted June 27, 2017 Share Posted June 27, 2017 --CLIENT local headshotDamage = 200 -- damage to take when the player is shot in the head function onPlayerHeadshot( attacker, _, bodypart ) if not ( bodypart == 9 ) then return false end -- check if the player has been hit in the head if not ( getElementType( attacker ) == "player" ) then return false end -- check if the attacker is a player local playerHealth = getElementHealth( source ) -- get the player's health setElementHealth( source, playerHealth - headshotDamage ) -- set the player's new health cancelEvent() --cancel the event end addEventHandler( "onClientPlayerDamage", getRootElement(), onPlayerHeadshot ) Link to comment
Lorder Posted June 27, 2017 Author Share Posted June 27, 2017 28 minutes ago, *BeaT* said: --CLIENT local headshotDamage = 200 -- damage to take when the player is shot in the head function onPlayerHeadshot( attacker, _, bodypart ) if not ( bodypart == 9 ) then return false end -- check if the player has been hit in the head if not ( getElementType( attacker ) == "player" ) then return false end -- check if the attacker is a player local playerHealth = getElementHealth( source ) -- get the player's health setElementHealth( source, playerHealth - headshotDamage ) -- set the player's new health cancelEvent() --cancel the event end addEventHandler( "onClientPlayerDamage", getRootElement(), onPlayerHeadshot ) I'm trying Thx <3 Link to comment
Lorder Posted June 27, 2017 Author Share Posted June 27, 2017 @*BeaT* It did not work Link to comment
Moderators IIYAMA Posted June 27, 2017 Moderators Share Posted June 27, 2017 function onPlayerHeadshot( attacker, _, bodypart, loss ) local playerOriginalHealth = getElementHealth( source ) + loss -- get the player's original health local newHealth = math.max(playerHealth - headshotDamage, 0) setElementHealth( localPlayer, newHealth) -- set the player's new health You have to add the loss back to get the original health. In this case it doesn't really matter since the damage is 200, but if you want to use values lower than 200, you will need to add that. If you put the health under 0, it will do strange things.(reset etc.) addEventHandler( "onClientPlayerDamage", localPlayer, onPlayerHeadshot ) You can't set other players their health with success, only that one of the localPlayer. So we only have to check the localPlayer. cancelEvent() No need for cancelling. Keep in mind that this can get bugged under strange occasions. Because of the GTA engine. If this doesn't work, post the updated code. Link to comment
Lorder Posted June 27, 2017 Author Share Posted June 27, 2017 @IIYAMA I did it right but I did not work local playerOriginalHealth = getElementHealth( source ) + loss -- get the player's original health local newHealth = math.max(playerHealth - headshotDamage, 0) function onPlayerHeadshot( attacker, _, bodypart, loss ) if not ( bodypart == 9 ) then return false end -- check if the player has been hit in the head if not ( getElementType( attacker ) == "player" ) then return false end -- check if the attacker is a player local playerHealth = getElementHealth( source ) -- get the player's health setElementHealth( localPlayer, newHealth) -- set the player's new health end addEventHandler( "onClientPlayerDamage", getRootElement(), onPlayerHeadshot ) Link to comment
Moderators IIYAMA Posted June 27, 2017 Moderators Share Posted June 27, 2017 Did you? You should have warnings/errors at the moment, so I don't think so. Replace line 8 with line 1 and 2. (of your updated code) Replace line 12 with the line that looks similar. (from my code) And show the updated code. Link to comment
Lorder Posted June 27, 2017 Author Share Posted June 27, 2017 3 minutes ago, IIYAMA said: Did you? You should have warnings/errors at the moment, so I don't think so. Replace line 8 with line 1 and 2. (of your updated code) Replace line 12 with the line that looks similar. (from my code) And show the updated code. Can you help me in this business is new? Link to comment
Moderators IIYAMA Posted June 27, 2017 Moderators Share Posted June 27, 2017 1 minute ago, Lorder said: Can you help me in this business is new? Try harder. You are not coding at the moment, you are simple moving lines. Link to comment
Lorder Posted June 27, 2017 Author Share Posted June 27, 2017 (edited) local playerHealth = getElementHealth( source ) -- get the player's health function onPlayerHeadshot( attacker, _, bodypart, loss ) if not ( bodypart == 9 ) then return false end -- check if the player has been hit in the head if not ( getElementType( attacker ) == "player" ) then return false end -- check if the attacker is a player local playerHealth = getElementHealth( source ) -- get the player's health setElementHealth( localPlayer, newHealth) -- set the player's new health end addEventHandler( "onClientPlayerDamage", localPlayer, onPlayerHeadshot ) Edited June 27, 2017 by Lorder Link to comment
Moderators IIYAMA Posted June 27, 2017 Moderators Share Posted June 27, 2017 1 minute ago, Lorder said: How can I find out? Please give me the code 1 I promise you I will try hard to find out function onPlayerHeadshot( attacker, _, bodypart, loss ) if not ( bodypart == 9 ) then return false end -- check if the player has been hit in the head if not ( getElementType( attacker ) == "player" ) then return false end -- check if the attacker is a player local playerOriginalHealth = getElementHealth( source ) + loss -- get the player's original health local newHealth = math.max(playerOriginalHealth - headshotDamage, 0) setElementHealth( localPlayer, newHealth) -- set the player's new health end addEventHandler( "onClientPlayerDamage", localPlayer, onPlayerHeadshot ) Link to comment
Lorder Posted June 27, 2017 Author Share Posted June 27, 2017 @IIYAMA I did it but it doesn't get much damage same Link to comment
Moderators IIYAMA Posted June 27, 2017 Moderators Share Posted June 27, 2017 function onPlayerHeadshot( attacker, _, bodypart, loss ) if not ( bodypart == 9 ) then return false end -- check if the player has been hit in the head if not attacker or not ( getElementType( attacker ) == "player" ) then return false end -- check if the attacker is a player local playerOriginalHealth = getElementHealth( source ) + loss -- get the player's original health local newHealth = math.max(playerOriginalHealth - headshotDamage, 0) setElementHealth( localPlayer, newHealth) -- set the player's new health iprint("playerOriginalHealth:", playerOriginalHealth, ", newHealth:", newHealth) end addEventHandler( "onClientPlayerDamage", localPlayer, onPlayerHeadshot ) debug it and show results. Link to comment
Moderators IIYAMA Posted June 27, 2017 Moderators Share Posted June 27, 2017 (edited) 4 minutes ago, Lorder said: @IIYAMA yea, that explains a lot. Run the script clientside, not serverside. Make a backup of the meta.xml (so can mess it up) Open the meta.xml <script src="scriptName.lua" /> change to: <script src="scriptName.lua" type="client"/> Restart the resource. Edited June 27, 2017 by IIYAMA Link to comment
Lorder Posted June 28, 2017 Author Share Posted June 28, 2017 (edited) @IIYAMAit does not work meta.xml <meta> <script src="hs.lua" type="client"/> </meta> hs.lua function onPlayerHeadshot( attacker, _, bodypart, loss ) if not ( bodypart == 9 ) then return false end -- check if the player has been hit in the head if not attacker or not ( getElementType( attacker ) == "player" ) then return false end -- check if the attacker is a player local playerOriginalHealth = getElementHealth( source ) + loss -- get the player's original health local newHealth = math.max(playerOriginalHealth - headshotDamage, 90) setElementHealth( localPlayer, newHealth) -- set the player's new health iprint("playerOriginalHealth:", playerOriginalHealth, ", newHealth:", newHealth) end addEventHandler( "onClientPlayerDamage", localPlayer, onPlayerHeadshot ) Edited June 28, 2017 by Lorder Link to comment
Rockyz Posted June 28, 2017 Share Posted June 28, 2017 13 minutes ago, Lorder said: @IIYAMAit does not work meta.xml <meta> <script src="hs.lua" type="client"/> </meta> hs.lua function onPlayerHeadshot( attacker, _, bodypart, loss ) if not ( bodypart == 9 ) then return false end -- check if the player has been hit in the head if not attacker or not ( getElementType( attacker ) == "player" ) then return false end -- check if the attacker is a player local playerOriginalHealth = getElementHealth( source ) + loss -- get the player's original health local newHealth = math.max(playerOriginalHealth - headshotDamage, 90) setElementHealth( localPlayer, newHealth) -- set the player's new health iprint("playerOriginalHealth:", playerOriginalHealth, ", newHealth:", newHealth) end addEventHandler( "onClientPlayerDamage", localPlayer, onPlayerHeadshot ) Show the debug again Link to comment
Lorder Posted June 28, 2017 Author Share Posted June 28, 2017 10 hours ago, #,+( _xiRoc[K]; > said: Show the debug again There are no faults, but no more damage Link to comment
Moderators IIYAMA Posted June 28, 2017 Moderators Share Posted June 28, 2017 You edited line 7, that is a bit sloppy of you. If you put that to 90, the health can never be lower than 90. If you want it to work, change it back to the code I gave you. My code: local newHealth = math.max(playerOriginalHealth - headshotDamage, 0) Your code: local newHealth = math.max(playerOriginalHealth - headshotDamage, 90) Link to comment
Lorder Posted June 28, 2017 Author Share Posted June 28, 2017 13 minutes ago, IIYAMA said: You edited line 7, that is a bit sloppy of you. If you put that to 90, the health can never be lower than 90. If you want it to work, change it back to the code I gave you. My code: local newHealth = math.max(playerOriginalHealth - headshotDamage, 0) Your code: local newHealth = math.max(playerOriginalHealth - headshotDamage, 90) I tried, but it didn't work, no bugs Link to comment
Moderators IIYAMA Posted June 28, 2017 Moderators Share Posted June 28, 2017 I did test the code without this part: if not ( bodypart == 9 ) then return false end -- check if the player has been hit in the head if not attacker or not ( getElementType( attacker ) == "player" ) then return false end -- check if the attacker is a player Just to check if it is working (because I didn't have a dummy to test it on). It did work. If you disable that, will it give you an insta-kill when you receive any damage? If not, then you have :Oed it up somewhere along the way. Link to comment
Lorder Posted June 28, 2017 Author Share Posted June 28, 2017 (edited) 18 minutes ago, IIYAMA said: I did test the code without this part: if not ( bodypart == 9 ) then return false end -- check if the player has been hit in the head if not attacker or not ( getElementType( attacker ) == "player" ) then return false end -- check if the attacker is a player Just to check if it is working (because I didn't have a dummy to test it on). It did work. If you disable that, will it give you an insta-kill when you receive any damage? If not, then you have :Oed it up somewhere along the way. I try, but he does not get much damage from his head function onPlayerHeadshot( attacker, _, bodypart, loss ) local playerOriginalHealth = getElementHealth( source ) + loss -- get the player's original health local newHealth = math.max(playerOriginalHealth - headshotDamage, 0) setElementHealth( localPlayer, newHealth) -- set the player's new health iprint("playerOriginalHealth:", playerOriginalHealth, ", newHealth:", newHealth) end addEventHandler( "onClientPlayerDamage", localPlayer, onPlayerHeadshot ) Edited June 28, 2017 by Lorder Link to comment
Moderators IIYAMA Posted June 28, 2017 Moderators Share Posted June 28, 2017 answer my question. 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