Forum

> > CS2D > Scripts > Abusing ai_ commands for non-bots
Forums overviewCS2D overview Scripts overviewLog in to reply

English Abusing ai_ commands for non-bots

1 reply
To the start Previous 1 Next To the start

old Abusing ai_ commands for non-bots

Bowlinghead
User Off Offline

Quote
Hello us

∗ I want to use this ai_ command for real players.
cs2d lua cmd ai_freeline
1
2
3
4
5
6
7
8
addhook("ms100", "kkk")
function kkk()
	-- id=1, a NON-BOT player
	if (ai_freeline(1, 300, 400)) then
		msg("YES")
	end

end
The code never prints "YES" (Listen Server, so id=1 is always me) even when I have a free line of sight to the coordinate.
Do I have to implement my own player_freeline() here or are there any workarounds? (Setpos´ing a bot for a split second, do ai_freeline check, and then setpos´ing the bot back is possible but not good for the gameplay )

∗ I want to use cs2d lua cmd ai_goto to check, if a certain tile position is inside the playable map boundaries.
More >
Like:
1
2
3
4
5
6
7
8
9
botid = 2
parse("setpos 2 32 32) -- Place Bot OUTSIDE OF MAP
function isOutside(x,y)
	if (ai_goto(botid, x,y) == 0) then
		return false;
	else 
		return true;
	end
end

While I always have a bot with pid=2 placed outside of the map. Are there better ways?

old Re: Abusing ai_ commands for non-bots

DC
Admin Off Offline

Quote
Unfortunately cs2d lua cmd ai_freeline only works with bot players. Temporarily setting the position of a bot player is probably the only way to use it with a custom starting coordinate. Also that would only work if you have at least one bot on the server. Not possible to use it with regular players. It will always return false for those as you noticed.

Pretty much the same is true for cs2d lua cmd ai_goto - and most (if not all) other ai_ Lua commands. You need a bot.

You could implement your own checks instead in Lua. These would be slower but they would work without bots. I'm pretty sure that someone implemented a freeline check somewhere already. You basically shoot a ray / move a point with sin/cos and check if it collides. You could also use the Bresenham algorithm to determine the pixel coordinates which need to be checked one after another.

For the second problem you would have to implement a flood fill algorithm which starts at the spawn point. You could cache the results and only do the flood fill once - unless the map contains dynamic elements like breakables or dynwalls etc.

Both of these algorithms are rather basic and you can find a lot of samples when you search for it.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview