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

teleport


Post New Thread Reply   
 
Thread Tools Display Modes
Whai
Senior Member
Join Date: Jul 2018
Old 07-13-2019 , 13:46   Re: teleport
Reply With Quote #11

The "IsClientConnected" with "IsPlayerAlive" (I forgot about that) have to be after the comparison, because it would check on every client
Change "tp <client>" into "sm_tp <client>"
__________________

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

so like this?
PHP Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR ""
#define PLUGIN_VERSION "0.00"

#include <sourcemod>
#include <sdktools>
#include <cstrike>
//#include <sdkhooks>

#pragma newdecls required


public Plugin myinfo 
{
    
name "",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
RegAdminCmd("sm_tp"tpADMFLAG_KICK);
}

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 1<= MaxClientsi++){
        
            
GetClientName(iClientnamesizeof(Clientname));
            if(
StrEqual(Enteredname,Clientname)){
        
                if(
IsClientConnected(i)){
            
                    if(
IsPlayerAlive(i))
                    {
                    
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;


Last edited by Doggg; 07-13-2019 at 14:39.
Doggg is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-13-2019 , 14:35   Re: teleport
Reply With Quote #13

You're doing it all wrong. There's already a specific method for targeting players without checking for their names. In fact, finding players via name is bad practice.

Here's how it should be done:

PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
RegAdminCmd("sm_tp"cmdTeleportADMFLAG_KICK"Teleport a player to your position.");
}

public 
Action cmdTeleport(int clientint args)
{
    if (
client <= || client MaxClients || !IsClientInGame(client) || !IsPlayerAlive(client))
    {
        
ReplyToCommand(client"[SM] You must be in-game and alive to teleport players to your position.");

        return 
Plugin_Handled;
    }

    switch (
args)
    {
        case 
1:
        {
            
float flPos[3];
            
GetClientAbsOrigin(clientflPos);

            
char target[32], target_name[32];
            
int target_list[MAXPLAYERS], target_count;
            
bool tn_is_ml;
            
GetCmdArg(1targetsizeof(target));

            if ((
target_count ProcessTargetString(targetclienttarget_listMAXPLAYERSCOMMAND_FILTER_NO_BOTS|COMMAND_FILTER_ALIVEtarget_namesizeof(target_name), tn_is_ml)) <= 0)
            {
                
ReplyToTargetError(clienttarget_count);
                return 
Plugin_Handled;
            }

            for (
int iPlayer 0iPlayer target_countiPlayer++)
            {
                if (
target_list[iPlayer] <= MaxClients && IsClientInGame(target_list[iPlayer]))
                {
                    
TeleportEntity(target_list[iPlayer], flPosNULL_VECTORNULL_VECTOR);
                    
ReplyToCommand(client"[SM] You teleported %N to your position."target_list[iPlayer]);
                    
PrintToChat(target_list[iPlayer], "[SM] You were teleported to %N's position."client);
                }
            }
        }
        default: 
ReplyToCommand(client"[SM] Usage: sm_tp <#userid|name>");
    }

    return 
Plugin_Handled;

This allows you to use target filters like @red and @blue, and also allows you to target User IDs and Steam IDs. It's safer and more accurate.
__________________

Last edited by Psyk0tik; 07-13-2019 at 14:37.
Psyk0tik is offline
Doggg
Member
Join Date: Jun 2018
Old 07-13-2019 , 14:42   Re: teleport
Reply With Quote #14

Quote:
Originally Posted by Crasher_3637 View Post
You're doing it all wrong. There's already a specific method for targeting players without checking for their names. In fact, finding players via name is bad practice.

Here's how it should be done:

PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
RegAdminCmd("sm_tp"cmdTeleportADMFLAG_KICK"Teleport a player to your position.");
}

public 
Action cmdTeleport(int clientint args)
{
    if (
client <= || client MaxClients || !IsClientInGame(client) || !IsPlayerAlive(client))
    {
        
ReplyToCommand(client"[SM] You must be in-game and alive to teleport players to your position.");

        return 
Plugin_Handled;
    }

    switch (
args)
    {
        case 
1:
        {
            
float flPos[3];
            
GetClientAbsOrigin(clientflPos);

            
char target[32], target_name[32];
            
int target_list[MAXPLAYERS], target_count;
            
bool tn_is_ml;
            
GetCmdArg(1targetsizeof(target));

            if ((
target_count ProcessTargetString(targetclienttarget_listMAXPLAYERSCOMMAND_FILTER_NO_BOTS|COMMAND_FILTER_ALIVEtarget_namesizeof(target_name), tn_is_ml)) <= 0)
            {
                
ReplyToTargetError(clienttarget_count);
                return 
Plugin_Handled;
            }

            for (
int iPlayer 0iPlayer target_countiPlayer++)
            {
                if (
target_list[iPlayer] <= MaxClients && IsClientInGame(target_list[iPlayer]))
                {
                    
TeleportEntity(target_list[iPlayer], flPosNULL_VECTORNULL_VECTOR);
                    
ReplyToCommand(client"[SM] You teleported %N to your position."target_list[iPlayer]);
                    
PrintToChat(target_list[iPlayer], "[SM] You were teleported to %N's position."client);
                }
            }
        }
        default: 
ReplyToCommand(client"[SM] Usage: sm_tp <#userid|name>");
    }

    return 
Plugin_Handled;

This allows you to use target filters like @red and @blue, and also allows you to target User IDs and Steam IDs. It's safer and more accurate.
DUDEEEEEEE ITS SOO COMPLICATED, can you explain this code a bit? i am a begginer lol
Doggg is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 07-13-2019 , 14:57   Re: teleport
Reply With Quote #15

Quote:
Originally Posted by Doggg View Post
DUDEEEEEEE ITS SOO COMPLICATED, can you explain this code a bit? i am a begginer lol
I will try my best and start from top to bottom.

First, the if statement is saying that if the client has an invalid index OR is not in-game OR is dead, he/she cannot use the command.

Second, inside the switch statement... If the client enters more or less than 1 argument, a message will be displayed to him/her saying how to properly use the command. If the client enters 1 argument, the plugin will get the client's position (origin vector).

Lastly, once the client's origin vector is retrieved, the plugin will look through the current list of players and filter out any bots and dead players, and once it finds players that match the name (ex: Doggg), User ID, Steam ID, or target filter (ex: @red), those players will be teleported to the client.

Examples:

sm_tp Doggg - this will teleport you to me.
sm_tp #123 - this will teleport the client with the User ID of 123 to me.
sm_tp @red - this will teleport all players on red team to me.

The key function you need to access these targeting features is ProcessTargetString because it will allow the plugin to retrieve the list of players that match your argument and will loop through the list to teleport each player to your position.

PHP Code:
char target[32], target_name[32];
int target_list[MAXPLAYERS], target_count;
bool tn_is_ml;
GetCmdArg(1targetsizeof(target)); // get the 1st argument of the command.

if ((target_count ProcessTargetString(targetclienttarget_listMAXPLAYERSCOMMAND_FILTER_NO_BOTS|COMMAND_FILTER_ALIVEtarget_namesizeof(target_name), tn_is_ml)) <= 0)
{
    
ReplyToTargetError(clienttarget_count); // display error message to client if target(s) cannot be retrieved, if target cannot be found, etc.
    
return Plugin_Handled;

I hope this will give you some understanding of how the code works.
__________________
Psyk0tik is offline
Nexd
BANNED
Join Date: Dec 2013
Location: Hungary
Old 07-13-2019 , 19:38   Re: teleport
Reply With Quote #16

You can get the client target like this:

PHP Code:
char argument[MAX_NAME_LENGTH];
GetCmdArg(1argumentsizeof(argument));
int target FindTarget(clientargumenttrue); 

Last edited by Nexd; 07-13-2019 at 19:38.
Nexd is offline
Reply



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 17:37.


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