How to make random spawn colors?
#1

Hi, i want my own PlayerColors if someone spawn, but it must be random. I've got now this script, but i think it's not working very well. Zometimes i get the color purple, mostly if a am ID 1, instead of 0. And purple isn't included by this random.

So how can i make an better script?

My script:
pawn Код:
enum playercolor
{
    color_id,
};

new PlayerColor[][playercolor] =
{
    {0xE60000FF}, //Red
    {0x1229FAFF}, //Blue
    {0x21DD00FF}, //Green
    {0xFFFF00FF}, //Yellow
    {0xF97804FF}, //Orange
    {0x00C2ECFF}, //Light Blue
    {0x38FF06FF}, //Light Green
    {0x008040FF}, //Dark Green
    {0xFF8080FF} //Light Red
};

public OnPlayerConnect(playerid)
{
    new randomcolor = random(sizeof(PlayerColor));
    SetPlayerColor(playerid, PlayerColor[randomcolor][color_id]);
    return 1;
}
Reply
#2

You don't have to use enum for just 1 enum, try this:

pawn Код:
new PlayerColor[9] = {
0xE60000FF, //Red
0x1229FAFF, //Blue
0x21DD00FF, //Green
0xFFFF00FF, //Yellow
0xF97804FF, //Orange
0x00C2ECFF, //Light Blue
0x38FF06FF, //Light Green
0x008040FF, //Dark Green
0xFF8080FF //Light Red
};

public OnPlayerConnect(playerid)
{
    new randomcolor = random(sizeof(PlayerColor));
    SetPlayerColor(playerid, PlayerColor[randomcolor]);
    return 1;
}
Reply
#3

Quote:
Originally Posted by Andom
You don't have to use enum for just 1 enum, try this:

pawn Код:
new PlayerColor[9] = {
0xE60000FF, //Red
0x1229FAFF, //Blue
0x21DD00FF, //Green
0xFFFF00FF, //Yellow
0xF97804FF, //Orange
0x00C2ECFF, //Light Blue
0x38FF06FF, //Light Green
0x008040FF, //Dark Green
0xFF8080FF //Light Red
};

public OnPlayerConnect(playerid)
{
    new randomcolor = random(sizeof(PlayerColor));
    SetPlayerColor(playerid, PlayerColor[randomcolor]);
    return 1;
}
That script don't works also very well.
With that script, ID 0 is always orange, and that is the normal SA:MP method...
Reply
#4

*bump*

Ok, it's now a lot more working. But now i got another problem. Everyone gets the same color if playerid 0 has spawned...

pawn Код:
new bool:Spawned[MAX_PLAYERS];

new PlayerColor[9] = {
0xE60000FF, //Red
0x1229FAFF, //Blue
0xFFFF00FF, //Yellow
0xF97804FF, //Orange
0x00C2ECFF, //Light Blue
0x38FF06FF, //Light Green
0x008040FF, //Dark Green
0xFF8080FF //Light Red
};

public OnPlayerConnect(playerid)
{
Spawned[playerid] = false;
return 1;
}

public OnPlayerSpawn(playerid)
{
new randomcolor = random(sizeof(PlayerColor));
if(Spawned[playerid] == false)
{
SetPlayerColor(playerid, PlayerColor[randomcolor]);
Spawned[playerid] = true;
}
return 1;
}
Reply
#5

*bump2*

And another bug: Someone can get the color Black, but that is'nt defined

Someone who can help me?
Reply
#6

For real random color: random(0xFFFFFFFF)
Reply
#7

Quote:
Originally Posted by 0rb
For real random color: random(0xFFFFFFFF)
o.0 Do you think that that makes my problem better? NO. In that random are much more dark colors. And some invisible icons you can get. I don't want that, because THAT is my problem.

Maybe you know something else?
Reply
#8

Код:
Use this

Код:
//============================================================================== Random Colour When Spawn
new playerColors[100] = {
0xFF8C13FF,0xC715FFFF,0x20B2AAFF,0xDC143CFF,0x6495EDFF,0xf0e68cFF,0x778899FF,0xFF1493FF,0xF4A460FF,0xEE82EEFF,0xFFD720FF,
0x8b4513FF,0x4949A0FF,0x148b8bFF,0x14ff7fFF,0x556b2fFF,0x0FD9FAFF,0x10DC29FF,0x534081FF,0x0495CDFF,0xEF6CE8FF,0xBD34DAFF,
0x247C1BFF,0x0C8E5DFF,0x635B03FF,0xCB7ED3FF,0x65ADEBFF,0x5C1ACCFF,0xF2F853FF,0x11F891FF,0x7B39AAFF,0x53EB10FF,0x54137DFF,
0x275222FF,0xF09F5BFF,0x3D0A4FFF,0x22F767FF,0xD63034FF,0x9A6980FF,0xDFB935FF,0x3793FAFF,0x90239DFF,0xE9AB2FFF,0xAF2FF3FF,
0x057F94FF,0xB98519FF,0x388EEAFF,0x028151FF,0xA55043FF,0x0DE018FF,0x93AB1CFF,0x95BAF0FF,0x369976FF,0x18F71FFF,0x4B8987FF,
0x491B9EFF,0x829DC7FF,0xBCE635FF,0xCEA6DFFF,0x20D4ADFF,0x2D74FDFF,0x3C1C0DFF,0x12D6D4FF,0x2A51E2FF,0xE3AC12FF,
0xFC42A8FF,0x2FC827FF,0x1A30BFFF,0xB740C2FF,0x42ACF5FF,0x2FD9DEFF,0xFAFB71FF,0x05D1CDFF,0xC471BDFF,0x94436EFF,0xC1F7ECFF,
0xCE79EEFF,0xBD1EF2FF,0x93B7E4FF,0x3214AAFF,0x184D3BFF,0xAE4B99FF,0x7E49D7FF,0x4C436EFF,0xFA24CCFF,0xCE76BEFF,0xA04E0AFF,
0x9F945CFF,0xDCDE3DFF,0x10C9C5FF,0x70524DFF,0x0BE472FF,0x8A2CD7FF,0x6152C2FF,0xCF72A9FF,0xE59338FF,0xEEDC2DFF,0xD8C762FF,
0x3FE65CFF
};
//==============================================================================


OnPlayerConnect

//============================================================================== RANDOM COLOUR WHEN CONNECT
new rand = random(sizeof(playerColors));
SetPlayerColor(playerid, playerColors[rand]);
works for me ;P
Reply
#9

Quote:
Originally Posted by aspire5630
Код:
Use this

Код:
//============================================================================== Random Colour When Spawn
new playerColors[100] = {
0xFF8C13FF,0xC715FFFF,0x20B2AAFF,0xDC143CFF,0x6495EDFF,0xf0e68cFF,0x778899FF,0xFF1493FF,0xF4A460FF,0xEE82EEFF,0xFFD720FF,
0x8b4513FF,0x4949A0FF,0x148b8bFF,0x14ff7fFF,0x556b2fFF,0x0FD9FAFF,0x10DC29FF,0x534081FF,0x0495CDFF,0xEF6CE8FF,0xBD34DAFF,
0x247C1BFF,0x0C8E5DFF,0x635B03FF,0xCB7ED3FF,0x65ADEBFF,0x5C1ACCFF,0xF2F853FF,0x11F891FF,0x7B39AAFF,0x53EB10FF,0x54137DFF,
0x275222FF,0xF09F5BFF,0x3D0A4FFF,0x22F767FF,0xD63034FF,0x9A6980FF,0xDFB935FF,0x3793FAFF,0x90239DFF,0xE9AB2FFF,0xAF2FF3FF,
0x057F94FF,0xB98519FF,0x388EEAFF,0x028151FF,0xA55043FF,0x0DE018FF,0x93AB1CFF,0x95BAF0FF,0x369976FF,0x18F71FFF,0x4B8987FF,
0x491B9EFF,0x829DC7FF,0xBCE635FF,0xCEA6DFFF,0x20D4ADFF,0x2D74FDFF,0x3C1C0DFF,0x12D6D4FF,0x2A51E2FF,0xE3AC12FF,
0xFC42A8FF,0x2FC827FF,0x1A30BFFF,0xB740C2FF,0x42ACF5FF,0x2FD9DEFF,0xFAFB71FF,0x05D1CDFF,0xC471BDFF,0x94436EFF,0xC1F7ECFF,
0xCE79EEFF,0xBD1EF2FF,0x93B7E4FF,0x3214AAFF,0x184D3BFF,0xAE4B99FF,0x7E49D7FF,0x4C436EFF,0xFA24CCFF,0xCE76BEFF,0xA04E0AFF,
0x9F945CFF,0xDCDE3DFF,0x10C9C5FF,0x70524DFF,0x0BE472FF,0x8A2CD7FF,0x6152C2FF,0xCF72A9FF,0xE59338FF,0xEEDC2DFF,0xD8C762FF,
0x3FE65CFF
};
//==============================================================================


OnPlayerConnect

//============================================================================== RANDOM COLOUR WHEN CONNECT
new rand = random(sizeof(playerColors));
SetPlayerColor(playerid, playerColors[rand]);
works for me ;P
OMGWTF, another code that shall never work better than my script. It's exactly the same, only you have 100 random colors and i have 9.
Reply
#10

Quote:
Originally Posted by Remi-X
Quote:
Originally Posted by aspire5630
Код:
Use this

Код:
//============================================================================== Random Colour When Spawn
new playerColors[100] = {
0xFF8C13FF,0xC715FFFF,0x20B2AAFF,0xDC143CFF,0x6495EDFF,0xf0e68cFF,0x778899FF,0xFF1493FF,0xF4A460FF,0xEE82EEFF,0xFFD720FF,
0x8b4513FF,0x4949A0FF,0x148b8bFF,0x14ff7fFF,0x556b2fFF,0x0FD9FAFF,0x10DC29FF,0x534081FF,0x0495CDFF,0xEF6CE8FF,0xBD34DAFF,
0x247C1BFF,0x0C8E5DFF,0x635B03FF,0xCB7ED3FF,0x65ADEBFF,0x5C1ACCFF,0xF2F853FF,0x11F891FF,0x7B39AAFF,0x53EB10FF,0x54137DFF,
0x275222FF,0xF09F5BFF,0x3D0A4FFF,0x22F767FF,0xD63034FF,0x9A6980FF,0xDFB935FF,0x3793FAFF,0x90239DFF,0xE9AB2FFF,0xAF2FF3FF,
0x057F94FF,0xB98519FF,0x388EEAFF,0x028151FF,0xA55043FF,0x0DE018FF,0x93AB1CFF,0x95BAF0FF,0x369976FF,0x18F71FFF,0x4B8987FF,
0x491B9EFF,0x829DC7FF,0xBCE635FF,0xCEA6DFFF,0x20D4ADFF,0x2D74FDFF,0x3C1C0DFF,0x12D6D4FF,0x2A51E2FF,0xE3AC12FF,
0xFC42A8FF,0x2FC827FF,0x1A30BFFF,0xB740C2FF,0x42ACF5FF,0x2FD9DEFF,0xFAFB71FF,0x05D1CDFF,0xC471BDFF,0x94436EFF,0xC1F7ECFF,
0xCE79EEFF,0xBD1EF2FF,0x93B7E4FF,0x3214AAFF,0x184D3BFF,0xAE4B99FF,0x7E49D7FF,0x4C436EFF,0xFA24CCFF,0xCE76BEFF,0xA04E0AFF,
0x9F945CFF,0xDCDE3DFF,0x10C9C5FF,0x70524DFF,0x0BE472FF,0x8A2CD7FF,0x6152C2FF,0xCF72A9FF,0xE59338FF,0xEEDC2DFF,0xD8C762FF,
0x3FE65CFF
};
//==============================================================================


OnPlayerConnect

//============================================================================== RANDOM COLOUR WHEN CONNECT
new rand = random(sizeof(playerColors));
SetPlayerColor(playerid, playerColors[rand]);
works for me ;P
OMGWTF, another code that shall never work better than my script. It's exactly the same, only you have 100 random colors and i have 9.
Well use that, but change the colours, to the ones you want!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)