Forum

> > CS2D > Scripts > Radius message function doesn't work
Forums overviewCS2D overview Scripts overviewLog in to reply

English Radius message function doesn't work

2 replies
To the start Previous 1 Next To the start

old Radius message function doesn't work

EngiN33R
Moderator Off Offline

Quote
I've been coding some stoofz, and for some reason, this does not work.
Spoiler >


msg3 is a function for printing the message to all players in range. All print debugs work perfectly, even the txt:len() chat cropping thing works on print messages.

Why isn't the function working? Can anyone help?

old Re: Radius message function doesn't work

Flacko
User Off Offline

Quote
Because of your incoherent variable naming you got confused and made a mistake in bounding box collision detection.
So, first, let's change this:
1
local xl,yl,xb,yb=x-rx,y-ry,x+rx,y+ry
To this:
1
2
local xl, xr = x-rx, x+rx -- X-Left and X-Right
local yt, yb = y-ry,y+ry -- Y-Top and Y-Bottom

Do NEVER use this again:
1
for _, p in ipairs(player(0,"table")) do
(Anyways, Lua won't let you do this in the future)
The ipairs() function is getting deprecated in lua 5.2.
Use pairs() instead.

So, change that line to this:
1
for _,p in pairs(player(0,"table")) do

And finally, fix the bounding-box check:
1
if player(p,"x")>=xl and player(p,"x")<=xl and player(p,"y")>=yb and player(p,"y")<=yb
To:
1
2
if player(p,"x")>= xl and player(p,"x") <= xr then
	if player(p,"y") >= yt and player(p,"y") <= yb then
I usually split the bounds checking in two different conditionals (one for each dimension) You can put it into a single line if you feel like doing so.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview