Raised This Month: $ Target: $400
 0% 

Solved Replacing a SayText message with arguments


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-01-2017 , 12:54   Replacing a SayText message with arguments
Reply With Quote #1

PHP Code:
public plugin_init()
    
register_message(get_user_msgid("TextMsg"), "msgTextMsg")

public 
msgTextMsg(iMessageiDestid)

    static 
szMessage[32]
    
get_msg_arg_string(2szMessagecharsmax(szMessage))
    
    
set_hudmessage(bla bla)
    
show_hudmessage(idszMessage)

If the message contains arguments, like this one:

PHP Code:
"Cstrike_TitlesTXT_Game_bomb_drop"            "%s1 dropped the bomb" 
... how do I get the full formated message without the "%s" and send it as a HUD message?
__________________

Last edited by OciXCrom; 02-02-2017 at 09:50.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-01-2017 , 13:22   Re: Replacing a SayText message with arguments
Reply With Quote #2

Code:
byte	DestinationType
string	Message
string	Submsg
string	Submsg
string	Submsg
string	Submsg
__________________

Last edited by HamletEagle; 02-01-2017 at 13:22.
HamletEagle is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-01-2017 , 14:59   Re: Replacing a SayText message with arguments
Reply With Quote #3

So, how would I format the message acording to the number of substrings? I know that I can find their number with get_msg_args(), but how to add them in the message?

PHP Code:
new szSubString[get_msg_args()][32]
// This is invalid, because it isn't a constant expression

format(szMessagecharsmax(szMessage), "%s"szMessageszSubstring[0], szSubstring[1], ...) // ? 
This has been bugging me for a long time and I still don't have a clue how to do it. I just need the %s parameters to be automatically replaced by the respective substrings.
__________________

Last edited by OciXCrom; 02-01-2017 at 14:59.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-01-2017 , 15:30   Re: Replacing a SayText message with arguments
Reply With Quote #4

I tried using format_args(), but it returns a blank string. Not even sure if this function is used here.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
SpannerSpammer
Member
Join Date: Mar 2006
Old 02-02-2017 , 08:42   Re: Replacing a SayText message with arguments
Reply With Quote #5

You need to rebuild the message being sent by mapping out what the
final message text is being processed by the client. In your example
here, the bomb drop TextMsg #Game_bomb_drop is sent to the
client, who then looks up the entry in cstrike/titles.txt which is another
localized string: #Cstrike_TitlesTXT_Game_bomb_drop which
is then looked up in resource/cstrike_english.txt .

Simplify this process so that you get the final msg from the TextMsg
by using you own function to map out the messages being sent.
CS doesn't seem to use more than 3 of the 4 optional substrings BTW.

The code below is untested, but you get the picture.

Spoiler
__________________
[NeoTF|DEV]SpannerSpammer-[AoE]-
NeoTF Development Team.
http://steamcommunity.com/groups/neotf
SpannerSpammer is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-02-2017 , 09:23   Re: Replacing a SayText message with arguments
Reply With Quote #6

So basically I'll need to check the number of parameters 1 by 1 and form the messages with all the checks again. I guess I can do that if there's no easier way.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-02-2017 , 09:50   Re: Replacing a SayText message with arguments
Reply With Quote #7

Oh, I actually came up with an automized way to do this using a simple loop:

PHP Code:
public msgTextMsg(iMessageiDestid)

    static 
szMessage[64]
    
get_msg_arg_string(2szMessagecharsmax(szMessage))
    
    if(
TrieKeyExists(g_eTries[TRIE_MESSAGES], szMessage))
    {
        new 
szNewMessage[128], iType
        TrieGetString
(g_eTries[TRIE_MESSAGES], szMessageszNewMessagecharsmax(szNewMessage))
        
TrieGetCell(g_eTries[TRIE_TYPE], szMessageiType)
        
        new 
iArgs get_msg_args()
        
        if(
iArgs 2)
        {
            for(new 
szSubString[32], 2iArgsi++)
            {
                
get_msg_arg_string(1szSubStringcharsmax(szSubString))
                
replace(szNewMessagecharsmax(szNewMessage), SYM_SUBSTRINGszSubString)
            }
        }
        
        
replace_all(szNewMessagecharsmax(szNewMessage), SYM_SUBSTRING"")

        ... 
send message 
Thanks for pointing me in the right direction.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-02-2017 , 09:51   Re: Replacing a SayText message with arguments
Reply With Quote #8

You can progresively add them to the message. Something like:
PHP Code:
const baseArguments 2

new argsNum get_msg_args()
if(
argsNum baseArguments)
{
    new 
subStringsNum argsNum baseArguments
    
for(new baseArguments 1<= subStringsNumi++)
    {
        
get_msg_arg_string(isubStringcharsmax(subString))
    }

And replace each %s with the subString value.
__________________

Last edited by HamletEagle; 02-02-2017 at 09:52.
HamletEagle is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-02-2017 , 10:20   Re: Replacing a SayText message with arguments
Reply With Quote #9

1 minute too late. Thanks anyways.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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:03.


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