Raised This Month: $ Target: $400
 0% 

combine PrintToChat()'s


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
klashfire
Member
Join Date: May 2014
Location: NY, USA
Old 04-12-2016 , 12:16   combine PrintToChat()'s
Reply With Quote #1

say I used
PrintToChat(client, "your messages were %s", msg1)
and then I wanted it to loop a print to chat until all messages were output, so
PrintToChat(client, "and %s", loopmsg)

so let's say it might output
your messages were potato guy
and urinal
and dental problems
and constipation

(all bold messages are client entered)
How would I get those "and %s" messages into one chat message, so it would be
and urinal and dental problems and constipation?
__________________

klashfire is offline
humbugtheman
Member
Join Date: Jan 2012
Old 04-12-2016 , 12:24   Re: combine PrintToChat()'s
Reply With Quote #2

Could you use the "Format" function inside the loop to create the string you want to print, and then print the entire string after the loop has ended?
humbugtheman is offline
Farbror Godis
AlliedModders Donor
Join Date: Feb 2016
Old 04-12-2016 , 12:58   Re: combine PrintToChat()'s
Reply With Quote #3

There's a function for this, ImplodeStrings.

Store your strings in a two dimensional array, an example of use:
PHP Code:
char names[MAXPLAYERS][MAX_NAME_LENGTH];
int count;

for(
int i 1<= MaxClientsi++) {
    if(
IsClientInGame(i)) {
        
Format(names[count++], sizeof(names[]), "%N"i);
    }
}

char buffer[193]; // Max length of chat messages in CS:S + 1 to account for null terminator.
ImplodeStrings(namescount", "buffersizeof(buffer));

PrintToChatAll("Players: %s"buffer); 
Output: "Players: klashfire, humbugtheman, Farbror Godis^"

EDIT: Made a mistake.

Last edited by Farbror Godis; 04-12-2016 at 13:54. Reason: Mistake
Farbror Godis is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 04-12-2016 , 16:40   Re: combine PrintToChat()'s
Reply With Quote #4

Quote:
Originally Posted by Farbror Godis View Post
There's a function for this, ImplodeStrings
Store your strings in a two dimensional array
You could also:
PHP Code:
new String:msg[256];
Format(msgsizeof(msg), "Your messages were %s"FIRST_MESSAGE);
[FOR/WHILE 
LOOP HERE]{
    
Format(msgsizeof(msg), "%s and %s"msgSTRING_TO_ADD_HERE);
}
PrintToChat(clientmsg); 

Last edited by thecount; 04-12-2016 at 16:41.
thecount 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 21:00.


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