Raised This Month: $ Target: $400
 0% 

Color stock


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Vechta
Veteran Member
Join Date: Jun 2010
Old 08-22-2010 , 10:21   Color stock
Reply With Quote #1

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!")
Vechta is offline
naven
Veteran Member
Join Date: Jun 2008
Location: Poland, Cieszyn
Old 08-22-2010 , 13:18   Re: Color stock
Reply With Quote #2

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!"
__________________
naven.com.pl
"At the end of the day, there are always going to be mental disorders and people who cause violence for no other reason than the fact that they're fucked up and lost. And all we can do is try to learn from it." Corey Taylor.
naven is offline
Vechta
Veteran Member
Join Date: Jun 2010
Old 08-22-2010 , 13:42   Re: Color stock
Reply With Quote #3

Quote:
Originally Posted by N A V E N View Post
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 ?
Vechta is offline
naven
Veteran Member
Join Date: Jun 2008
Location: Poland, Cieszyn
Old 08-22-2010 , 16:47   Re: Color stock
Reply With Quote #4

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?
__________________
naven.com.pl
"At the end of the day, there are always going to be mental disorders and people who cause violence for no other reason than the fact that they're fucked up and lost. And all we can do is try to learn from it." Corey Taylor.
naven is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 08-22-2010 , 16:54   Re: Color stock
Reply With Quote #5

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
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.

Last edited by ot_207; 08-22-2010 at 16:56.
ot_207 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-23-2010 , 04:40   Re: Color stock
Reply With Quote #6

You can pass ^1 ^3 and ^4 without any problem though.
Use !g in files such as language files.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Vechta
Veteran Member
Join Date: Jun 2010
Old 08-23-2010 , 12:55   Re: Color stock
Reply With Quote #7

Quote:
Originally Posted by ot_207 View Post
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

But thanks ^^
Vechta is offline
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 22:01.


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