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

[TF2] Selecting multiple people


Post New Thread Reply   
 
Thread Tools Display Modes
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 10-02-2016 , 19:48   Re: [TF2] Selecting multiple people
Reply With Quote #11

If, for some strange reason, you wanted to re-create @red (which already exists), here's how you'd do it:

PHP Code:
public void OnPluginStart() {
    
AddMultiTargetFilter("@red2"TargetFilter_red2"Red Team"false);
}

public 
void OnPluginEnd() {
    
RemoveMultiTargetFilter("@red2"TargetFilter_red2);
}

public 
bool TargetFilter_red2(const char[] sPatternHandle hClients) {
    
bool foundTarget;
    for(
int i 1<= MaxClientsi++) {
        if (
IsClientInGame(i) && TF2_GetClientTeam(client) == TFTeam_Red) {
            
PushArrayCell(hClientsi);
            
foundTarget true;
        }
    }
    return 
foundTarget;

__________________

Last edited by ddhoward; 10-02-2016 at 20:31. Reason: fixing the error pointed out two posts below this
ddhoward is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 10-02-2016 , 20:03   Re: [TF2] Selecting multiple people
Reply With Quote #12

You should be able to use ProcessTargetString in your command callback, which accepts @red or whatever and returns an array of client index.

See this thread I made: https://forums.alliedmods.net/showthread.php?t=270607 (it uses TF2 examples)

Last edited by Potato Uno; 10-02-2016 at 20:10.
Potato Uno is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 10-02-2016 , 20:09   Re: [TF2] Selecting multiple people
Reply With Quote #13

Quote:
Originally Posted by ddhoward View Post
If, for some strange reason, you wanted to re-create @red (which already exists), here's how you'd do it:

PHP Code:
public void OnPluginStart() {
    
AddMultiTargetFilter("@red2"TargetFilter_red2"Red Team"false);
}

public 
void OnPluginEnd() {
    
RemoveMultiTargetFilter("@red2"TargetFilter_red2);
}

public 
bool TargetFilter_red2(const char[] sPatternHandle hClients) {
    
bool foundTarget;
    for(
int i 1<= MaxClientsi++) {
        if (
IsClientInGame(i) && TF2_GetClientTeam(client) == TFTeam_Red)
            
PushArrayCell(hClientsi);
            
foundTarget true;
    }
    return 
foundTarget;

Not sure if I am reading this wrong but I think you need braces around the if () statement. As it stands, it will only push the client index if the team is red, but foundTarget will be set to true every time the loop runs even if you don't find a RED player (outside the if statement).
Potato Uno is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 10-02-2016 , 20:30   Re: [TF2] Selecting multiple people
Reply With Quote #14

You're totally right, I omitted the braces because there was only one line within the if statement; I neglected to add the braces back in once I added the second line.
__________________
ddhoward is offline
Phil25
AlliedModders Donor
Join Date: Feb 2015
Old 10-03-2016 , 02:08   Re: [TF2] Selecting multiple people
Reply With Quote #15

Check if TF2_GetClientTeam(client) == TFTeam_Red

Edit: Oh woops, I forgot there was a second page...

Last edited by Phil25; 10-03-2016 at 02:09.
Phil25 is offline
BraveFox
AlliedModders Donor
Join Date: May 2015
Location: Israel
Old 10-03-2016 , 04:24   Re: [TF2] Selecting multiple people
Reply With Quote #16

Quote:
Originally Posted by Riotline View Post
Ye but how do I make the MultiTargetFilter for red team like Phil25 said but specific for red team

also anyone know how to randomize only red team xD
1.Team chat?
2.GetRandomPlayer(GetRandomPlayerFilter_Red);
__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests
BraveFox is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-03-2016 , 12:05   Re: [TF2] Selecting multiple people
Reply With Quote #17

Quote:
Originally Posted by ddhoward View Post
You're totally right, I omitted the braces because there was only one line within the if statement; I neglected to add the braces back in once I added the second line.
This is why the programming standards at my last job required braces even for single line if blocks.
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 14:38.


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