Forum

> > CS2D > Scripts > Hit hook doesn't work
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Hit hook doesn't work

22 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt Hit hook doesn't work

Obviously Exactly Myself
User Off Offline

Zitieren
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!]
1× editiert, zuletzt 23.01.12 06:04:19

alt Re: Hit hook doesn't work

Alistaire
User Off Offline

Zitieren
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)

alt Re: Hit hook doesn't work

MikuAuahDark
User Off Offline

Zitieren
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

alt Re: Hit hook doesn't work

Alistaire
User Off Offline

Zitieren
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

alt Re: Hit hook doesn't work

DannyDeth
User Off Offline

Zitieren
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.

alt Re: Hit hook doesn't work

Obviously Exactly Myself
User Off Offline

Zitieren
user DannyDeth hat geschrieben
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'

alt Re: Hit hook doesn't work

Obviously Exactly Myself
User Off Offline

Zitieren
user DannyDeth hat geschrieben
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.

alt Re: Hit hook doesn't work

Alistaire
User Off Offline

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

If you'd only post more of the script.

alt Re: Hit hook doesn't work

Obviously Exactly Myself
User Off Offline

Zitieren
user Alistaire hat geschrieben
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.

alt Re: Hit hook doesn't work

Alistaire
User Off Offline

Zitieren
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 hat geschrieben
user Alistaire hat geschrieben
notepad program

Windows-nubzors.

Windows-nubzors everywhere.


Programmer's Notepad. Programmer's Notepad everywhere.
2× editiert, zuletzt 24.01.12 15:05:45

alt Re: Hit hook doesn't work

DannyDeth
User Off Offline

Zitieren
user Alistaire hat geschrieben
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."

alt Re: Hit hook doesn't work

DarkLight66
User Off Offline

Zitieren
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.

alt Re: Hit hook doesn't work

Starkkz
Moderator Off Offline

Zitieren
user DarkLight66 hat geschrieben
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

alt Re: Hit hook doesn't work

Alistaire
User Off Offline

Zitieren
user Starkkz hat geschrieben
user DarkLight66 hat geschrieben
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?

alt Re: Hit hook doesn't work

DannyDeth
User Off Offline

Zitieren
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.

alt Re: Hit hook doesn't work

Flacko
User Off Offline

Zitieren
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
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht