Forum

> > CS2D > Scripts > Knockback not working right
Forums overviewCS2D overview Scripts overviewLog in to reply

English Knockback not working right

5 replies
To the start Previous 1 Next To the start

old Knockback not working right

alluclone1
User Off Offline

Quote
hi guys

i got problem with knockback
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
26
27
28
29
30
31
32
33
34
recoil_factor = 3

addhook('hit','knockback')
function knockback(id,source,weapon)
local killer_x = player(source,'x')
local killer_y = player(source,'y')
local victim_x = player(id,'x')
local victim_y = player(id,'y')
local recoil = itemtype(weapon,'recoil') * recoil_factor
	if player(id,"team")==1 then
	if player(source,'exists') then
		if killer_x > victim_x then 
			if tile(player(id,'tilex') - 1,player(id,'tiley'),'walkable') then
				parse('setpos '..id..' '..(player(id,'x') - recoil)..' '..player(id,'y')) 
			end
		end
		if killer_x < victim_x then 
			if tile(player(id,'tilex') + 1,player(id,'tiley'),'walkable') then
				parse('setpos '..id..' '..(player(id,'x') + recoil)..' '..player(id,'y')) 
			end
		end
		if killer_y > victim_y then
			if tile(player(id,'tilex'),player(id,'tiley') - 1,'walkable') then
				parse('setpos '..id..' '..player(id,'x')..' '..(player(id,'y') - recoil)) 
			end
		end
		if killer_y < victim_y then 
			if tile(player(id,'tilex'),player(id,'tiley') + 1,'walkable') then
				parse('setpos '..id..' '..player(id,'x')..' '..(player(id,'y') + recoil)) 
			end
		end	
	end
end
end
Human can shoot me in the wall
whats the problem?

old Re: Knockback not working right

J4x
User Off Offline

Quote
Well, he didn't understand because he didn't make this script its form biohazard mod. For me it works pefectly.
edited 1×, last 04.03.11 02:13:36 am

old Re: Knockback not working right

Starkkz
Moderator Off Offline

Quote
I recomend to use the angle method, and check if the tile is walkable..

1
2
3
local Angle = math.rad(you put an angle into -180 to 180)
local x = player position x + math.sin(Angle) * (Distance in pixels)
local y = player position y - math.cos(Angle) * (Distance in pixels)

Now check if it is walkable
1
2
3
if tile(math.floor(x/32),math.floor(y/32),"walkable") then
	-- here you can teleport him because it is walkable
end

old Re: Knockback not working right

alluclone1
User Off Offline

Quote
Yeh right i took this from zombie horde cause i cant do it

EDIT:No. i just cant do it. human shoot me always in the wall.
Not working its give me this error
1
LUA ERROR: sys/lua/test2.lua:106: '=' expected near 'x'
edited 3×, last 05.03.11 10:02:16 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview