stock not working
#1

hi guys,
so my stock what i pretend from it is when a player doesnt choose one of those ID's there it returns false but it is returning false on every single time.
PHP Code:
stock IsValidModelPlane(modelid)
{
    
#define    MAX_BAD_MODELS 128
    
new allowedmodels[MAX_BAD_MODELS] =
    {
        
511512513593417469487548563
    
};
    if (
modelid 400 || modelid 611) return false;
    for (new 
0MAX_BAD_MODELSi++)
    {
        if (
modelid != allowedmodels[i]) return false;
    }
    
#undef MAX_BAD_MODELS
    
return 1;

Reply
#2

pawn Code:
stock IsValidModelPlane(modelid)
{
    #define    MAX_BAD_MODELS 128
    new allowedmodels[MAX_BAD_MODELS] =
    {
        511, 512, 513, 593, 417, 469, 487, 548, 563
    };
    if (modelid < 400 || modelid > 611) return false;
    for (new i = 0; i < MAX_BAD_MODELS; i++)
    {
        if (modelid == allowedmodels[i]) return true;
    }
    #undef MAX_BAD_MODELS

    return false;
}
By your logic it must match all allowedmodels, by the code I gave you only single one is required.
Reply
#3

I don't really see any reason for using a local array and a loop:

pawn Code:
IsValidModelPlane(modelid)
{
    switch (modelid)
    {
        case 511, 512, 513, 593, 417, 469, 487, 548, 563: return 1;
    }
    return 0;
}
Reply
#4

Quote:
Originally Posted by Konstantinos
View Post
I don't really see any reason for using a local array and a loop:

pawn Code:
IsValidModelPlane(modelid)
{
    switch (modelid)
    {
        case 511, 512, 513, 593, 417, 469, 487, 548, 563: return 1;
    }
    return 0;
}
Is this same as?
pawn Code:
IsValidModelPlane(modelid)
{
    switch (modelid)
    {
        case 511, 512, 513, 593, 417, 469, 487, 548, 563: return 1;
        default: return 0;
    }
}
Reply
#5

The function needs to return a value after the switch so it is pointless to return 0 twice (one in "default:" and the other at the end).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)