[Include] Carbonite's Useful Function [SendMessage]
#1

Hello SA-MP community!

I have been webcoding and I found this community through a friend of mine. I want to make my own popular server for people to play on someday and for now I just want to learn the Pawn scripting so I could become more experienced before I open a whole community to this community. To do this I've been going through SA-MP wiki and started my own gamemode which is being tested by me and me only.

SendMessage(playerid, Sscanf[], {Float,_}:...);
Код:
stock SendMessage(PlayerID, Sscanf[], {Float,_}:...) {
	if(!IsPlayerConnected(PlayerID)) return false;

	new
		String[500];
	for(new SscanfString = 0; SscanfString < (numargs() - 1); SscanfString++) {
		switch(Sscanf[SscanfString]) {
			case 's': {
				new
					Result[100];

				for(new ResultString = 0; getarg((SscanfString + 2), ResultString) != 0; ResultString++) {
					Result[ResultString] = getarg((SscanfString + 2), ResultString);
				}

				if(!strlen(String)) {
					format(String, 500, "%s", Result);
				} else format(String, 500, "%s%s", String, Result);
			}
			case 'd', 'i': {
				new
					Result = getarg(SscanfString + 2);

				if(!strlen(String)) {
					format(String, 500, "%d", Result);
				} else format(String, 500, "%s%d", String, Result);
			}
			case 'f': {
				new
					Float: Result = Float: getarg(SscanfString + 2);

				if(!strlen(String)) {
					format(String, 500, "%f", Result);
				} else format(String, 500, "%s%f", String, Result);
			}
			case 'c': {
				new
					Result[100];

				for(new ResultString = 0; getarg((SscanfString + 2), ResultString) != 0; ResultString++) {
					Result[ResultString] = getarg((SscanfString + 2), ResultString);
				}

				new
				    NumberOfColors = 10,
				    Colors[][][] = {
				    	{ "Black", "{000000}" },
				    	{ "Grey", "{C0C0C0}" },
				    	{ "White", "{FFFFFF}" },
				    	{ "Red", "{FF0000}" },
				    	{ "Orange", "{FF8000}" },
				    	{ "Yellow", "{FFFF00}" },
				    	{ "Green", "{00FF00}" },
				    	{ "Blue", "{0000FF}" },
				    	{ "Purple", "{800080}" },
				    	{ "Teal", "{008080}" }
				    };

				for(new NumColors = 0; NumColors < NumberOfColors; NumColors++) {
					if(strcmp(Result, Colors[NumColors][0], true) == 0) {
						if(!strlen(String)) {
							format(String, 500, "%s", Colors[NumColors][1]);
						} else format(String, 500, "%s%s", String, Colors[NumColors][1]);
					}
				}
			}
		}
	}

	SendClientMessage(PlayerID, -1, String);
	return true;
}
The code is above, installation is simple... Copy, Paste, and Compile.

An example usage of this code is...
Код:
SendMessage(playerid, "cscs", "Teal", "Carbonite's ", "Red", "SendMessage function.");
Which in the chat box will display...
Carbonite's SendMessage function.

This was tested and works 100%!

How to add more color options?
See...
Код:
new
    NumberOfColors = 10,
    Colors[][][] = {
   	{ "Black", "{000000}" },
    	{ "Grey", "{C0C0C0}" },
    	{ "White", "{FFFFFF}" },
    	{ "Red", "{FF0000}" },
    	{ "Orange", "{FF8000}" },
    	{ "Yellow", "{FFFF00}" },
    	{ "Green", "{00FF00}" },
    	{ "Blue", "{0000FF}" },
    	{ "Purple", "{800080}" },
    	{ "Teal", "{008080}" }
    };
Just change NumberOfColors = 10 to NumberOfColors = 11

Then add...
Код:
,
{ "Color", "{RRGGBB}" }
... after ...
Код:
{ "Teal", "{008080}" }
Example...
Код:
new
    NumberOfColors = 11,
    Colors[][][] = {
   	{ "Black", "{000000}" },
    	{ "Grey", "{C0C0C0}" },
    	{ "White", "{FFFFFF}" },
    	{ "Red", "{FF0000}" },
    	{ "Orange", "{FF8000}" },
    	{ "Yellow", "{FFFF00}" },
    	{ "Green", "{00FF00}" },
    	{ "Blue", "{0000FF}" },
    	{ "Purple", "{800080}" },
    	{ "Teal", "{008080}" },
    	{ "Brown", "{732F02}" }
    };
Tell me how I'm doing so far...
Comment and Rate please.
Make suggestions.
Be kind and courteous.
Thank you for your time.
Reply
#2

Wow! Nice! Keep up the cool snippets

PS: I thought an include was a file in a .inc, Not a snippet. :P
Reply
#3

Oh I thought an include was something you included into your gamemodes/filterscripts.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)