Raised This Month: $ Target: $400
 0% 

[CSS] How to get char on String array index


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BAILANDO
Senior Member
Join Date: Feb 2015
Location: Slovakia
Old 05-11-2015 , 15:25   [CSS] How to get char on String array index
Reply With Quote #1

Hello, i need help, how to get char on index position in String, for example "abcd" and i need to get 'd' then String:msg[10] have "abcdefghi" and msg[3] have 'd', but if i make printtochat(client, msg[3]) then i see in chat efghi. Then please, how can i get this char, i need it for check, if first char is ! or / (command string)

Code:
public OnPluginStart(){     RegConsoleCmd("test", Test); } public OnMapStart(){ } public OnMapEnd(){ } public Action:Test(id, args){     new String:msg[10];     Format(msg, 10, "abcdefghij");     if(StrEqual(msg[0], "a")){         PrintToChat(id, "first letter is a");     }     else{         PrintToChat(id, "first lettet isn't a");     } }
BAILANDO is offline
KyleS
SourceMod Plugin Approver
Join Date: Jul 2009
Location: Segmentation Fault.
Old 05-11-2015 , 15:41   Re: [CSS] How to get char on String array index
Reply With Quote #2

If you need to get the 'd', use FindCharInString. If you're wanting to print a single character, use %c.

http://www.cplusplus.com/reference/cstdio/printf/

There are a few extensions in pawn, such as %b and %N.
KyleS is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 05-11-2015 , 17:36   Re: [CSS] How to get char on String array index
Reply With Quote #3

Use this to check for the first character
PHP Code:
if (msg[0] == 'a')
{
    
// First char is an a

You should read this.
__________________

Last edited by Impact123; 05-11-2015 at 17:46.
Impact123 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-12-2015 , 09:47   Re: [CSS] How to get char on String array index
Reply With Quote #4

This sounds suspiciously like an XY Problem.

Why do you need to know if the first character is ! or / ?

RegConsoleCmd and RegAdminCmd will both register / and ! commands for you. You can override existing commands (including / and ! commands) using AddCommandListener.

For catching chat commands without / and !, there's the OnClientSayCommand and OnClientSayCommand_Post callbacks. As far as I'm aware, these aren't called until after command processing from the previous 3 commands are finished.

As a last resort, you can manually hook say and say_team commands and use IsChatTrigger to see if they will fire a command.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 05-12-2015 at 09:48.
Powerlord is offline
sinsic
Senior Member
Join Date: May 2012
Old 05-12-2015 , 10:51   Re: [CSS] How to get char on String array index
Reply With Quote #5

So you want to print the 4. character of string msg[10] which contains "abcdefghi"?
I don't know if there is a shorter way but this works.

PHP Code:
new String:msg[10];
Format(msgsizeof(msg), "abcdefghi");
new 
String:sWantedChar[2];
strcopy(sWantedCharsizeof(sWantedChar), msg[3]);
PrintToChatAll(sWantedChar); 
If you are just checking if it has ! or / for the first character it is way more easier.
PHP Code:
FindCharInString(msg"!"); 
It returns "-1" if ! is not found in the string, or the position if it is found so you can check if it is at start.
__________________

Last edited by sinsic; 05-12-2015 at 11:16.
sinsic is offline
BAILANDO
Senior Member
Join Date: Feb 2015
Location: Slovakia
Old 05-12-2015 , 12:34   Re: [CSS] How to get char on String array index
Reply With Quote #6

Thanks for help

Powerlord: i have program for anonym chat, because admins have [TAG] before name like [ADMIN] etc, and if he say /enable (sm_enable), then he write without tag with default team color, but if he write /disable or /admin etc, then all players see what he write because this anonym chat work like: block default msg if client have true in boolarray with sm_enable and say PrintToChat into chat with ifs like(if...==CS_TEAM_T) or if(IsPlayerAlive) etc for making *DEAD* before name and what see this message like normal chat. Only for this i need to check if first char is / or !

Thanks again.
BAILANDO 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 00:30.


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