SA-MP Forums Archive
Random Skins - 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: Random Skins (/showthread.php?tid=614254)



Random Skins - Allura - 06.08.2016

Is there a better way to do this? It works fine, but any better way of doing it and I'll be super grateful!
Code checks at OnAccountLoad whether they are male or female, and have the skin ID under 1. If so, it'll generate three random skins if male, and three if female. Else, it will load normal skin from the database.

Код:
new MaleSkins[][4] =
{
	{6}, // Emmet
	{29}, // Drug Dealer
	{48} // hmyst
};

new FemaleSkins[][4] =
{
	{40}, // Normal Ped
	{41}, // Normal Ped
	{56} // Normal Ped
};
Код:
    if(!strcmp(Player[playerid][Gender], "Male") && Player[playerid][Skin] < 1)
	{
	    new rand = random(sizeof(MaleSkins));
		SetSpawnInfo(playerid, 0, MaleSkins[rand][0], Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 0, 0, 0, 0, 0, 0);
		Player[playerid][Skin] = GetPlayerSkin(playerid);
	}
 	else if(!strcmp(Player[playerid][Gender], "Female") && Player[playerid][Skin] < 1)
	{
 		new rand = random(sizeof(FemaleSkins));
		SetSpawnInfo(playerid, 0, FemaleSkins[rand][0], Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 0, 0, 0, 0, 0, 0);
		Player[playerid][Skin] = GetPlayerSkin(playerid);
	}
	else
	{
 		Player[playerid][Skin] = cache_get_field_content_int(0, "Skin");
		SetSpawnInfo(playerid, 0, Player[playerid][Skin], Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 0, 0, 0, 0, 0, 0);
	}
   	SpawnPlayer(playerid);



Re: Random Skins - Konstantinos - 06.08.2016

A bit more organized:
pawn Код:
if (Player[playerid][Skin] < 1)
{
    if (!strcmp(Player[playerid][Gender], "Male")) Player[playerid][Skin] = MaleSkins[random(sizeof MaleSkins)];
    else Player[playerid][Skin] = FemaleSkins[random(sizeof FemaleSkins)];
}
else Player[playerid][Skin] = cache_get_field_content_int(0, "Skin");

SetSpawnInfo(playerid, 0, Player[playerid][Skin], Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
EDIT: It is much better to save the gender as an integer like 1 for male and 2 for female.


Re: Random Skins - Allura - 06.08.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
A bit more organized:
pawn Код:
if (Player[playerid][Skin] < 1)
{
    if (!strcmp(Player[playerid][Gender], "Male")) Player[playerid][Skin] = MaleSkins[random(sizeof MaleSkins)];
    else Player[playerid][Skin] = FemaleSkins[random(sizeof FemaleSkins)];
}
else Player[playerid][Skin] = cache_get_field_content_int(0, "Skin");

SetSpawnInfo(playerid, 0, Player[playerid][Skin], Player[playerid][posX], Player[playerid][posY], Player[playerid][posZ], Player[playerid][posA], 0, 0, 0, 0, 0, 0);
SpawnPlayer(playerid);
EDIT: It is much better to save the gender as an integer like 1 for male and 2 for female.
Thanks so much!


Re: Random Skins - Konstantinos - 06.08.2016

On another note: a 1D array is enough:

pawn Код:
new MaleSkins[] =
{
    6, // Emmet
    29, // Drug Dealer
    48 // hmyst
};

new FemaleSkins[] =
{
    40, // Normal Ped
    41, // Normal Ped
    56 // Normal Ped
};