SA-MP Forums Archive
Problem with Random Skin - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem with Random Skin (/showthread.php?tid=512697)



Problem with Random Skin - Auditore155 - 12.05.2014

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;
								}
							}
						}



Re: Problem with Random Skin - Beckett - 12.05.2014

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.


Re: Problem with Random Skin - Auditore155 - 14.05.2014

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.


Re: Problem with Random Skin - Auditore155 - 16.05.2014

bump


Re: Problem with Random Skin - Auditore155 - 17.05.2014

bump


Re: Problem with Random Skin - Koala818 - 17.05.2014

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.


Re: Problem with Random Skin - Auditore155 - 18.05.2014

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


Re: Problem with Random Skin - Auditore155 - 18.05.2014

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;
                                }
                            }
						}



Re: Problem with Random Skin - Auditore155 - 19.05.2014

bump


Re: Problem with Random Skin - Auditore155 - 30.05.2014

bump