stock not working - 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: stock not working (
/showthread.php?tid=614287)
stock not working -
GunZsmd - 06.08.2016
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] =
{
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 false;
}
#undef MAX_BAD_MODELS
return 1;
}
Re: stock not working -
Misiur - 06.08.2016
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.
Re: stock not working -
Konstantinos - 06.08.2016
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;
}
Re: stock not working -
Shinja - 06.08.2016
Quote:
Originally Posted by Konstantinos
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;
}
}
Re: stock not working -
Konstantinos - 06.08.2016
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).