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

Can't get a command to target all players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
itsJakub
New Member
Join Date: Aug 2022
Old 08-09-2022 , 16:31   Can't get a command to target all players
Reply With Quote #1

Hi, I'm using the SetEntityGravity command to change the gravity and I'm unsure on how to get it to apply to all players.

I've tried a few methods which didn't work. Currently, I'm trying to define all client numbers and use this in the entity parameters.

Error 035 argument mismatch since this is an invalid entity.
Attached Thumbnails
Click image for larger version

Name:	lg.JPG
Views:	39
Size:	59.5 KB
ID:	196238  
Attached Files
File Type: txt lg.txt (796 Bytes, 20 views)
itsJakub is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 08-09-2022 , 17:35   Re: Can't get a command to target all players
Reply With Quote #2

Try using sm_beacon as an example:

https://github.com/alliedmodders/sou...n.sp#L201-L244
__________________
Marttt is offline
Sreaper
髪を用心
Join Date: Nov 2009
Old 08-10-2022 , 00:00   Re: Can't get a command to target all players
Reply With Quote #3

Quote:
Originally Posted by itsJakub View Post
Hi, I'm using the SetEntityGravity command to change the gravity and I'm unsure on how to get it to apply to all players.

I've tried a few methods which didn't work. Currently, I'm trying to define all client numbers and use this in the entity parameters.

Error 035 argument mismatch since this is an invalid entity.
PHP Code:
#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
RegConsoleCmd("sm_lg"Command_Low_Gravity"Sets a low gravity");
}

public 
Action Command_Low_Gravity(int clientint args)
{
    
char arg[3];
    
GetCmdArg(1argsizeof(arg));
    
int gravity StringToInt(arg);

    if (
args != || !HasOnlyNumbers(arg) || gravity || gravity 1)
    {
        
ReplyToCommand(client"[SM] Usage: sm_lg <0/1>");
        return 
Plugin_Handled;
    }

    for (
int i 1<= MaxClientsi++)
    {
        if (!
IsClientInGame(i)) continue;

        
SetEntityGravity(igravity 0.08 1.0);
    }
    
ReplyToCommand(client"[SM] Low gravity has been %s."gravity "Enabled" "Disabled");
    return 
Plugin_Handled;
}

stock bool HasOnlyNumbers(char[] s) {
    
int len strlen(s);
    for (
int i 0leni++)
        if (!
IsCharNumeric(s[i])) return false;
    return 
true;


Last edited by Sreaper; 08-10-2022 at 17:53. Reason: HasOnlyNumbers
Sreaper is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-10-2022 , 04:37   Re: Can't get a command to target all players
Reply With Quote #4

Either a loop code to look all client indexs, like post above.


Or another function is ProcessTargetString(), which is little advance
https://sm.alliedmods.net/new-api/co...ssTargetString

PHP Code:



public void OnPluginStart()
{
    
RegConsoleCmd("sm_test1"test1);
    
RegConsoleCmd("sm_test2"test2);

    
LoadTranslations("common.phrases"); // You need load translation files when use ProcessTargetString and ReplyToTargetError()
}

void PrintPlayerNameInConsole(int clientint target)
{
    
PrintToConsole(client"Index %i = Player %N"targettarget);
}



public 
Action test1(int clientint args)
{
    for(
int i 1<= MaxClientsi++)
    {
        if(!
IsClientInGame(i) || IsClientSourceTV(i) || IsClientReplay(i))
            continue;

        
PrintPlayerNameInConsole(clienti);
    }

    return 
Plugin_Handled;
}

public 
Action test2(int clientint args)
{
    
// When using command without arguments, print command tip
    
if(args 1)
    {
        
ReplyToCommand(client"[SM] Command usage: sm_test2 @all, sm_test2 @me, sm_test2 @!me, sm_test2 #userid, sm_test2 \"#STEAM_0:1:123\"");

        return 
Plugin_Handled;
    }

    
// Get command first argument
    
char pattern[MAX_NAME_LENGTH];
    
GetCmdArg(1patternsizeof(pattern));




    
int targetcount;
    
int targetsarray[MAXPLAYERS+1];

    
char target_name[MAX_NAME_LENGTH];

    
bool tn_is_ml// true, when target_name return as multi-target phrase. False, when return one target name

    
targetcount ProcessTargetString(pattern,
                                    
0,    // When admin is server console = 0 index, we bypass admin immunity check
                                    
targetsarray,
                                    
sizeof(targetsarray),
                                    
0,
                                    
target_name,
                                    
sizeof(target_name),
                                    
tn_is_ml);

    if(
targetcount <= COMMAND_TARGET_NONE)
    {
        
ReplyToTargetError(clienttargetcount);
        return 
Plugin_Handled;
    }
    else
    {
        for(
int x 0targetcountx++)
        {
            
PrintPlayerNameInConsole(clienttargetsarray[x]);
        }
        
        if(
tn_is_ml)
        {
            
PrintToConsole(client"tn_is_ml - Admin argument %s, target to %s"patterntarget_name);
        }
        else
        {
            
PrintToConsole(client"Admin argument %s, target to %s"patterntarget_name);
        }
    }

    return 
Plugin_Handled;

__________________
Do not Private Message @me
Bacardi 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 15:30.


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