Possibility of $within_cylinder()?

greatguys1

Epic Adventurer
MSC Developer
Warriors of the North
MSC Archivist
Joined
Apr 20, 2013
Messages
339
Reaction score
62
Age
26
Location
Yes
Is it possible to get a script function to return if an entity is within a cylinder?
Similar to $within_cone, I'd like it to have the params, <test_origin>,<cylinder_origin>,<cylinder_angles>,<cylinder_length>,<cylinder_radius>.
Would this be possible? Or is there a way to hack it with the current functions

An example would be:
$within_cylinder($vec(0,0,0),$vec(-50,0,0),$vec(0,0,0),100,10)
professional diagram.png

It, of course, doesn't have to have those params in that order, but just to get the point across
 

Thothie

Administrator
Staff member
Administrator
Moderator
MSC Archivist
Joined
Apr 8, 2005
Messages
16,342
Reaction score
326
Location
lost

Meanwhile, your best bet is probably to use a $within_box or $within_cone - especially since I didn't think to request being able to define the angles on the cylinder.

Code:
//$within_box(<target|origin>,<testbox_org|0>,<testbox_mins>,<testbox_maxs>)
//- Tests if <target>'s bounding box intersects with test box area, or if <origin> is inside test box.
//- If testbox_org is zero, origin is calced from mins/maxs, and abs min/max vectors must be supplied.
//- When client side, <target> accepts idx but cannot currently extract bounding boxes from client side entities

There's also the really ugly manual way, but you wouldn't want to do it very frequently - this is a PoC script where the box turns red when occupied:
Code:
{ check_box

	//. createnpc other/box_test ME

	dbg check_box $get(MY_OWNER,name)

	local L_OWNER_POS $get(MY_OWNER,origin)
	local L_OWNER_ANG $get(MY_OWNER,viewangles)

	setvard BOX_CENTER L_OWNER_POS
	vectoradd BOX_CENTER $relpos($vec(0,$vec.yaw(L_OWNER_ANG),0),$vec(0,BOX_LENGTH,0)) //placing box half distance forward
	setvard BOX_MINS BOX_CENTER
	vectoradd BOX_MINS $relpos($vec(0,$vec.yaw(L_OWNER_ANG),0),$vec($neg(BOX_WIDTH),$neg(BOX_LENGTH),0))
	setvard BOX_MAXS BOX_CENTER
	vectoradd BOX_MAXS $relpos($vec(0,$vec.yaw(L_OWNER_ANG),0),$vec(BOX_WIDTH,BOX_LENGTH,0))
	
	setvard ALL_ENTS $get_tsphere(any,1024,L_OWNER_POS)
	local L_BOX_OCCUPIED $func(func_check_box_occupied)

	if ( L_BOX_OCCUPIED )
	{
		local L_BOX_COLOR $vec(255,0,0)
	}
	else
	{
		local L_BOX_COLOR $vec(0,255,0)
	}

	//draw box
	local L_BEAM_START BOX_MINS
	local L_BEAM_END L_BEAM_START
	vectoradd L_BEAM_END $relpos($vec(0,$vec.yaw(L_OWNER_ANG),0),$vec(0,$math(multiply,BOX_LENGTH,2),0))
	effect beam point lgtning.spr 5 L_BEAM_START L_BEAM_END L_BOX_COLOR 200 0 0.5
	local L_BEAM_START BOX_MAXS
	local L_BEAM_END L_BEAM_START
	vectoradd L_BEAM_END $relpos($vec(0,$vec.yaw(L_OWNER_ANG),0),$vec(0,$neg($math(multiply,BOX_LENGTH,2)),0))
	effect beam point lgtning.spr 5 L_BEAM_START L_BEAM_END L_BOX_COLOR 200 0 0.5

	callevent 0.5 check_box
}

{ func_check_box_occupied
	setvard T_BOX_OCCUPIED 0
	calleventloop $get_token_amt(ALL_ENTS) func_check_box_occupied_loop
	return T_BOX_OCCUPIED
}

{ func_check_box_occupied_loop
	local L_CUR_ENT $get_token(ALL_ENTS,game.script.iteration)
	local L_CUR_ENT_ORG $get(L_CUR_ENT,origin)
	if $vec.x(L_CUR_ENT_ORG) >= $vec.x(BOX_MINS)
	if $vec.x(L_CUR_ENT_ORG) <= $vec.x(BOX_MAXS)
	if $vec.y(L_CUR_ENT_ORG) >= $vec.y(BOX_MINS)
	if $vec.y(L_CUR_ENT_ORG) <= $vec.y(BOX_MAXS)
	setvard T_BOX_OCCUPIED 1
	breakloop
}

It's a 2D box, but simple enough to add a z component to.
 
Top