PDA

View Full Version : Problem Skin


KamilPolska
31/03/2019, 11:28 PM
I have a problem with cmd. I want to make my skin change after entering the command /buyskin 1 or /buyskin 2. And when I type /buyskin 3 or /buyskin 270 it pops up a message that I can not choose it skiny.

new Disguise[][] = { {1}, {2} };

CMD:buyskin(playerid, params[])
{
if(IsPlayerInRangeOfPoint(playerid, 0.0, 0.0, 0.0, 0.0))
{
new lolgf;
if(sscanf(params, "d", lolgf))
{
SendClientMessage(playerid, -1, "Usage /buyskin [skin id]");
return 1;
}
new well = 0;
if(lolgf > 0 && lolgf < 300)
{
for(new skin = 0; skin < 300; skin++)
{
if(lolgf == Disguise[skin][0])
{
well = 1;
}
}
if(well == 1)
{
PlayerInfo[playerid][skin_id] = lolgf;
SetPlayerSkin(playerid, lolgf);
SendClientMessage(playerid, -1, "You bought a new skin!");
}
else
{
SendClientMessage(playerid, -1, "You can not choose this skin!");
}
}
else
{
SendClientMessage(playerid, -1, "Skin from 1 to 299!");
}
}
return 1;
}

MP2
01/04/2019, 01:17 PM
The behaviour you described is exactly what the code is set up to do. You are checking if the skin they enter matches the values in the 'Disguise' array. What exactly is the purpose of this array in terms of how is it meant to work with this command? There are only two elements in this array but you have set the code up so that it can check any skin index up to 300.

Also, you have a two-dimensional array but are only using a single element in each dimension.. An array does not need two dimensions to only store one set of values.

Also, a small bit of advice, it would be helpful for yourself and others if you gave your variables meaningful or symbolic names instead of just 'lolgf' and 'well'. It is unclear what the purpose of these variables is and whether or not they are meant to be doing what they are in fact doing..

To clarify..

if(lolgf == Disguise[skin][0])

lolgf = the value they entered as a parameter, correct? Disguise[skin][0] - the first dimension in the 'Disguise' array only has two elements so you could only check Disguise[0] and Disguise[1] so you're going to have an array index out-of-bounds error if you try to check this for skin 2 or higher.

KamilPolska
02/04/2019, 05:05 PM
Thanks!