SA-MP Forums Archive
Today I learned - Share your newly found knowledge! - 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: Today I learned - Share your newly found knowledge! (/showthread.php?tid=359953)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18


Re: Today I learned - Share your newly found knowledge! - milanosie - 21.07.2012

Today I learned that the bone structure of skin Id 267 Officer Jimmy Hernandez Is fucked up.


Re: Today I learned - Share your newly found knowledge! - Vince - 21.07.2012

Today I learned that the name of an enum also defines its total size.


AW: Re: Today I learned - Share your newly found knowledge! - Nero_3D - 22.07.2012

Quote:
Originally Posted by Vince
View Post
Today I learned that the name of an enum also defines its total size.
Only if you use the default increment (+= 1)

Today I learned that NOP's are slower than no code


Re: Today I learned - Share your newly found knowledge! - Niko_boy - 22.07.2012

Today i learnt that you can use 0 < Var < 5 instead of Var > 0 && Var < 5
<meh was so ez>


Re: Today I learned - Share your newly found knowledge! - MrDeath537 - 22.07.2012

Today I learned how to use the '%' operator!
It gives you the rest of a division, for example:
pawn Code:
9 / 4 // This will give you 2
9 % 4 // This will give you 1



Re: Today I learned - Share your newly found knowledge! - JoBullet - 22.07.2012

The '%'(modulus) operator returns remainder of division.


Re: Today I learned - Share your newly found knowledge! - Sasino97 - 22.07.2012

Quote:
Originally Posted by Niko_boy
View Post
Today i learnt that you can use 0 < Var < 5 instead of Var > 0 && Var < 5
<meh was so ez>
I studied that way of writing (x < y < z means y is between x and z) at school, but I discovered that you can use it in Pawn and in some other languages very recently.


Re: Today I learned - Share your newly found knowledge! - Slice - 22.07.2012

Today I learned getdate(&year=0, &month=0, &day=0) returns the current day of the year (i.e. 5th of febuary is the 36th day).


Re: Today I learned - Share your newly found knowledge! - Matz - 22.07.2012

Today I learned ;
pawn Code:
new Float:vec[3]; GetPlayerPos(playerid,vec[0],vec[1],vec[2]);
instead of
pawn Code:
new Float:X, Float:Y, Float:Z; GetPlayerPos(playerid,X,Y,Z);



Re: Today I learned - Share your newly found knowledge! - Slice - 23.07.2012

Today I learned because of compiler bug, you can place entries in the public functions table by doing this:
pawn Code:
forward public SomeFunction();
SomeFunction(){}
Not one extra instruction of code will be inside the AMX.


Re: Today I learned - Share your newly found knowledge! - Rudy_ - 25.07.2012

Today i learned how to use Stocks.

pawn Код:
stock KillPlayer(playerid)
{
    SetPlayerHealth(playerid, 0.0);
    return 1;
}
just a gay example
PS: had to go that's why didnt added how to use it in Command :S


Re: Today I learned - Share your newly found knowledge! - JoBullet - 25.07.2012

Today I learned that this is how you enforce someone implementing function(not public) to return array of exact size:

Код:
forward [128] getMessage(playerid);

stock getMessage(playerid)
{
    #pragma unused playerid
    new msg[128];
    return msg;
}
Of course those work for multiple dimensions too.

Код:
forward [128][1][2] getInfo();

stock getInfo()
{
    new info[128][1][2];
    info[0][0][1] = 1;
    return info;
}
This also works for natives:
Код:
native [128] getClientMessage(playerid);



Re: Today I learned - Share your newly found knowledge! - MP2 - 26.07.2012

Today I learnt (or more realised) how to pass indeterminate sized arrays to functions:

pawn Код:
stock CreateVehicleSpawn(someArray[], someArray_size = sizeof(someArray))
{
    // blah
}
because doing this will produce an error:

pawn Код:
stock CreateVehicleSpawn(someArray[])
{
    printf("Array size: %i", sizeof(someArray));
}
'indeterminate array size in sizeof expression'


Re: Today I learned - Share your newly found knowledge! - SuNL1GhT - 28.07.2012

Today I learned how to make a simple teleport command.

Quote:

if (strcmp("/lv", cmdtext, true, 10) == 0)
{
SetPlayerPos (playerid, 2002.1925,1543.9114,13.5859);
SetPlayerInterior (playerid, 0);
SendClientMessage (playerid, 0xaa3333a, "Welcome to Las Venturas.");
SendClientMessage (playerid, 0xFFFFFFF, "This area is free to map!");
return 1;
}

if (strcmp("/lvair", cmdtext, true, 10) == 0)
{
SetPlayerPos (playerid, 1592.0784,1171.6952,14.2241);
SetPlayerInterior (playerid, 0);
SendClientMessage (playerid, 0xaa3333a, "Welcome to Las Venturas Airport.");
SendClientMessage (playerid, 0xFFFFFFF, "This area is free to map!");
return 1;
}

if (strcmp("/sfair", cmdtext, true, 10) == 0)
{
SetPlayerPos (playerid, -1161.7926,33.5112,14.1484);
SetPlayerInterior (playerid, 0);
SendClientMessage (playerid, 0xaa33331, "Welcome to San Fierro Airport.");
SendClientMessage (playerid, 0xFFFFFFF, "This area is free to map!");
return 1;
}

if (strcmp("/home", cmdtext, true, 10) == 0)
{
SetPlayerPos (playerid, -49.6428,-270.6409,6.6332);
SetPlayerInterior (playerid, 0);
SendClientMessage (playerid, 0xaa33331, "Welcome to Home. The place you spawned.");
SendClientMessage (playerid, 0xFFFFFFF, "This area is free to map!");
return 1;
}
return 0;




Re: Today I learned - Share your newly found knowledge! - JoBullet - 29.07.2012

Today I learned that only class-specifiers('stock','const','static','public') that cannot mix together are 'public' and 'static', thus following are all correct in any combination(Note: only one class-specifier can be defined for one declarator)
Код:
new stock const static variable;
new stock const public variable;
new stock const const static variable; // error, 'const' class-specifier defined twice for one declarator.
Today I learned that you can set native's index arbitrarily like this
Код:
native func() = -0;
This will produce following(in assembly code):
Код:
sysreq.c 0
Note that integer following equal-sign must be negative,
This is invalid:
Код:
native func() = 11; // error
Another valid example:
Код:
native func() = -123;
The native's index would now be -123


Re: Today I learned - Share your newly found knowledge! - Vince - 29.07.2012

Today I learned that the compiler implicitly includes default.inc in all scripts.


Re: Today I learned - Share your newly found knowledge! - JoBullet - 29.07.2012

Today I learned that there exists a keyword named "defined", its design is very much same as sizeof though its functionality is similar to "#if defined" pre-processor construct. "defined" keyword resolves at compile-time to constant-expression(in this case bool: tagged). Its functionality is to deduce existance of either local or global variable, function, state variable or macro.
Syntax: (parentheses are optional)
Код:
if(defined symbol)
{}
if(defined(symbol))
{}
new const symbol_exists = defined(symbol);



Re: Today I learned - Share your newly found knowledge! - Arca - 30.07.2012

Today I learned that using static to initialize variable inside a loop is much more efficient than using new.


Re: Today I learned - Share your newly found knowledge! - JoBullet - 30.07.2012

Quote:
Originally Posted by Arca
Посмотреть сообщение
Today I learned that using static to initialize variable inside a loop is much more efficient than using new.
That's untrue, static variable is a global with a visibility limited to a function within it's declared, and it has nothing to do with efficiency, put it another way:
This code:
Код:
new static variable;
is equivalent to this code:
Код:
static variable;



Re: Today I learned - Share your newly found knowledge! - JoBullet - 30.07.2012

Today I learned that pattern name is called prefix. The prefix is the part of pattern that begins at the beginning of the pattern and ends on first occurrence of non-alphabetic character.
Note: in this context alphabetic means it is member of: 'a'..'z', 'A'..'Z', '0'..'9', '@', '_'.
This is important because warning 201("redefinition of constant/macro") is issued when there are more then one equivalent PREFIXes(NOT patterns).
Код:
#define pattern substitution
#define prefix<non-alphabetic substitution
#define prefix{non-alphabetic warning 201 issued
I have also learned that trailing argument in pattern is cut off if it exists because it could match anything,
Код:
#define _X%1 whatever
actually is equivalent to
Код:
#define _X whatever