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

LANG string with variable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Phant
Veteran Member
Join Date: Sep 2009
Location: New Jersey
Old 01-04-2015 , 22:12   LANG string with variable
Reply With Quote #1

Hello. Right now I have this dumb code:
PHP Code:
    switch(i_state)
    {
        case 
0:
        {
            
client_print(idprint_chat"%s%L"PREFIXLANG_SERVER"S_0")
        }
        case 
1:
        {
            
client_print(idprint_chat"%s%L"PREFIXLANG_SERVER"S_1")
        }
        case 
2:
        {
            
client_print(idprint_chat"%s%L"PREFIXLANG_SERVER"S_2")
        }
        case 
3:
        {
            
client_print(idprint_chat"%s%L"PREFIXLANG_SERVER"S_3")
        }
        case 
4:
        {
            
client_print(idprint_chat"%s%L"PREFIXLANG_SERVER"S_4")
        }
        case 
5:
        {
            
client_print(idprint_chat"%s%L"PREFIXLANG_SERVER"S_5")
        }
    } 
How I can simplify it? I try:
PHP Code:
    new state_str[32]
    
num_to_str(i_statestate_strcharsmax(state_str))
    
client_print(idprint_chat"%s%L"PREFIXLANG_SERVER"S_%s"state_str
But I got:

(ofcousre "S_0" exist in language file of plugin)

Last edited by Phant; 01-04-2015 at 22:13.
Phant is offline
Send a message via ICQ to Phant
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-04-2015 , 22:17   Re: LANG string with variable
Reply With Quote #2

You can't format twice in a single statement. You would need to format the "S_#" string first (in a new variable) then use the resultant string (the variable) in the client_print() function.

PHP Code:
new szState[6]
formatex(szStatecharsmax(szState), "S_%d"iState)
client_print(idprint_chat"%L"LANG_SERVERszState
__________________

Last edited by fysiks; 01-04-2015 at 22:19.
fysiks is offline
Phant
Veteran Member
Join Date: Sep 2009
Location: New Jersey
Old 02-06-2015 , 10:54   Re: LANG string with variable
Reply With Quote #3

Thanks. One more question:
How to "add" string from Lang-file?

I'm trying:
Quote:
add(szMsg, charsmax(szMsg), LANG_SERVER, "S_LAST")
add(szMsg, charsmax(szMsg), "%L", LANG_SERVER, "S_LAST")
But it's not correct .
Phant is offline
Send a message via ICQ to Phant
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-06-2015 , 11:12   Re: LANG string with variable
Reply With Quote #4

Use format or formatex to ... format a string.
__________________
Arkshine is offline
Phant
Veteran Member
Join Date: Sep 2009
Location: New Jersey
Old 02-06-2015 , 11:39   Re: LANG string with variable
Reply With Quote #5

Quote:
Originally Posted by Arkshine View Post
Use format or formatex to ... format a string.
I use it and want add text at end after all:
PHP Code:
    new szMsg[192]
    if(
i_state 7)
    {
        
formatex(szMsgcharsmax(szMsg), "%s%L (T %i:%i (%i:%i) CT)."PREFIXLANG_SERVERszMsgStateg_cw_rounds_alphag_cw_rounds_bravog_cw_ov_rounds_alphag_cw_ov_rounds_bravo)
    } else if(
i_state 3) {
        
formatex(szMsgcharsmax(szMsg), "%s%L (T %i:%i CT)."PREFIXLANG_SERVERszMsgStateg_cw_rounds_alphag_cw_rounds_bravo)
    } else {
        
formatex(szMsgcharsmax(szMsg), "%s%L."PREFIXLANG_SERVERszMsgState)
    }
    
    if(
last_round)
    {
        
// HOW?
        //add(szMsg, charsmax(szMsg), "%L", LANG_SERVER, "S_LAST")
    

I do not want to do like that (add more if/else's):
PHP Code:
    new szMsg[192]
    if(
i_state 7)
    {
        if(
last_round)
        {
            
formatex(szMsgcharsmax(szMsg), "%s%L (T %i:%i (%i:%i) CT). %L"PREFIXLANG_SERVERszMsgStateg_cw_rounds_alphag_cw_rounds_bravog_cw_ov_rounds_alphag_cw_ov_rounds_bravoLANG_SERVER"S_LAST")
        } else {
            
formatex(szMsgcharsmax(szMsg), "%s%L (T %i:%i (%i:%i) CT)."PREFIXLANG_SERVERszMsgStateg_cw_rounds_alphag_cw_rounds_bravog_cw_ov_rounds_alphag_cw_ov_rounds_bravo)
        }
    } else if(
i_state 3) {
        if(
last_round)
        {
            
formatex(szMsgcharsmax(szMsg), "%s%L (T %i:%i CT). %L"PREFIXLANG_SERVERszMsgStateg_cw_rounds_alphag_cw_rounds_bravoLANG_SERVER"S_LAST")
        } else {
            
formatex(szMsgcharsmax(szMsg), "%s%L (T %i:%i CT)."PREFIXLANG_SERVERszMsgStateg_cw_rounds_alphag_cw_rounds_bravo)
        }
    } else {
        if(
last_round)
        {
            
formatex(szMsgcharsmax(szMsg), "%s%L. %L"PREFIXLANG_SERVERszMsgStateLANG_SERVER"S_LAST")
        } else {
            
formatex(szMsgcharsmax(szMsg), "%s%L."PREFIXLANG_SERVERszMsgState)
        }
    } 

Last edited by Phant; 02-06-2015 at 11:40.
Phant is offline
Send a message via ICQ to Phant
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 10:42.


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