Forum

> > CS2D > Scripts > Hit hook doesn't work
Forums overviewCS2D overview Scripts overviewLog in to reply

English Hit hook doesn't work

22 replies
Page
To the start Previous 1 2 Next To the start

old Hit hook doesn't work

Obviously Exactly Myself
User Off Offline

Quote
I don't know why this script doesn't work, the damage resistance (The sethealth thingy) doesn't work but the others are.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[Code above removed!]

addhook("hit","zj_godmode")
function zj_godmode(id)
	if zj_invulnerable[id] == 1 then
		return 1
	end
	if zj_upgrade[id] == 1 then
		return 1
	end
	if (zj_player_knowledge[id]>=20 and zj_player_knowledge[id]<=39) then
		parse("sethealth ".. id .." ".. (player(id, "health") + 1))
	elseif (zj_player_knowledge[id]>=40 and zj_player_knowledge[id]<=59) then
		parse("sethealth ".. id .." ".. (player(id, "health") + 2))
	elseif (zj_player_knowledge[id]>=60 and zj_player_knowledge[id]<=79) then
		parse("sethealth ".. id .." ".. (player(id, "health") + 3))
	elseif (zj_player_knowledge[id]>=80 and zj_player_knowledge[id]<=99) then
		parse("sethealth ".. id .." ".. (player(id, "health") + 4))
	elseif zj_player_knowledge[id] >= 100 then
		parse("sethealth ".. id .." ".. (player(id, "health") + 5))
	end
end

[Code below removed!]
edited 1×, last 23.01.12 06:04:19 am

old Re: Hit hook doesn't work

Alistaire
User Off Offline

Quote
Then what the fuck is the problem. Only thing I see is that you've put the parses 'wrong'. In my scripts they are like;

parse('sethealth '..id..' '..player(id, 'health') + 3)

old Re: Hit hook doesn't work

MikuAuahDark
User Off Offline

Quote
umm, maybe the () is wrong!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
addhook("hit","zj_godmode")
function zj_godmode(id)
	if zj_invulnerable[id] == 1 then
		return 1
	end
	if zj_upgrade[id] == 1 then
		return 1
	end
	if (zj_player_knowledge[id]>=20 and zj_player_knowledge[id]<=39) then
		parse("sethealth ".. id .." ".. player(id, "health") + 1)
	elseif (zj_player_knowledge[id]>=40 and zj_player_knowledge[id]<=59) then
		parse("sethealth ".. id .." ".. player(id, "health") + 2)
	elseif (zj_player_knowledge[id]>=60 and zj_player_knowledge[id]<=79) then
		parse("sethealth ".. id .." ".. player(id, "health") + 3)
	elseif (zj_player_knowledge[id]>=80 and zj_player_knowledge[id]<=99) then
		parse("sethealth ".. id .." ".. player(id, "health") + 4)
	elseif zj_player_knowledge[id] >= 100 then
		parse("sethealth ".. id .." ".. player(id, "health") + 5)
	end
end

old Re: Hit hook doesn't work

Alistaire
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
addhook('hit','zj_godmode')
function zj_godmode(id)
	if zj_invulnerable[id] == 1 then
		return 1
	end
	if zj_upgrade[id] == 1 then
		return 1
	end
	if (zj_player_knowledge[id]>=20 and zj_player_knowledge[id]<=39) then
		parse('sethealth '..id..' '..player(id, 'health') + 1)
	elseif (zj_player_knowledge[id]>=40 and zj_player_knowledge[id]<=59) then
		parse('sethealth '..id..' '..player(id, 'health') + 2)
	elseif (zj_player_knowledge[id]>=60 and zj_player_knowledge[id]<=79) then
		parse('sethealth '..id..' '..player(id, 'health') + 3)
	elseif (zj_player_knowledge[id]>=80 and zj_player_knowledge[id]<=99) then
		parse('sethealth '..id..' '..player(id, 'health') + 4)
	elseif zj_player_knowledge[id] >= 100 then
		parse('sethealth '..id..' '..player(id, 'health') + 5)
	end
end

old Re: Hit hook doesn't work

DannyDeth
User Off Offline

Quote
This is a WONDERFUL example of: "Those who know nothing, teach."

Let's see.. you need to learn that Lua doesn't give a fuck if you use double-/single quotes or "[[" and "]]." Also, the thing with the brackets being removed was a rather huge fail, since this is actually more likely to cause errors than having the brackets there.

The problem here is probably the arrays you are checking with, verify their data.

old Re: Hit hook doesn't work

Obviously Exactly Myself
User Off Offline

Quote
user DannyDeth has written
This is a WONDERFUL example of: "Those who know nothing, teach."

Let's see.. you need to learn that Lua doesn't give a fuck if you use double-/single quotes or "[[" and "]]." Also, the thing with the brackets being removed was a rather huge fail, since this is actually more likely to cause errors than having the brackets there.

The problem here is probably the arrays you are checking with, verify their data.


It's not the arrays, I checked the arrays and they're fine.

EDIT:
I tried to remove the extra ")" but it became worse.
1
LUA ERROR: maps/ZJ's City.lua:674: ')' expected (to close '(' at line 673) near 'elseif'

old Re: Hit hook doesn't work

Obviously Exactly Myself
User Off Offline

Quote
user DannyDeth has written
Could you perhaps give EXACT details on what happens?


I'm trying to knowledge system in my server. You get +2 knowledge when you kill an enemy, and -4 when you kill a team-mate. When you have more knowledge, you will have damage resistance, if you read my script, you can understand it.

old Re: Hit hook doesn't work

Alistaire
User Off Offline

Quote
But I don't understand what's wrong if the script works without any errors.

If you'd only post more of the script.

old Re: Hit hook doesn't work

Obviously Exactly Myself
User Off Offline

Quote
user Alistaire has written
But I don't understand what's wrong if the script works without any errors.

If you'd only post more of the script.


u rly want mi 2 post diz skript wid 1064 laynz?

The problem is, it doesn't add more health for the player.

old Re: Hit hook doesn't work

Alistaire
User Off Offline

Quote
If you could add everything you find which has ANYTHING to do with those zj_ commands, it'd be easier to find an error. Or just get a good notepad program and search the error yourself.

----

user DannyDeth has written
user Alistaire has written
notepad program

Windows-nubzors.

Windows-nubzors everywhere.


Programmer's Notepad. Programmer's Notepad everywhere.
edited 2×, last 24.01.12 03:05:45 pm

old Re: Hit hook doesn't work

DannyDeth
User Off Offline

Quote
user Alistaire has written
notepad program

Windows-nubzors.

Windows-nubzors everywhere.

EDIT:
It wasn't what you said.. it was what you said. It's called a TEXT EDITOR not a "notepad program."

old Re: Hit hook doesn't work

DarkLight66
User Off Offline

Quote
I bet is the fact that you should put return 1 after every sethealth and then put it like:

1
parse("sethealth ".. id .." ".. (hpdmg -1))

for example, but you will need to change the function to:

1
function zj_godmode(id,source,weapon,hpdmg)

that will cause another error thought, but i haven´t found how to fix it.
Of course, im not sure if that code will even work lol.

old Re: Hit hook doesn't work

Starkkz
Moderator Off Offline

Quote
user DarkLight66 has written
I bet is the fact that you should put return 1 after every sethealth


They should know that the script stops being executed after puting a return. That's basic

old Re: Hit hook doesn't work

Alistaire
User Off Offline

Quote
user Starkkz has written
user DarkLight66 has written
I bet is the fact that you should put return 1 after every sethealth


They should know that the script stops being executed after puting a return. That's basic


If you put return 1; yea..

Not after return 1 afaik?

old Re: Hit hook doesn't work

DannyDeth
User Off Offline

Quote
If you put a "return 1" statement it will just add to the victim health, nincompoops.

EDIT:
I mean this as in:
Player 1 hits Player 2.
Player 2's health goes up from 100 to 110.

old Re: Hit hook doesn't work

Flacko
User Off Offline

Quote
If that's the case then you should calculate sth like player(id,'health')-hpdmg+resistance.

1
2
3
4
5
6
7
8
9
10
11
12
function zj_godmode(id,src,wp,hpdmg,apdmg)
	local res = 0
	res = math.ceil((zj_player_knowledge[id]-20)/20)
	if res < 0 then res = 0 end
	if res > 5 then res = 5 end
	--If the damage is too low make sure the player doesn't heal
	if res > hpdmg then res = hpdmg end

	parse('sethealth '..id..' '..player(id,'health')-hpdmg+res)
	parse('setarmor '..id..' '..player(id,'armor')-apdmg)
	return 1
end
I guess something like that should work
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview