Raised This Month: $ Target: $400
 0% 

Formatting Strings


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Infest
Member
Join Date: Mar 2005
Old 11-08-2016 , 04:07   Re: Formatting Strings
Reply With Quote #3

Quote:
Originally Posted by PartialCloning View Post
How can I pre-format a string like:

HTML Code:
new Format[][]{
"Your steamID is: %s.",
"Your code is: %d.",
"You won 20 tickets for completing the %s task and killing %d players"
};

public TaskHunter(ID, Request)
{
    client_print(ID, print_chat, "%s", Format[2], "Hunter", g_MyKill[ID]);
}
Like a language file but embedded within the plugin?
I would recommend against that, and instead get those values on the fly.

E.g.

PHP Code:
enum
{
    
REQUEST_STEAM,
    
REQUEST_CODE,
    
REQUEST_TICKET_WIN
}

new 
g_iCode[MAX_PLAYERS]
new 
g_iKillCount[MAX_PLAYERS]
new const 
g_szTask[] = "human killer"

public printPlayerMessage(idiRequest)
{
    switch(
iRequest)
    {
        case 
REQUEST_STEAM:
        {
            static 
szSteamId[32]
            
get_user_authid(idszSteamIdcharsmax(szSteamId))
            
client_print(idprint_chat"Your Steam ID is: %s"szSteamId)
        }
        case 
REQUEST_CODE:
        {
            
client_print(idprint_chat"Your code is: %i"g_iCode[id])
        }
        case 
REQUEST_TICKET_WIN:
        {
            
// TODO: 20 tickets should not be hard coded
            
client_print(idprint_chat"You have won 20 tickets for completing task %s and killing %i players"g_szTaskg_iKillCount)
        }
        default:
        {
            
log_amx("printPlayerMessage: Request out of range [%i]"iRequest)
        }
    }

But if you must:

Otherwise you will need to maintain an array of players that contain that information. You could do a 3d string array, e.g. new sGameMessages[MAX_PLAYERS][][] - It should work, but I would not recommend this and instead opt for a dynamic array:

A better way would be to maintain a dynamic array of messages for players; Read about this here: https://forums.alliedmods.net/showthread.php?t=249602 (Check out Hamlets code example that uses enum _: eData)

Last edited by Infest; 11-08-2016 at 04:10.
Infest is offline
 



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 01:59.


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