AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Color stock (https://forums.alliedmods.net/showthread.php?t=136053)

Vechta 08-22-2010 10:21

Color stock
 
Why this stock sometimes print the code wrong?

Code:
Code:

stock bb_colored_print(target, const message[], any:...)
{
        static buffer[512], i, argscount
        argscount = numargs()
       
        static g_msgSayText_cp, g_MaxPlayers_cp;
        if(!g_msgSayText_cp) {
                g_msgSayText_cp = get_user_msgid("SayText");
        }
        if(!g_MaxPlayers_cp) {
                g_MaxPlayers_cp = get_maxplayers();
        }
       
        // Send to everyone
        if (!target)
        {
                static player
                for (player = 1; player <= g_MaxPlayers_cp; player++)
                {
                        // Not connected
                        if (!is_user_connected(player))
                                continue;
                       
                        // Remember changed arguments
                        static changed[5], changedcount // [5] = max LANG_PLAYER occurencies
                        changedcount = 0
                       
                        // Replace LANG_PLAYER with player id
                        for (i = 2; i < argscount; i++)
                        {
                                if (getarg(i) == LANG_PLAYER)
                                {
                                        setarg(i, 0, player)
                                        changed[changedcount] = i
                                        changedcount++
                                }
                        }
                       
                        // Format message for player
                        vformat(buffer, charsmax(buffer), message, 3)
                       
                        replace_all(buffer, charsmax(buffer), "!g", "^4");
                        replace_all(buffer, charsmax(buffer), "!y", "^1");
                        replace_all(buffer, charsmax(buffer), "!t", "^3");
                       
                        // Send it
                        message_begin(MSG_ONE_UNRELIABLE, g_msgSayText_cp, _, player)
                        write_byte(player)
                        write_string(buffer)
                        message_end()
                       
                        // Replace back player id's with LANG_PLAYER
                        for (i = 0; i < changedcount; i++)
                                setarg(changed[i], 0, LANG_PLAYER)
                }
        }
        // Send to specific target
        else
        {
                // Format message for player
                vformat(buffer, charsmax(buffer), message, 3)
               
                replace_all(buffer, charsmax(buffer), "!g", "^4");
                replace_all(buffer, charsmax(buffer), "!y", "^1");
                replace_all(buffer, charsmax(buffer), "!t", "^3");
               
                // Send it
                message_begin(MSG_ONE, g_msgSayText_cp, _, target)
                write_byte(target)
                write_string(buffer)
                message_end()
        }
}

Example:
PHP Code:

bb_colored_print(id"^x04[Test] ^x03You have now ^x04%i ^x03Points!"

In game it prints something like this:
Code:

est ou have now  Points!")

naven 08-22-2010 13:18

Re: Color stock
 
It's not wrong
Take a look at this:
PHP Code:

bb_colored_print(id"^x04[Test] ^x03You have now ^x04%i ^x03Points!"

PHP Code:

bb_colored_print(id"^x04[Test](space)^x03You(space)have(space)now(space)^x04%i(space)^x03Points!"


Vechta 08-22-2010 13:42

Re: Color stock
 
Quote:

Originally Posted by N A V E N (Post 1278889)
It's not wrong
Take a look at this:
PHP Code:

bb_colored_print(id"^x04[Test] ^x03You have now ^x04%i ^x03Points!"

PHP Code:

bb_colored_print(id"^x04[Test](space)^x03You(space)have(space)now(space)^x04%i(space)^x03Points!"


But why it print wrong O.o ?

naven 08-22-2010 16:47

Re: Color stock
 
It doesn't print wrong man.
Correct:
PHP Code:

bb_colored_print(id"^x04[Test] ^x03You have now^x04%i^x03Points!"

Can you see the difference now?

ot_207 08-22-2010 16:54

Re: Color stock
 
Also because of this: "%i" you should add an integer for format.

Edit: OOps.
The stock must be used this way!!!
PHP Code:

bb_colored_print(id"!g[Test] !tYou have now !g %i !tPoints!"50


ConnorMcLeod 08-23-2010 04:40

Re: Color stock
 
You can pass ^1 ^3 and ^4 without any problem though.
Use !g in files such as language files.

Vechta 08-23-2010 12:55

Re: Color stock
 
Quote:

Originally Posted by ot_207 (Post 1279094)
Also because of this: "%i" you should add an integer for format.

Edit: OOps.
The stock must be used this way!!!
PHP Code:

bb_colored_print(id"!g[Test] !tYou have now !g %i !tPoints!"50


Ye, was my mistake saw it yester evening too :D

But thanks ^^


All times are GMT -4. The time now is 22:01.

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