AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [ STOCK/INC ] Find player in box (https://forums.alliedmods.net/showthread.php?t=307944)

CrazY. 05-31-2018 16:29

[ STOCK/INC ] Find player in box
 
1 Attachment(s)
.: Find player in box :.



Hello, I've made this simple stock to find alive players in a imaginary box. Box color is white as default.

Usage:
Code:
/* Find player in box  *  * @param (float/vector) flVecBoxOrigin   Origin of the box at where will be created  * @param (float) flBoxSize                        Size of the box  * @param (int) iDisplayBox               Time in 0.1s that the box will be stay displayed (0 doesn't show)  * @param (int) iIgnoredPlayer            Player index that won't will be checked (0 doesn't skip anyone)  *  * @return (int)    First player found index, 0 if no one was  found.  */ stock findPlayerInBox(const Float:flVecOrigin[3], Float:flBoxSize, iDisplayBox=0, iIgnoredPlayer=0)

There are several ways to customize this code, such as store all players in an array, get entities instead of players, get players on a specific team... but I'm lazy now, maybe later.

E1_531G 06-01-2018 07:38

Re: [ STOCK/INC ] Find player in box
 
Quote:

if (mins.x <= flVecPlayerMaxs[0]
&& mins.y <= flVecPlayerMaxs[1]
&& mins.z <= flVecPlayerMaxs[2]
&& maxs.x >= flVecPlayerMins[0]
&& maxs.y >= flVecPlayerMins[1]
&& maxs.z >= flVecPlayerMins[2])
return pPlayer;
How should this work?

CrazY. 06-01-2018 09:59

Re: [ STOCK/INC ] Find player in box
 
Basically this intersects vectors. I've updated the code, since I did wrong in that part, more precisely like c++.

E1_531G 06-01-2018 12:44

Re: [ STOCK/INC ] Find player in box
 
Quote:

Originally Posted by CrazY. (Post 2594810)
Basically this intersects vectors. I've updated the code, since I did wrong in that part, more precisely like c++.

I know what it does. I pointed on your mistake about inexistent variables 'maxs' and 'mins' and also dot-notation.

joropito 06-04-2018 13:16

Re: [ STOCK/INC ] Find player in box
 
What if the player is just touching the box? I mean half body inside, half outside of the box.

Check code for hull collisions on sdk to understand.

CrazY. 06-04-2018 13:54

Re: [ STOCK/INC ] Find player in box
 
Code doesn't detect when player touch the box, instead check if player absmin/absmax is inside of the box mins/maxs. You can start a TE_BOX message based on player's vectors to see what I'm trying to explain.


All times are GMT -4. The time now is 04:01.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.