Re: Useful Functions -
dice7 - 29.12.2009
Quote:
Originally Posted by Y_Leѕѕ
Quote:
Originally Posted by |∞|-Рцппσĵσ-|∞|
pawn Код:
public IsACivillianSkin(skinid) { #define MAX_LAW_SKINS 16 new BadLawSkin[MAX_LAW_SKINS] = { 166, 165, 164, 163, 280, 281, 282, 283, 288, 284, 285, 287, 57, 265, 266, 267 }; for (new i = 0; i < MAX_LAW_SKINS; i++) if(skinid == BadLawSkin[i]) return false; #undef MAX_LAW_SKINS return 1; }
|
Again, doesn't need to be public. Also you may want to read this topic, specifically the part I've directly linked to:
http://forum.sa-mp.com/index.php?top...post_reduction
|
It's just that people absolutely love to copy from Godfather
pawn Код:
IsACivillianSkin(skinid)
{
switch(skinid)
{
case 166, 165, 164, 163, 280, 281, 282, 283, 288, 284, 285, 287, 57, 265, 266, 267: {return 0;}
}
return 1;
}
Re: Useful Functions -
Luka P. - 29.12.2009
Quote:
Originally Posted by dice7
Quote:
Originally Posted by Y_Leѕѕ
Quote:
Originally Posted by |∞|-Рцппσĵσ-|∞|
pawn Код:
public IsACivillianSkin(skinid) { #define MAX_LAW_SKINS 16 new BadLawSkin[MAX_LAW_SKINS] = { 166, 165, 164, 163, 280, 281, 282, 283, 288, 284, 285, 287, 57, 265, 266, 267 }; for (new i = 0; i < MAX_LAW_SKINS; i++) if(skinid == BadLawSkin[i]) return false; #undef MAX_LAW_SKINS return 1; }
|
Again, doesn't need to be public. Also you may want to read this topic, specifically the part I've directly linked to:
http://forum.sa-mp.com/index.php?top...post_reduction
|
It's just that people absolutely love to copy from Godfather
pawn Код:
IsACivillianSkin(skinid) { switch(skinid) { case 166, 165, 164, 163, 280, 281, 282, 283, 288, 284, 285, 287, 57, 265, 266, 267: {return 0;} } return 1; }
|
You don't need those brackets {} at case becase you're useing one function or whatever
pawn Код:
IsACivillianSkin(skinid)
{
switch(skinid)
{
case 166, 165, 164, 163, 280, 281, 282, 283, 288, 284, 285, 287, 57, 265, 266, 267: return 0;
}
return 1;
}
Re: Useful Functions -
Luka P. - 30.12.2009
How long do you scripting/programming, ******?
Your work is really awesome!
Re: Useful Functions -
Nero_3D - 30.12.2009
Quote:
Originally Posted by Luka™
How long do you scripting/programming, ******?
Your work is really awesome!
|
Sure he is

He started with a very young age because his dad is a well known programmer (or something like that)
And he is not like the most of this community around ~16 or ~15 (if you look at the age thread - bad youth)
He should be something around 25, I think
But I got a question, too, why are you still that active and your lastname, want to ****** for your dad again
And admin can delete that in the near future
Re: Useful Functions -
LarzI - 30.12.2009
Alex "******" Cole
Always remember that name.
Sa-mp's pride
Re: Useful Functions -
Djiango - 30.12.2009
Quote:
Originally Posted by Y_Leѕѕ
Quote:
Originally Posted by |∞|-Рцппσĵσ-|∞|
Forward.
pawn Код:
forward PlayerReport(id, sound);//Play crime report for players
|
Shouldn't need this as the function doesn't need to be public.
Quote:
Originally Posted by |∞|-Рцппσĵσ-|∞|
pawn Код:
public IsACivillianSkin(skinid) { #define MAX_LAW_SKINS 16 new BadLawSkin[MAX_LAW_SKINS] = { 166, 165, 164, 163, 280, 281, 282, 283, 288, 284, 285, 287, 57, 265, 266, 267 }; for (new i = 0; i < MAX_LAW_SKINS; i++) if(skinid == BadLawSkin[i]) return false; #undef MAX_LAW_SKINS return 1; }
|
Again, doesn't need to be public. Also you may want to read this topic, specifically the part I've directly linked to:
http://forum.sa-mp.com/index.php?top...post_reduction
|
I don't get it. I made it public's as stock's are slower.
So what exactly are you trying to say?
I've been reading alot of your topics, but I don't get the bit part yet?
Some topics seems a little confusing, if you only know pawn.
Quote:
Originally Posted by dice7
It's just that people absolutely love to copy from Godfather
|
I may have used a godfather function. I don't really know, as I haven't used gf.
I think I found the function on this forum, and edited it to fit my gm.
Anyways. Thanks for the hints.
I learn new things every day. So thanks for pointing me in the right direction.
Re: Useful Functions -
ded - 30.12.2009
Afaik, functions don't need to be public unless they are called by SetTimerEx and things.
Re: Useful Functions -
Djiango - 30.12.2009
Thanks pawnstar.
I've been reading about publics, and I think I get it now.
https://sampwiki.blast.hk/wiki/Public_functions
Re: Useful Functions -
ded - 30.12.2009
No problemo
Re: Useful Functions -
M4S7ERMIND - 31.12.2009
what does quicksort do? some efficient data collection O(xn) O(n) O(1І).. it would take me 4 days to figure out what ******'s functions do. >_<
Re: Useful Functions -
Donny_k - 31.12.2009
"IsACivillianSkin(...)" This function is a modified version of "IsValidSkin" from Simons debug script IIRC.
Quote:
Originally Posted by » ραωпsтαг «
Afaik, functions don't need to be public unless they are called by SetTimerEx and things.
|
Functions are required to be public when they are being called by the machine, this is when it's a timer or you are calling it using the CallLocal/RemoteFunction, they don't need to be public unless they are one of the two.
Quote:
Originally Posted by Mастерминд
what does quicksort do? some efficient data collection O(xn) O(n) O(1І).. it would take me 4 days to figure out what ******'s functions do. >_<
|
It makes this "64938" into this "34689", it's sorts values into an order (score systems mostly use it).
Re: Useful Functions -
ded - 31.12.2009
Quote:
Originally Posted by Donny
Functions are required to be public when they are being called by the machine, this is when it's a timer or you are calling it using the CallLocal/RemoteFunction, they don't need to be public unless they are one of the two.
|
Uh huh, like I said.
Re: Useful Functions -
Donny_k - 31.12.2009
Quote:
Originally Posted by » ραωпsтαг «
Quote:
Originally Posted by Donny
Functions are required to be public when they are being called by the machine, this is when it's a timer or you are calling it using the CallLocal/RemoteFunction, they don't need to be public unless they are one of the two.
|
Uh huh, like I said. 
|
Yes I know, I was filling in the blanks ("things").
I'm not correcting you dude.
Re: Useful Functions -
ded - 31.12.2009
Lol, sorry.
Re: Useful Functions -
M4S7ERMIND - 31.12.2009
Quote:
Originally Posted by Y_Leѕѕ
That's "Big O" notation - it's a representation of how long an algorithm takes.
O(n) - Means the function takes time relative to the number of items in it (so searching 32 skins will take longer than searching 16).
O(xn) - Means it is also relative to the number of items, but slower than the other one per item (I'm not sure this is valid notation).
O(1) - Means it always takes the same time regardless of the number of items.
|
I dont know if I understood right

O(1) is the most efficient, then O(n) and O(xn) is least efficient..
Alright, I used GenerateList for IsValidSkin:
pawn Код:
new Skins[284] =
{
20,21,22,23,24,25,67,26,27,28,29,30,31,32,33,
34,35,36,37,38,39,40,41,43,44,45,46,47,48,49,
50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,
68,69,70,71,72,73,75,76,77,78,79,80,81,82,83,
84,85,87,88,89,90,91,92,93,94,95,96,97,98,99,
101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,120,121,122,123,
124,125,126,127,128,129,130,131,132,133,134,
135,136,137,138,139,140,141,142,143,144,145,
146,147,148,150,151,152,153,154,155,156,157,
158,159,160,161,162,163,164,165,166,167,168,
169,170,171,172,173,174,175,176,177,178,179,
180,181,182,183,184,185,186,187,188,189,190,
191,192,193,194,195,196,197,198,199,200,201,
202,203,204,205,206,207,209,210,211,212,213,
214,215,216,217,218,219,220,221,222,223,224,
225,226,227,228,229,230,231,232,233,234,235,
236,237,238,239,240,241,242,243,244,245,246,
247,248,249,250,251,252,253,254,255,255,257,
258,259,260,261,262,263,264,265,266,267,268,
269,270,271,272,274,275,276,277,278,279,280,
281,282,283,284,285,286,287,288,290,291,292,
293,294,295,296,297,298,299,0,1,2,7,9,10,11,
12,13,14,15,16,17,18,19
};
main()
{
GenerateList("Gamemode.pwn", "IsValidSkin", Skins, true);
}
stock IsValidSkin(skinid)
{
if(skinid >= 0 && skinid <= 2 || skinid == 7 || skinid >= 9 && skinid <= 41 || skinid >= 43 && skinid <= 64 || skinid >= 66 && skinid <= 73 || skinid >= 75 && skinid <= 85 || skinid >= 87 &&
skinid <= 118 || skinid >= 120 && skinid <= 148 || skinid >= 150 && skinid <= 207 || skinid >= 209 && skinid <= 264 || skinid >= 274 && skinid <= 288 || skinid >= 290 && skinid <= 299) return 1;
return 0;
}
It generated me this:
pawn Код:
stock bool:
IsValidSkin(val) //line 11195
{
static
s_iValArray[] =
{
-377, -1025, -4195335, -8388625, -2097153,
-1, -65537, -1, -131074, 4093
};
if (val > 299)
{
return false;
}
return (s_iValArray[val >> 5] & (1 << (val & 0x1F))); //line 11207
}
I use it like this:
pawn Код:
if(!IsValidSkin(skinid)) return SendClientMessage(Invalid skin ID...
Then I compile and it gives me 2 warnings:
(11195) : warning 208: function with tag result used before definition, forcing reparse
(11207) : warning 213: tag mismatch
The warnings are gone when I remove
bool: from line 11194, so I dont know why theres bool.. :\
Anyway, is that more efficient than IsValidSkin I used before
Re: Useful Functions -
M4S7ERMIND - 31.12.2009
The tag problem got fixed, when I moved the function above where its used, however the tag mismatch was still there.
I generated:
GenerateList("Gamemode.pwn", "IsValidSkin", Skins, false);, changed the function to IsInvalidSkin and then
the tag mismatch warning was gone. :S
I try to make my server as efficient as possible, thanks for help ****** ^^
Re: Useful Functions -
M4S7ERMIND - 31.12.2009
Quote:
Originally Posted by Y_Leѕѕ
In general you should always give a list of everything for which is applies and return true
|
Why would I start filling a list that return false. It would take me forever :S
Im glad you fixed
tag mismatch problem and thanks for providing me with such a useful information and for the update link. ^^
Re: Useful Functions -
StrickenKid - 01.01.2010
Useful string & charcter uppercase and lowercase functions
pawn Код:
stock bool:isupper(c)
{
if (c >= 65 && c <= 90)
return true;
return false;
}
Usage:
Код:
isupper( char ) - returns true if the char is uppercase, returns false if not
pawn Код:
stock strtolower(str[])
{
for (new i = 0, j = strlen(str); i < j; i++)
{
if (isupper(str[i]))
str[i] += 32;
}
}
Usage:
Код:
strtolower( "StRiNg" ) - translates the uppercase chars to lowercase - does not return a specific value
pawn Код:
stock bool:islower(c)
{
if (c >= 97 && c <= 122)
return true;
return false;
}
Usage:
Код:
islower( char ) - returns true if the char is lowercase, returns false if not
pawn Код:
stock strtoupper(str[])
{
for (new i = 0, j = strlen(str); i < j; i++)
{
if (islower(str[i]))
str[i] -= 32;
}
}
Usage:
Код:
strtoupper( "StRiNg" ) - translates the lowercase chars to uppercase - does not return a specific value
Happy coding and have a happy new years,
Ethan
Re: Useful Functions -
LarzI - 01.01.2010
Nice one's Ethan
Re: Useful Functions -
Nero_3D - 01.01.2010
Quote:
Originally Posted by lrZ^ aka LarzI
Nice one's Ethan 
|
there is nothing nice :S
and what do you know about if(statement) return true; else return false;
pawn Код:
#define islower(%1) ('a' <= %1 <= 'z')
#define isupper(%1) ('A' <= %1 <= 'Z')
//tolower© and toupper© already exist - pawn-lang.pdf page 127-128