Almacenar color hex en variable
#1

Buenas, vengo a pedir una mano ya que necesito almacenar un color hex en una variable, y no sй como hacerlo, a lo que me refiero es que no sй en que tipo de variable habrнa que almacenarlo, si alguien podrнa ayudarme, estarнa muy agradecido, desde ya muchas gracias.
Reply
#2

un color hex lo puedes guardar y cargar como un int

Код:
new colorojo;
colorojo = 0xFF0000FF;

para mostarlo en un mensaje
new string[50];
format(string, sizeof(string), "El color rojo es {%06x}este", colorojo >>> 8);
SendClientMessageToAll(-1, string);

para cargarlo por ejemplo:
SetPlayerColor(playerid, colorrojo);
Reply
#3

Como un integer o un string, no importa.

pawn Код:
// ** INCLUDES

#include <a_samp>
#include <sscanf>

// ** DEFINES

// *** GENERAL

#define HEX_VALUE "0xFFFFFFFF"
#define INTEGER_VALUE -1

// *** FUNCTIONS

#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)

// ** MAIN

main()
{
    print("Loaded \"color_hex_int.amx\"");

    printf(""#HEX_VALUE" to integer: %i", HexToInt(HEX_VALUE));
    printf(""#INTEGER_VALUE" to hexadecimal: %s", IntToHex(INTEGER_VALUE));

    new string[11], answer[12];
    strcpy(string, HEX_VALUE, 11);
    answer = (IsHexOrInt(string)) ? ("Hexadecimal") : ("Integer");
    printf("Is %s an integer or a hexadecimal value? %s", string, answer);

    format(string, sizeof(string), "%d", INTEGER_VALUE);
    answer = (IsHexOrInt(string)) ? ("Hexadecimal") : ("Integer");
    printf("Is %s an integer or a hexadecimal value? %s", string, answer);
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// ** FUNCTIONS

stock HexToInt(hex[])
{
    new int;
    sscanf(hex, "x", int);
    return int;
}

stock IntToHex(int)
{
    new string[7];
    format(string, sizeof(string), "%06x", int >>> 8);
    return string;
}

stock IsNumeric(const string[])
{
    return !sscanf(string, "{d}");
}

stock IsHexOrInt(hex[])
{
    if(IsNumeric(hex)) return false;
    return true;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)