Raised This Month: $12 Target: $400
 3% 

Need help with change command syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 09-11-2021 , 08:36   Need help with change command syntax
Reply With Quote #1

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

__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 09-11-2021 at 08:39.
kww is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-11-2021 , 08:41   Re: Need help with change command syntax
Reply With Quote #2

If you made it then you should be more than capable of switching the indices inside read_argv.
__________________
HamletEagle is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 09-11-2021 , 10:54   Re: Need help with change command syntax
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
If you made it then you should be more than capable of switching the indices inside read_argv.
ok i will try
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951
kww is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-11-2021 , 17:13   Re: Need help with change command syntax
Reply With Quote #4

Quote:
Originally Posted by kww View Post
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.
__________________
fysiks is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 09-12-2021 , 05:07   Re: Need help with change command syntax
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
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?
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 09-12-2021 at 05:12.
kww is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-12-2021 , 08:13   Re: Need help with change command syntax
Reply With Quote #6

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.
__________________
fysiks 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 11:33.


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