Color embedding(function)
#1

Код:
stock GetColorFromText(color[])
{
	new rcolor;
	switch(color[])
	{
	    case "red": rcolor = "FF0000";
	    case "orange": rcolor = "FF6A00";
	    case "yellow": rcolor = "FFFF00";
	    case "green": rcolor = "15FF00";
	    case "blue": rcolor = "0000FF";
	    case "violet": rcolor = "FF00C3";
	    case "maroon": rcolor = "8C0303";
	    case "white": rcolor = "FFFFFF";
	    case "gray": rcolor = "8C8C8C";
	}
	return rcolor;
}
I do not know how to embed properly by just using that, example:
"I need the text to be like this."
So it would be like:
"*FF00C3*I need the text*FF0000* to be like this."
Now how do I do it with my current function?
Will it be something like this? But it doesnt work
""GetColorFromText("violet")"I need the text"GetColorFromText("red")"to be like this."
Reply
#2

pawn Код:
new string[128];

format(string, sizeof(string), "{%s}I need the text {%s}to be like this.", GetColorFromText(violet), GetColorFromText(red));
SendClientMessage(playerid, -1, string);
Didn't test it, don't even know if this would work but there you go.
Reply
#3

You could just use #define.
pawn Код:
#define red "{FF0000}"
SendClientMessage(playerid, -1, "This is white - "red"This is red");
Reply
#4

Quote:
Originally Posted by Jimmy0wns
Посмотреть сообщение
pawn Код:
new string[128];

format(string, sizeof(string), "{%s}I need the text {%s}to be like this.", GetColorFromText(violet), GetColorFromText(red));
SendClientMessage(playerid, -1, string);
Didn't test it, don't even know if this would work but there you go.
Thanks for that. I'll try it
UD:Errors given me below
Код:
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(106) : error 029: invalid expression, assumed zero
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(108) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(108) : error 006: must be assigned to an array
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(109) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(109) : error 006: must be assigned to an array
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(110) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(110) : error 006: must be assigned to an array
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(111) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(111) : error 006: must be assigned to an array
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(112) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(112) : error 006: must be assigned to an array
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(113) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(113) : error 006: must be assigned to an array
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(114) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(114) : error 006: must be assigned to an array
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(115) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(115) : error 006: must be assigned to an array
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(116) : error 001: expected token: "-string end-", but found "-identifier-"
C:\Users\Acer\Desktop\Programming\Languages\PAWN\SAMP Server\gamemodes\blitzkriegOfFaction.pwn(116) : error 006: must be assigned to an array
Quote:
Originally Posted by CalvinC
Посмотреть сообщение
You could just use #define.
pawn Код:
#define red "{FF0000}"
SendClientMessage(playerid, -1, "This is white - "red"This is red");
I will store a color in my string variable and try to call it with "GetColorFromText()" and that is the problem I am facing.
Reply
#5

AFAIK You cannot switch on a string in pawn, switch may only be used with integers.
You could do something like this: http://forum.sa-mp.com/showthread.ph...ighlight=yhash.
Other than that you have to use strcmp to compare to strings together.

Correct me if im wrong.
Reply
#6

Quote:

Not Found

The requested URL /showthread.ph...ighlight=yhash was not found on this server.

Could you please show me a bit more of the link? It's split.

UD:I found the way, and as you said(^), I can't compare strings in a switch().
Код:
stock GetColorFromText(color)
{
	new rcolor[128];
	switch(color)
	{
	    case 1: rcolor = "FF0000";
	    case 2: rcolor = "FF6A00";
	    case 3: rcolor = "FFFF00";
	    case 4: rcolor = "15FF00";
	    case 5: rcolor = "0000FF";
	    case 6: rcolor = "FF00C3";
	    case 7: rcolor = "8C0303";
	    case 8: rcolor = "FFFFFF";
	    case 9: rcolor = "8C8C8C";
	}
	return rcolor;
}
It works when you combine Jimmy's.
Reply
#7

Just came out with this, you only need to edit the array data and insert the color name.

Код:
enum rcolors
{
	rColName[10],
	rColHex[7]
}

static const rColors[][rcolors] = 
{
	{"none", "FFFFFF"},
	{"red", "FF0000"},
	{"green", "00FF00"},
	{"blue", "0000FF"},
	{"black", "000000"}
};


stock GetColorFromText(color[])
{
	new 
		colid = 0
	;

	for (new J = sizeof (rColors), i = 1; i != J; i++)
	{
		if (!strcmp(rColors[i][rColName], color, true))
		{
			colid = i;
			break;
		}
	}

	return rColors[colid][rColHex];
}


//
	format(string, sizeof(string), "{%s}I need the text {%s}to be like this.", GetColorFromText("red"), GetColorFromText("blue"));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)