AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need help with change command syntax (https://forums.alliedmods.net/showthread.php?t=334268)

kww 09-11-2021 08:36

Need help with change command syntax
 
Hi men! I made some command to set player's team. (I needed it and I made it) It works cool, but not as I wanted first.
Syntax now: setteam <team: t|ct|spec> [name or #userid] [kill]
Is it possible to make it like this: setteam [name or #userid] <team: t|ct|spec> [kill]
I think it is possible but players can't have names like in teams' tokens, am i right?

PHP Code:

public setteam_command(executor)
{
    new 
team[5]
    
read_argv(1teamcharsmax(team))
    
    if(!
team[0]) console_print(executor"[%s] Usage: setteam <team: t|ct|spec> [name or #userid] [kill]"PLUGIN_NAME)
    else if(
equali(team"t") || equali(team"ct") || equali(team"spec"))
    {
        new 
targetargs_num read_argc() - 1
        
if(args_num 1)
        {
            new 
szPlayer[MAX_NAME_LENGTH]
            
read_argv(2szPlayercharsmax(szPlayer))
            
            
target cmd_target(executorszPlayerCMDTARGET_ALLOW_SELF)
            
            if(!
target// player is NOT found
            
{
                
console_print(executor"[%s] Error: wrong argument 2 (Player ^"%s^" not found)"PLUGIN_NAMEszPlayer)
                return 
PLUGIN_HANDLED
            
}
            
            new 
kill[5]
            
read_argv(3killcharsmax(kill))
            if(
kill[0])
            {
                if(
equali(kill"kill"))
                    
_kill(target)
                else {
                    
console_print(executor"[%s] Error: wrong argument 3 (%s)"PLUGIN_NAMEkill)
                    return 
PLUGIN_HANDLED
                
}
            }
        }
        else 
target executor
        
        
switch(team[0])
        {
            case 
't'cs_set_user_team(targetCS_TEAM_T)
            case 
'c'cs_set_user_team(targetCS_TEAM_CT)
            case 
's'cs_set_user_team(targetCS_TEAM_SPECTATOR)
        }
    }
    else 
client_print(executorprint_console"[%s] Error: wrong argument 1 (%s)"PLUGIN_NAMEteam)
    
    return 
PLUGIN_HANDLED



HamletEagle 09-11-2021 08:41

Re: Need help with change command syntax
 
If you made it then you should be more than capable of switching the indices inside read_argv.

kww 09-11-2021 10:54

Re: Need help with change command syntax
 
Quote:

Originally Posted by HamletEagle (Post 2757481)
If you made it then you should be more than capable of switching the indices inside read_argv.

ok i will try

fysiks 09-11-2021 17:13

Re: Need help with change command syntax
 
Quote:

Originally Posted by kww (Post 2757480)
Syntax now: setteam <team: t|ct|spec> [name or #userid] [kill]
Is it possible to make it like this: setteam [name or #userid] <team: t|ct|spec> [kill]
I think it is possible but players can't have names like in teams' tokens, am i right?

Why would you think that? If you change the order then you changed the order so the team will always be the second argument regardless of what text you submit for the first argument.

kww 09-12-2021 05:07

Re: Need help with change command syntax
 
Quote:

Originally Posted by fysiks (Post 2757521)
Why would you think that? If you change the order then you changed the order so the team will always be the second argument regardless of what text you submit for the first argument.

Team argument should be necessary. [name or #userid] and [kill] can be omitted. If i will ignore name and want to move myself then syntax will be setteam spec kill, but what if i have player with name "spec"? Then I must throw an error, yes?

fysiks 09-12-2021 08:13

Re: Need help with change command syntax
 
Oh, I see now. All required arguments must be before optional argument if you don't have a definitive way to differentiate between the two types. But if you do have a way to definitively differentiate between them, you would just have a single argument anyways.

I know that some plugins look for "@team" in a player name argument to apply an action to a whole team. However, this relies on a player never having that string in their name and you, as the executer of the function, not trying to apply it to a player using that string.


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

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