Raised This Month: $32 Target: $400
 8% 

teleport


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Doggg
Member
Join Date: Jun 2018
Old 07-12-2019 , 19:39   teleport
Reply With Quote #1

Hey guys, I am trying to make a plugin that when client write /tp <client name> it will teleport the sec client (the one that was wrote in the plugin) to the aim of the main client (the one who called the plugin).
how do i teleport people?
how do i get the aim coordinates of the main player (where he is aiming at).
Doggg is offline
Nexd
BANNED
Join Date: Dec 2013
Location: Hungary
Old 07-12-2019 , 20:49   Re: teleport
Reply With Quote #2

If he is aiming on another player you can use the GetClientAimTarget

For teleport, you can use TeleportEntity

Firstly, get the player origin (Where you want to teleport the other player):
method 1: GetClientAbsOrigin
PHP Code:
float origin[3];
GetClientAbsOrigin(clientorigin); 
method 2:
PHP Code:
float pos[3];
GetEntPropVector(clientProp_Send"m_vecOrigin"pos); 
Then
PHP Code:
TeleportEntity(clientoriginNULL_VECTORNULL_VECTOR); 

Last edited by Nexd; 07-12-2019 at 20:50.
Nexd is offline
Doggg
Member
Join Date: Jun 2018
Old 07-13-2019 , 08:24   Re: teleport
Reply With Quote #3

Quote:
Originally Posted by Nexd View Post
If he is aiming on another player you can use the GetClientAimTarget

For teleport, you can use TeleportEntity

Firstly, get the player origin (Where you want to teleport the other player):
method 1: GetClientAbsOrigin
PHP Code:
float origin[3];
GetClientAbsOrigin(clientorigin); 
method 2:
PHP Code:
float pos[3];
GetEntPropVector(clientProp_Send"m_vecOrigin"pos); 
Then
PHP Code:
TeleportEntity(clientoriginNULL_VECTORNULL_VECTOR); 

thanks, what is this null_vector?
what is the diffrence between the two methods? they both will give me the cords the player is aiming at?
thansk!
Doggg is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-13-2019 , 10:19   Re: teleport
Reply With Quote #4

Quote:
Originally Posted by Doggg View Post
thanks, what is this null_vector?
what is the diffrence between the two methods? they both will give me the cords the player is aiming at?
thansk!
NULL_VECTOR is passed when you don't want to change the value of the vector. In this case, you're only teleporting the client to the target's position without worrying about the client's angles and velocity. According to the API, here are the parameters of the TeleportEntity() function: void TeleportEntity(int entity, const float origin[3], const float angles[3], const float velocity[3])

As for your next question, the 1st method specifically retrieves a client's origin vector while the 2nd method can be used to retrieve the origin vector of both clients and non-client entities. Using either one should suffice your needs.
__________________

Last edited by Psyk0tik; 07-13-2019 at 10:20.
Psyk0tik is offline
Doggg
Member
Join Date: Jun 2018
Old 07-13-2019 , 11:45   Re: teleport
Reply With Quote #5

Quote:
Originally Posted by Crasher_3637 View Post
NULL_VECTOR is passed when you don't want to change the value of the vector. In this case, you're only teleporting the client to the target's position without worrying about the client's angles and velocity. According to the API, here are the parameters of the TeleportEntity() function: void TeleportEntity(int entity, const float origin[3], const float angles[3], const float velocity[3])

As for your next question, the 1st method specifically retrieves a client's origin vector while the 2nd method can be used to retrieve the origin vector of both clients and non-client entities. Using either one should suffice your needs.
Thanks! another last question, Any idea how i can check if the name that the main client entered (the one he wants to tp) is there? i should go on for and search one by one or there is some meathod?
Doggg is offline
Doggg
Member
Join Date: Jun 2018
Old 07-13-2019 , 12:21   Re: teleport
Reply With Quote #6

Quote:
Originally Posted by Crasher_3637 View Post
NULL_VECTOR is passed when you don't want to change the value of the vector. In this case, you're only teleporting the client to the target's position without worrying about the client's angles and velocity. According to the API, here are the parameters of the TeleportEntity() function: void TeleportEntity(int entity, const float origin[3], const float angles[3], const float velocity[3])

As for your next question, the 1st method specifically retrieves a client's origin vector while the 2nd method can be used to retrieve the origin vector of both clients and non-client entities. Using either one should suffice your needs.
How this is looking so far? the StrEqual isnt working yet.. how do i fix it?
Code:
public void OnPluginStart()
{
RegAdminCmd("sm_tp", tp, ADMFLAG_KICK);
}

public Action tp(int client, int args)
{
	if(args < 0)
	{
	ReplyToCommand(client, "[SM] tp <client>");
	return Plugin_Handled;
	}
	
	float origin[3];
        GetClientAbsOrigin(client, origin);  
	char name[30]; 
	GetCmdArg(1, name, sizeof(name));
	
	for (int i = 0; i < MaxClients; i++){
		
		if(IsPlayerAlive(i)){
			
			if(IsClientConnected(i))
				{
					if(StrEqual(i,name)){
					
					TeleportEntity(i, origin, NULL_VECTOR, NULL_VECTOR);  
					return Plugin_Handled;
					}							
					
				}

		}
		
	}
	
}

Last edited by Doggg; 07-13-2019 at 12:22.
Doggg is offline
Whai
Senior Member
Join Date: Jul 2018
Old 07-13-2019 , 13:18   Re: teleport
Reply With Quote #7

"IsClientConnected" should be before "IsPlayerAlive".
You have compared an integer with a string. You have to use GetClientName to get the player's name by its index then you can compare
__________________

Last edited by Whai; 07-13-2019 at 13:19.
Whai is offline
Doggg
Member
Join Date: Jun 2018
Old 07-13-2019 , 13:28   Re: teleport
Reply With Quote #8

Quote:
Originally Posted by Whai View Post
"IsClientConnected" should be before "IsPlayerAlive".
You have compared an integer with a string. You have to use GetClientName to get the player's name by its index then you can compare
Ok, I will fix that, But I try to run with this code :
and its says, Unknown command tp. you know why?
Code:
public Action tp(int client, int args)
{
	if(args < 0)
	{
	ReplyToCommand(client, "[SM] tp <client>");
	return Plugin_Handled;
	}
	
	float origin[3];
    GetClientAbsOrigin(client, origin);  
	char Enteredname[30]; 
	GetCmdArg(1, Enteredname, sizeof(Enteredname));
	char Clientname[30];
	
	for (int i = 0; i < MaxClients; i++){
		
		if(IsPlayerAlive(i)){
			
			if(IsClientConnected(i))
				{
					GetClientName(i, Clientname, sizeof(Clientname));
					if(StrEqual(Enteredname,Clientname)){
					PrintToChat(client, "\x04 You Teleported \x03 %s",Clientname);
					PrintToChat(i, "\x03 %s Teleported \x04 You",client);
					TeleportEntity(i, origin, NULL_VECTOR, NULL_VECTOR);  
					return Plugin_Handled;
					}							
					
				}

		}
			else
		{
	     ReplyToCommand(client, "Please Enter A Alive Player");
	     return Plugin_Handled;
		}
		
		
	}
	return Plugin_Handled;

Last edited by Doggg; 07-13-2019 at 13:28.
Doggg is offline
Whai
Senior Member
Join Date: Jul 2018
Old 07-13-2019 , 13:33   Re: teleport
Reply With Quote #9

Can you write you code in PHP quote ? because it is better with colors.

Quote:
Originally Posted by Doggg View Post
Ok, I will fix that, But I try to run with this code :
and its says, Unknown command tp. you know why?
because you write in your console "tp" instead of "sm_tp" as I can see on your RegAdminCmd
__________________
Whai is offline
Doggg
Member
Join Date: Jun 2018
Old 07-13-2019 , 13:41   Re: teleport
Reply With Quote #10

Quote:
Originally Posted by Whai View Post
Can you write you code in PHP quote ? because it is better with colors.



because you write in your console "tp" instead of "sm_tp" as I can see on your RegAdminCmd
lol well i did wrote tp i thought it will work.
the new fixed code:
PHP Code:
public Action tp(int clientint args)
{
    if(
args 0)
    {
    
ReplyToCommand(client"[SM] tp <client>");
    return 
Plugin_Handled;
    }
    
    
float origin[3];
    
GetClientAbsOrigin(clientorigin);  
    
char Enteredname[30]; 
    
GetCmdArg(1Enterednamesizeof(Enteredname));
    
char Clientname[30];
    
    for (
int i 0MaxClientsi++){
        
        if(
IsClientConnected(i)){
            
            if(
IsPlayerAlive(i))
                {
                    
GetClientName(iClientnamesizeof(Clientname));
                    if(
StrEqual(Enteredname,Clientname)){
                    
PrintToChat(client"\x04 You Teleported \x03 %s",Clientname);
                    
PrintToChat(i"\x03 %s Teleported \x04 You",client);
                    
TeleportEntity(ioriginNULL_VECTORNULL_VECTOR);  
                    break;
                    }                            
                    
                }

        }
            else
        {
         
ReplyToCommand(client"Please Enter A Alive Player");
         break;
        }
        
        
    }
    return 
Plugin_Handled;

Doggg 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 09:38.


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