How do I combine this?
#1

So, I have this command "/c" which sends a message to your clan's chat.
This is the command.
Код:
CMD:c(playerid, params[]) {
	if(playerVariables[playerid][pClan] < 1)
		return SendClientMessage(playerid, COLOR_GREY, "Your clan data is invalid.");

	if(isnull(params))
		return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/c [message]");

 	GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);

	switch(playerVariables[playerid][pClanRank])
	{
		case 1:	format(szMessage, sizeof(szMessage), "{%s}[CLAN] %s %s: %s",clanVariables[playerVariables[playerid][pClan]][cClanColor], clanVariables[playerVariables[playerid][pClan]][cClanRankName1], szPlayerName, params);
		case 2:	format(szMessage, sizeof(szMessage), "{%s}[CLAN] %s %s: %s",clanVariables[playerVariables[playerid][pClan]][cClanColor], clanVariables[playerVariables[playerid][pClan]][cClanRankName2], szPlayerName, params);
		case 3:	format(szMessage, sizeof(szMessage), "{%s}[CLAN] %s %s: %s",clanVariables[playerVariables[playerid][pClan]][cClanColor], clanVariables[playerVariables[playerid][pClan]][cClanRankName3], szPlayerName, params);
		case 4:	format(szMessage, sizeof(szMessage), "{%s}[CLAN] %s %s: %s",clanVariables[playerVariables[playerid][pClan]][cClanColor], clanVariables[playerVariables[playerid][pClan]][cClanRankName4], szPlayerName, params);
		case 5:	format(szMessage, sizeof(szMessage), "{%s}[CLAN] %s %s: %s",clanVariables[playerVariables[playerid][pClan]][cClanColor], clanVariables[playerVariables[playerid][pClan]][cClanRankName5], szPlayerName, params);
		case 6:	format(szMessage, sizeof(szMessage), "{%s}[CLAN] %s %s: %s",clanVariables[playerVariables[playerid][pClan]][cClanColor], clanVariables[playerVariables[playerid][pClan]][cClanRankName6], szPlayerName, params);
		case 7:	format(szMessage, sizeof(szMessage), "{%s}[CLAN] %s %s: %s",clanVariables[playerVariables[playerid][pClan]][cClanColor], clanVariables[playerVariables[playerid][pClan]][cClanRankName7], szPlayerName, params);
		default: format(szMessage, sizeof(szMessage), "{%s}[CLAN] %s %s: %s",clanVariables[playerVariables[playerid][pClan]][cClanColor], clanVariables[playerVariables[playerid][pClan]][cClanRankName1], szPlayerName, params);
	}
    SendToClan(playerVariables[playerid][pClan], COLOR_WHITE, szMessage);
	return 1;
}
Код:
SendToClan(playerVariables[playerid][pClan], clanVariables[playerVariables[playerid][pClan]][cClanColor], szMessage);
This is the stock that sends the message to the group.

clanVariables[playerVariables[playerid][pClan]][cClanColor] is not a "0xFFAAAAAA" format, but its rather a "AAAAAA" format. As you know, the SendToClan stock does not work with that color code. My question here is, how can I add "0x" to clanVariables[playerVariables[playerid][pClan]][cClanColor] so it turns into 0x"clanVariables[playerVariables[playerid][pClan]][cClanColor]"
Reply
#2

Don't. Just save the color as an integer, as that's what they are after all. You can do this with sscanf.
pawn Код:
sscanf(color_hex, "x", color_int);
Reply
#3

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Don't. Just save the color as an integer, as that's what they are after all. You can do this with sscanf.
pawn Код:
sscanf(color_hex, "x", color_int);
I'm sorry, but I don't understand what you mean by this.
Reply
#4

Use format.
Example:
PHP код:
new color[24];
format(color,24"0x%s",clanVariables[playerVariables[playerid][pClan]][cClanColor]); 
And after use variable 'color' instead of clanVariables[playerVariables[playerid][pClan]][cClanColor] when you send a message.
Reply
#5

Quote:
Originally Posted by AdrianG
Посмотреть сообщение
Use format.
Example:
PHP код:
new color[24];
format(color,24"0x%s",clanVariables[playerVariables[playerid][pClan]][cClanColor]); 
And after use variable 'color' instead of clanVariables[playerVariables[playerid][pClan]][cClanColor] when you send a message.
That wouldn't work. error 035: argument type mismatch (argument 2)
Reply
#6

What don't you understand? Colors are integers, not strings. You can use the sscanf plugin to convert a hexadecimal color to an integer. And use that integer instead of that string.

You can download sscanf at https://sampforum.blast.hk/showthread.php?tid=570927.

To convert a color into a string, do:
pawn Код:
new color_hex[11] = "0xFFFFFFFF", color_int;
sscanf(color_hex, "x", color_int);
The integer gets saved in "color_int". Its value, in this case, would be "-1".
Reply
#7

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
What don't you understand? Colors are integers, not strings. You can use the sscanf plugin to convert a hexadecimal color to an integer. And use that integer instead of that string.

You can download sscanf at https://sampforum.blast.hk/showthread.php?tid=570927.

To convert a color into a string, do:
pawn Код:
new color_hex[11] = "0xFFFFFFFF", color_int;
sscanf(color_hex, "x", color_int);
The integer gets saved in "color_int". Its value, in this case, would be "-1".
But my color is not a HEX number. Its in this form, "XXXXXX" so "FFFFFF". Would that work the same?
Reply
#8

Quote:
Originally Posted by danielpalade
Посмотреть сообщение
But my color is not a HEX number. Its in this form, "XXXXXX" so "FFFFFF". Would that work the same?
Colors AREN'T hexs, they are integers when the script is compiled. Just convert the hexadecimal value with the following function if you're having this much trouble, then:
pawn Код:
stock HexToInt(hex[])
{
    new int;
    sscanf(hex, "x", int);
    return int;
}
pawn Код:
SendToClan(playerVariables[playerid][pClan], HexToInt(clanVariables[playerVariables[playerid][pClan]][cClanColor]), szMessage);
Just remove "{%s}" and "clanVariables[playerVariables[playerid][pClan]][cClanColor]" from the formats.
Reply
#9

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Colors AREN'T hexs, they are integers when the script is compiled. Just convert the hexadecimal value with the following function if you're having this much trouble, then:
pawn Код:
stock HexToInt(hex[])
{
    new int;
    sscanf(hex, "x", int);
    return int;
}
pawn Код:
SendToClan(playerVariables[playerid][pClan], HexToInt(clanVariables[playerVariables[playerid][pClan]][cClanColor]), szMessage);
Just remove "{%s}" and "clanVariables[playerVariables[playerid][pClan]][cClanColor]" from the formats.
That didn't work. The text is straight black. The color code was D6C692 btw.
Reply
#10

You must add "0x" and the alpha (FF) too.

0xD6C692FF equals to -691629313.

Using the function with "0xD6C692FF":
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)