Raised This Month: $ Target: $400
 0% 

Color stock


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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