AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Can't get a command to target all players (https://forums.alliedmods.net/showthread.php?t=339015)

itsJakub 08-09-2022 16:31

Can't get a command to target all players
 
2 Attachment(s)
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.

Marttt 08-09-2022 17:35

Re: Can't get a command to target all players
 
Try using sm_beacon as an example:

https://github.com/alliedmodders/sou...n.sp#L201-L244

Sreaper 08-10-2022 00:00

Re: Can't get a command to target all players
 
Quote:

Originally Posted by itsJakub (Post 2786016)
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;



Bacardi 08-10-2022 04:37

Re: Can't get a command to target all players
 
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;




All times are GMT -4. The time now is 07:16.

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