Raised This Month: $138 Target: $400
 34% 

SetupBeamLaser to all clients


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Minfas
Junior Member
Join Date: Dec 2017
Old 08-18-2019 , 10:30   SetupBeamLaser to all clients
Reply With Quote #1

Hello community,
I would like to draw line from client's feet to all other players, but I don't know how to get their positions.

My code:
PHP Code:
#define LoopActiveClients(%1) for(int %1;%1 <= MaxClients;%1++) if(IsValidClient(%1, true))

LoopActiveClients(i)
    {
        if(
IsPlayerAlive(i))
        {
            
TE_SetupBeamLaser(clientig_iBeamSpriteg_iHaloSprite0100.50.10.110.0, {25500255}, 10);
            
TE_SendToAll();
        }
    } 
Currently its drawing line from all players to center of the map and the line can by seen only when you are looking towards the center of the map
Thank you for any help!

Last edited by Minfas; 08-18-2019 at 10:36.
Minfas is offline
ShD3luxe
Member
Join Date: Aug 2019
Location: Localhost
Old 08-18-2019 , 21:26   Re: SetupBeamLaser to all clients
Reply With Quote #2

Code:
	
        float fclientPosition[3]; // x y z float vector position
	GetClientAbsOrigin(client, fclientPosition); // get the position of the client in the vector
But you don't need the player's position https://sm.alliedmods.net/new-api/sd...SetupBeamLaser
You need the start index and end index.
If you want to draw lines from player A to B , B to C , A to C , and so on you need 2 loops .

Last edited by ShD3luxe; 08-18-2019 at 21:35. Reason: link documentation
ShD3luxe is offline
Minfas
Junior Member
Join Date: Dec 2017
Old 08-19-2019 , 14:21   Re: SetupBeamLaser to all clients
Reply With Quote #3

It says
Code:
error 047: array sizes do not match, or destination array is too small
while compiling
Minfas is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 08-19-2019 , 14:24   Re: SetupBeamLaser to all clients
Reply With Quote #4

What line did it come from? Gotta give more info. I mean I COULD assume its from the array that hosts your x/y/z but I'd like to look at more.
Halt is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 08-19-2019 , 14:29   Re: SetupBeamLaser to all clients
Reply With Quote #5

You have to understand how vectors work first.

Vectors hold 3 different values

X, Y, Z (This is a location on a map) so you need a array that holds 3 values.

Keep in mind arrays begin at 0, not 1.
Halt is offline
ShD3luxe
Member
Join Date: Aug 2019
Location: Localhost
Old 08-19-2019 , 15:51   Re: SetupBeamLaser to all clients
Reply With Quote #6

As I said TE_SetupBeamLaser needs the start entity index and end entity index you don't need any position vector.
Try like this (I don't recommend doing this bcs it will make your server laggy) :
Code:
public DrawLinesToAll()
{
    for(int currentClient = 1;currentClient <= MaxClients;currentClient++) // the first loop to get the start point index
    {
		if(!IsClientAlive(currentClient)) // make sure the player is alive
			continue;
			
        for(int clients = 1;clients <= MaxClients;clients++) // the second loop to get the rest end point indexes
		{
		    if(currentClient == clients) // make sure we don't draw the line to the same player
				continue;
				
			if(IsClientAlive(currentClient) && IsClientAlive(clients)) // make sure the client is alive
			{
				// draw the line from client A to B using their indexes 
				TE_SetupBeamLaser(currentClient,clients, g_iBeamSprite, g_iHaloSprite, 0, 10, 0.5, 0.1, 0.1, 1, 0.0, {255, 0, 0, 255}, 10);
				TE_SendToAll();
			}
		}
    }
}
ShD3luxe is offline
Halt
Senior Member
Join Date: Jan 2015
Location: Black Mesa
Old 08-19-2019 , 15:55   Re: SetupBeamLaser to all clients
Reply With Quote #7

Yea ignore what I said, follow ShD3luxe. I was thinking of TR_TraceRay
Halt is offline
Minfas
Junior Member
Join Date: Dec 2017
Old 08-19-2019 , 17:52   Re: SetupBeamLaser to all clients
Reply With Quote #8

Quote:
Originally Posted by ShD3luxe View Post
As I said TE_SetupBeamLaser needs the start entity index and end entity index you don't need any position vector.
Try like this (I don't recommend doing this bcs it will make your server laggy) :
Code:
public DrawLinesToAll()
{
    for(int currentClient = 1;currentClient <= MaxClients;currentClient++) // the first loop to get the start point index
    {
		if(!IsClientAlive(currentClient)) // make sure the player is alive
			continue;
			
        for(int clients = 1;clients <= MaxClients;clients++) // the second loop to get the rest end point indexes
		{
		    if(currentClient == clients) // make sure we don't draw the line to the same player
				continue;
				
			if(IsClientAlive(currentClient) && IsClientAlive(clients)) // make sure the client is alive
			{
				// draw the line from client A to B using their indexes 
				TE_SetupBeamLaser(currentClient,clients, g_iBeamSprite, g_iHaloSprite, 0, 10, 0.5, 0.1, 0.1, 1, 0.0, {255, 0, 0, 255}, 10);
				TE_SendToAll();
			}
		}
    }
}
Thanks for help! Its working, but I have few more questions.
The beam is attached to player's hand and its moving with all animations of the model, is there any way to make it pointing at player's feet?

And last thing is that the beam is visible only in certain field of view. (For example I can't see beam pointing at player that is like above me.)

Last edited by Minfas; 08-19-2019 at 17:53.
Minfas is offline
ShD3luxe
Member
Join Date: Aug 2019
Location: Localhost
Old 08-19-2019 , 18:58   Re: SetupBeamLaser to all clients
Reply With Quote #9

If you want to control the position of the beam in space then use TE_SetupBeamPoints and check if the player's z position are equal to not spawn the line.The problem here is that u need to create a timer to check every time for all players position and that will eat a lot of resources.
Doc -> https://sm.alliedmods.net/new-api/sd...etupBeamPoints
Code :
Code:
public DrawLinesToAll()
{
    for(int currentClient = 1;currentClient <= MaxClients;currentClient++) // the first loop to get the start point index
    {
		if(!IsClientAlive(currentClient)) // make sure the player is alive
			continue;
			
		float fstartPosition[3],fendPosition[3]; // x y z float vector position
		GetClientAbsOrigin(currentClient, fstartPosition); // get the position of the client in the vector
		
        for(int clients = 1;clients <= MaxClients;clients++) // the second loop to get the end point positions
		{
		    if(currentClient == clients) // make sure we don't draw the line from-to the same player
				continue;
				
			if(IsClientAlive(currentClient) && IsClientAlive(clients)) // make sure the client is alive
			{
				GetClientAbsOrigin(clients, fendPosition); // get the end point client position
				// do checks here 
				if(fstartPosition[2] != fendPosition[2]) // you can do checks based on position here ( here I checked that the z axis of the clients to not be equal )
				{
					// draw the line from client A position to client B position
					TE_SetupBeamPoints(fstartPosition,fendPosition, g_iBeamSprite, g_iHaloSprite, 0, 10, 0.5, 0.1, 0.1, 1, 0.0, {255, 0, 0, 255}, 10);
					TE_SendToAll();
				}
			}
		}
    }
}
ShD3luxe is offline
Minfas
Junior Member
Join Date: Dec 2017
Old 08-20-2019 , 11:58   Re: SetupBeamLaser to all clients
Reply With Quote #10

Thank you for help! <3
Minfas is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:20.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode