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

Solved Get player by name pattern


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 05-22-2020 , 10:02   Get player by name pattern
Reply With Quote #1

Hi, I'm trying to allow players to do !invite <playername>, but using ProcessTargetString does not seem to work properly for non-admins..?

My code:
PHP Code:
char target_name[MAX_TARGET_LENGTH];
int target_list[MAXPLAYERS], target_count;
bool tn_is_ml;

if((
target_count ProcessTargetString(argclienttarget_listMAXPLAYERSCOMMAND_FILTER_NO_BOTS|COMMAND_FILTER_NO_MULTItarget_namesizeof(target_name), tn_is_ml)) <= 0) {
    
ReplyToTargetError(clienttarget_count);
    return 
false;
}

for(
int usr 0usr target_countusr++) { // target_list[usr] is now the target entity index
    
if(!IsValidClient(target_list[usr], _true))
        continue;
    if(
target_list[usr] == client) { // Make sure target is not the client
        // Cannot invite yourself
        
break;
    }
    
    
CPrintToChat(client"Invite sent to %N !"target_list[usr]);

But it doesn't seem to work properly..

If I try to target anyone I get:
[SM] You cannot target this player.

Is there another way to do this, allowing players without flags to use it?
__________________

Last edited by condolent; 05-22-2020 at 10:27.
condolent is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-22-2020 , 10:11   Re: Get player by name pattern
Reply With Quote #2

Add COMMAND_FILTER_NO_IMMUNITY to your COMMAND_FILTER_ flags.

Given the flags you're using, using FindTarget might simplify your code.
__________________

Last edited by asherkin; 05-22-2020 at 10:12.
asherkin is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 05-22-2020 , 10:27   Re: Get player by name pattern
Reply With Quote #3

Quote:
Originally Posted by asherkin View Post
Add COMMAND_FILTER_NO_IMMUNITY to your COMMAND_FILTER_ flags.

Given the flags you're using, using FindTarget might simplify your code.
Yeah, FindTarget was actually way easier! Thanks
__________________
condolent 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 22:13.


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