Forum

> > CS2D > Scripts > setpos *32+16
Forums overviewCS2D overview Scripts overviewLog in to reply

English setpos *32+16

8 replies
To the start Previous 1 Next To the start

old setpos *32+16

Dynamite07
User Off Offline

Quote
1
2
3
4
5
6
addhook("movetile","no_move")
function no_move(id,x,y)
	if tile(x, y, 'frame') == 25 then -- 25 = tile
               parse('setpos '..id..' '..x*32+16 ..' '..y*32+16)
          end
end
Yoo all.
x/y*32+16 -- I think it would be normal if this teleport me back, but this teleport me to the center of the tile, can anyone say me why plz?

old Re: setpos *32+16

Alistaire
User Off Offline

Quote
1
2
3
4
5
6
addhook("movetile","no_move")
function no_move(id,x,y)
	if tile(x, y, 'frame') == 25 then -- 25 = tile
               parse('setpos '..id..' '..x*32+16 ..' '..y*32+16)
          end
end

x = tilex position
x * 32 = tile's start in pixels
x * 32 + 16 = tile's center in pixels

You should make it a move hook, not a movetile hook;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function array(v)
	local a = {}
	for k = 1, 32 do
		a[k] = v
	end
	return a;
end

plr = {}
plr.x = array(0)
plr.y = array(0)

addhook('move', '_moveFunc')

function _moveFunc(id, x, y)
	local tilex = math.floor(x / 32)
	local tiley = math.floor(y / 32)
	if tile(tilex, tiley, 'frame') == 25 then
		parse('setpos '..id..' '..plr.x[id]..' '..plr.y[id])
	end
	plr.x[id] = x
	plr.y[id] = y
end

old Re: setpos *32+16

Yates
Reviewer Off Offline

Quote
One tile is 32 by 32 pixels. So if you teleport yourself to a tile and add 16 pixels you will be in the middle of the tile. Seems obvious.

old Re: setpos *32+16

Alistaire
User Off Offline

Quote
user Dynamite07 has written
not a error, is like you are being teleported to the place where you are walking, is weird


Then why the fuck do you say it doesn't work.
Also, what is this script supposed to do? Teleport people away from tile 25, right?
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview