Random Skins
#1

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);
Reply
#2

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.
Reply
#3

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!
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)