SA-MP Forums Archive
More simple way to do this? - 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: More simple way to do this? (/showthread.php?tid=334182)



More simple way to do this? - 2KY - 14.04.2012

pawn Code:
public OnGameModeInit()
{
    for( new SkinID; SkinID < MAX_SKIN_ID; SkinID ++ )
    {
        switch( SkinID )
        {
            //Add the exceptions here - Normal users will NOT be allowed to select them!
           
            case 0: SkinID ++;
                //Not allowed to select this due to it being the Carl Johnson skin model!
               
            case 165: SkinID ++;
            case 166: SkinID ++;
            case 211: SkinID ++;
            case 217: SkinID ++;
            case 294: SkinID ++;
                //Not allowed to select these due to them being a 'Staff only' skin model!
               
            case 265: SkinID ++;
            case 266: SkinID ++;
            case 267: SkinID ++;
            case 274: SkinID ++;
            case 275: SkinID ++;
            case 276: SkinID ++;
            case 277: SkinID ++;
            case 278: SkinID ++;
            case 279: SkinID ++;
            case 280: SkinID ++;
            case 281: SkinID ++;
            case 282: SkinID ++;
            case 283: SkinID ++;
            case 284: SkinID ++;
            case 285: SkinID ++;
            case 286: SkinID ++;
            case 287: SkinID ++;
            case 288: SkinID ++;
                //Not allowed to select these due to them being a 'Specialized Service' skin model!
           
            default: AddPlayerClass( SkinID, 0,0,0,0, 0,0, 0,0, 0,0 );
                //They are allowed to use these skins, and have, as a result, been created!
        }
    }
    return 1;
}



Re: More simple way to do this? - [HiC]TheKiller - 14.04.2012

You could always do something like the following:

pawn Code:
stock IsValidSkin(skinid)
{
    new noskin[25] = {0, 165, 166, 211, 217, 294, 265, 266, 267, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288};
    for(new i; i<25; i++)
    {
        if(skinid == noskin[i]) return 0;
    }
    return 1;
}

public OnGameModeInit()
{
    for( new SkinID; SkinID < MAX_SKIN_ID; SkinID ++ )
    {
        if(IsValidSkin(SkinID) == 1) AddPlayerClass( SkinID, 0,0,0,0, 0,0, 0,0, 0,0 );
    }
    return 1;
}
This method is actually probably less efficient than what you have currently though. There are also other methods but they are pretty much similar.


Re: More simple way to do this? - 2KY - 14.04.2012

Quote:
Originally Posted by [HiC]TheKiller
View Post
You could always do something like the following:

pawn Code:
stock IsValidSkin(skinid)
{
    new noskin[25] = {0, 165, 166, 211, 217, 294, 265, 266, 267, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288};
    for(new i; i<25; i++)
    {
        if(skinid == noskin[i]) return 0;
    }
    return 1;
}

public OnGameModeInit()
{
    for( new SkinID; SkinID < MAX_SKIN_ID; SkinID ++ )
    {
        if(IsValidSkin(SkinID) == 1) AddPlayerClass( SkinID, 0,0,0,0, 0,0, 0,0, 0,0 );
    }
    return 1;
}
This method is actually probably less efficient than what you have currently though. There are also other methods but they are pretty much similar.
So what you're saying is what I have is pretty much the best it gets? Considering calling a stock is probably less efficient than a switch statement. (like you said) Thank you.


Re: More simple way to do this? - Joe Staff - 14.04.2012

You could simplify your code like this:

pawn Code:
stock IsValidSkin(skinid)
{
    switch(skinid)case 0,165,166,211,217,265,266,267,274,275,276,277,278,279,280,281,283,283,284,285,286,287,288,294: return 0;
    return 1;
}