Problem with Random Skin
#1

I got a problem in my script. When the player spawn, if the player choose male, the skin that spawned is female skin. Can anyone help me?

Код:
stock IsValidSkin(skinid)
{
	if (skinid < 0 || skinid > 299)
	    return 0;

	switch (skinid)
	{
	    case
		0, 69, 123, 147, 163, 21, 24, 143, 71,
		156, 176, 177, 165, 166, 275, 265, 266, 
		267, 269, 270, 271, 274, 276, 277, 278, 
		279, 280, 281, 282, 283, 284, 285, 286, 
		287, 288, 294, 296, 297: return 0;
	}

	return 1;
}

stock IsFemaleSpawnSkin(skinid)
{
	switch (skinid)
	{
	    case
		9, 11, 12, 13, 31, 38, 39, 40, 41, 53, 54,
		55, 56, 65, 76, 77, 89, 91, 93, 129, 130,
		131, 141, 148, 150, 151, 157, 169, 172, 190,
		191, 192, 193, 194, 195, 196, 197, 198, 199,
		211, 214, 215, 216, 218, 219, 224, 225, 226,
		231, 232, 233, 263, 298: return 1;
	}

	return 0;
}

stock IsFemaleSkin(skinid)
{
	switch (skinid)
	{
	    case
		9, 11, 12, 13, 31, 38, 39, 40, 41, 53, 54, 55,
		56, 63, 64, 65, 75, 76, 77, 85, 87, 88, 89, 90,
		91, 92, 93, 129, 130, 131, 138, 139, 140, 141,
		145, 148, 150, 151, 152, 157, 169, 172, 178, 190,
		191, 192, 193, 194, 195, 196, 197, 198, 199, 201,
		205, 207, 211, 214, 215, 216, 218, 219, 224, 225,
		226, 231, 232, 233, 237, 238, 243, 244, 245, 246,
		251, 256, 257, 263, 298: return 1;
	}

	return 0;
}
Код:
if(dialogid == DIALOG_SPAWN)
    {
		if(response || !response)
		{

			for(new x;x<10000;x++)
						{
							new rand=random(300);
							if(PlayerInfo[playerid][pSex] == 0)
							{
								if(IsValidSkin(rand))
								{
									PlayerInfo[playerid][pModel] = rand;
									SetPlayerSkin(playerid, rand);
									break;
								}
							}
							else
							{
								if(IsFemaleSkin(rand))
								{
									PlayerInfo[playerid][pModel] = rand;
									SetPlayerSkin(playerid, rand);
									break;
								}
							}
						}
Reply
#2

You should not random 300 because that number may be randomed out of 299 and will cause your server to crash.

pawn Код:
if(dialogid == DIALOG_SPAWN)
    {
        if(response || !response)
        {

            for(new x;x<10000;x++)
                        {
                            new rand=random(299);
                            if(PlayerInfo[playerid][pSex] == 0)
                            {
                                if(IsValidSkin(rand))
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
                            else
                            {
                                if(IsFemaleSkin(rand))
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
                        }
And you are getting random skins because you're randoming 299 not only Female skins, get the male ID's then save them somewhere, randomize one of these IDs to get this working aswell as Female ones.
Reply
#3

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
You should not random 300 because that number may be randomed out of 299 and will cause your server to crash.

pawn Код:
if(dialogid == DIALOG_SPAWN)
    {
        if(response || !response)
        {

            for(new x;x<10000;x++)
                        {
                            new rand=random(299);
                            if(PlayerInfo[playerid][pSex] == 0)
                            {
                                if(IsValidSkin(rand))
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
                            else
                            {
                                if(IsFemaleSkin(rand))
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
                        }
And you are getting random skins because you're randoming 299 not only Female skins, get the male ID's then save them somewhere, randomize one of these IDs to get this working aswell as Female ones.
I think I save it here
Код:
stock IsValidSkin(skinid)
{
	if (skinid < 0 || skinid > 299)
	    return 0;

	switch (skinid)
	{
	    case
		0, 69, 123, 147, 163, 21, 24, 143, 71,
		156, 176, 177, 165, 166, 275, 265, 266, 
		267, 269, 270, 271, 274, 276, 277, 278, 
		279, 280, 281, 282, 283, 284, 285, 286, 
		287, 288, 294, 296, 297: return 0;
	}

	return 1;
}

stock IsFemaleSpawnSkin(skinid)
{
	switch (skinid)
	{
	    case
		9, 11, 12, 13, 31, 38, 39, 40, 41, 53, 54,
		55, 56, 65, 76, 77, 89, 91, 93, 129, 130,
		131, 141, 148, 150, 151, 157, 169, 172, 190,
		191, 192, 193, 194, 195, 196, 197, 198, 199,
		211, 214, 215, 216, 218, 219, 224, 225, 226,
		231, 232, 233, 263, 298: return 1;
	}

	return 0;
}

stock IsFemaleSkin(skinid)
{
	switch (skinid)
	{
	    case
		9, 11, 12, 13, 31, 38, 39, 40, 41, 53, 54, 55,
		56, 63, 64, 65, 75, 76, 77, 85, 87, 88, 89, 90,
		91, 92, 93, 129, 130, 131, 138, 139, 140, 141,
		145, 148, 150, 151, 152, 157, 169, 172, 178, 190,
		191, 192, 193, 194, 195, 196, 197, 198, 199, 201,
		205, 207, 211, 214, 215, 216, 218, 219, 224, 225,
		226, 231, 232, 233, 237, 238, 243, 244, 245, 246,
		251, 256, 257, 263, 298: return 1;
	}

	return 0;
}
But the spawned skin is always female skin.
Reply
#4

bump
Reply
#5

bump
Reply
#6

The problem is here:
pawn Код:
{
                            new rand=random(300);
                            if(PlayerInfo[playerid][pSex] == 0)
                            {
                                if(IsValidSkin(rand))
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
                            else
                            {
                                if(IsFemaleSkin(rand))
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
                        }
pawn Код:
new rand=random(300);
                            if(PlayerInfo[playerid][pSex] == 0)
                            {
                                while(!IsValidSkin(rand))
                                {
                                                                rand=random(300);
                                }
                                                                        PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                            }
                            else
                            {
                                if(IsFemaleSkin(rand))
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
You must get a valid skin. You were just verifying if the rand was a valid skin and if it was not, you were moving forward.
Reply
#7

Quote:
Originally Posted by Koala818
Посмотреть сообщение
The problem is here:
pawn Код:
{
                            new rand=random(300);
                            if(PlayerInfo[playerid][pSex] == 0)
                            {
                                if(IsValidSkin(rand))
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
                            else
                            {
                                if(IsFemaleSkin(rand))
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
                        }
pawn Код:
new rand=random(300);
                            if(PlayerInfo[playerid][pSex] == 0)
                            {
                                while(!IsValidSkin(rand))
                                {
                                                                rand=random(300);
                                }
                                                                        PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                            }
                            else
                            {
                                if(IsFemaleSkin(rand))
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
You must get a valid skin. You were just verifying if the rand was a valid skin and if it was not, you were moving forward.
Thanks for helping but still the spawned skin is female
Reply
#8

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
pawn Код:
else
{
    if(!IsFemaleSkin(rand)) continue;
    PlayerInfo[playerid][pModel] = rand;
    SetPlayerSkin(playerid, rand);
    break;
}
Still bug this is my code now
Код:
if(dialogid == DIALOG_SPAWN)
    {
		if(response || !response)
		{

			for(new x;x<10000;x++)
						{
							new rand=random(299);
                            if(PlayerInfo[playerid][pSex] == 0)
                            {
                                while(!IsValidSkin(rand))
                                {
                                rand=random(299);
                                }
                                	PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                            }
                            else
                            {
                                if(!IsFemaleSkin(rand)) continue;
                                {
                                    PlayerInfo[playerid][pModel] = rand;
                                    SetPlayerSkin(playerid, rand);
                                    break;
                                }
                            }
						}
Reply
#9

bump
Reply
#10

bump
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)