Forum

> > CS2D > Scripts > Unable to parse health in hit hook
Forums overviewCS2D overview Scripts overviewLog in to reply

English Unable to parse health in hit hook

4 replies
To the start Previous 1 Next To the start

old Unable to parse health in hit hook

Denisgrad
User Off Offline

Quote
For some odd reason I seem to be unable to parse "sethealth" to victim id in hit hook. Im creating perks based on call of duty - Stopping Power and Danger Close the former increasing the damage of all guns and the latter increasing damage of explosives. My script returns no errors and when I change the id in parse "sethealth" to "source" aka the attacker the health is changed, but when the id is set to v or id, the victim's health is unchanged. Furthermore even though I write return 1 at the end of an if statement, damage is still done with a gun. Here is the script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function cod_hit(v,s,h,wpn)
         if player(s,"exists") then
         if cod_extrad[s]==1 then
                local dmg = h * 1.4
                if player(v,"health") - dmg > 0 then
                        parse('sethealth '..v..' '..player(v,"health") - dmg)
				cod_msg2(s,3,'Hit player for: '..dmg..'')
                        return 1
			end
        elseif cod_dangerclose[s]==1 then
					local dmg = h * 1.75
			if player(v,"health") - dmg > 0 then
				if weapon == 51 or weapon == 73 or weapon == 77 or weapon == 89 then
                        	parse('sethealth '..v..' ' ..player(v,"health") - dmg)
			cod_damagetaken[v] = cod_damagetaken[v] + dmg
			Unbreakable(v)
			return 1
				end
			end
                else
                cod_damagetaken[v] = cod_damagetaken[v] + h
                Unbreakable(v)
         end
         end
end


Im also using SQ's achievements script which plays around with hit hook but I set everything to return 1 if cod_extrad[s]==1 so that shouldnt be a problem as well.

EDIT: Should I even bother adding these two perks? If a command is parsed every time a bullet hits another players does this have the possibility to seriously slow down the server?
edited 1×, last 21.12.17 07:23:52 pm

old Re: Unable to parse health in hit hook

DC
Admin Off Offline

Quote
It looks like your parameter order is not okay. See: cs2d lua hook hit
Looks like you mixed up damage and weapon. Based on your description there might be more problems but the code indentation (tabs) is wrong, making it hard to read your code.

old Re: Unable to parse health in hit hook

Rainoth
Moderator Off Offline

Quote
1. Mixed up param order
2. No need to do the "exists" check so long as s~=0
3. The damage is going to exceed 100 providedyour weapon id is above 70 on the first hit
4. Not sure if intended but you dont apply extra damage if it could kill the player
5. The elseif has same effect as #3 but to a greater extent
6. weapon is nil so your conditions won't go through cause the param (in fixed order) is still named wpn not weapon
7.nil your locals when you're done using them
8. Tab your code properly
9. Assuming the functions you call are inexpensive it is perfectly reasonable to use them anywhere. Especially hithook which calls function only 10s of times per second during a heated game.

old Re: Unable to parse health in hit hook

Denisgrad
User Off Offline

Quote
Thank you for your reply. I fixed the issues you guys told me but it still wouldnt work. I know the indentation of the code is messy, I will fix that last. I havent created that though. I am making a Call of Duty mod and I was picking up from where my clanmate user Loooser left off in his file cs2d Call of Duty mode Final by Loooser script. It was like this and the hit hook was not written by me as well so I have no idea what the problem might be.

I decided to replace the two perks with different perks written by myself from scratch and now it works. The new perk is basically thermal vision, it allows you to see players through a wall in fog of war for 30 seconds.

Instead of creating a new thread I will just ask it here. Is it better to use always hook or ms100 hook to do this? I am thinking using always hook to draw 16-32 players 50 times a second might be problematic in the long run right?

old Re: Unable to parse health in hit hook

DC
Admin Off Offline

Quote
Using always/ms100 for image drawing should be avoided if possible. It costs performance and causes a lot of additional server traffic.

If you just need to draw images at players you could take a look at the cs2d lua cmd image modes. It allows you to draw images at players and it does not cost additional traffic/performance. No frequently called hooks required.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview