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


Today I learned - Share your newly found knowledge! - Slice - 15.07.2012

Yes, just like reddit.

Simple. If you learned something new related to SA-MP scripting, share it here!

Please: I'll start..


Today I learned the proper way to forward public functions is this:
pawn Code:
forward public OnSomethingHappen(a, b, c);
I've always done it without "public". The only difference, it seems, is it enforces some extra restrictions (such as not being able to assign default values).


Re: Today I learned - Share your newly found knowledge! - Lorenc_ - 15.07.2012

Today I learned that you can use a hash sign (#) instead of quote marks. E.G: SetPVarInt( playerid, #slice, 1 );


Re: Today I learned - Share your newly found knowledge! - CaHbKo - 15.07.2012

Today I learned, that...
Quote:
Originally Posted by Mauzen
View Post
Converting variabes "downwards" isnt a big problem btw. Just use normal cells, and if it really depends on being just 1/2 bytes long, you could do this:
cell & 0x0000FFFF (2 byte/16 bit value)
cell & 0x000000FF (1 byte/8 bit value)



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

Today I learned the compiler accepts trailing commas in enums.

pawn Code:
// Valid:
enum {
    ABC,
    DEF,
    GHI,
}



AW: Today I learned - Share your newly found knowledge! - Drebin - 17.07.2012

Today I learned that color embeddings can be defined ontop of the script.

pawn Code:
#define BLUE_EMBED "{0000FF}"
 
 
SendClientMessage(playerid, -1, "White turns into"BLUE_EMBED" blue.");



Re: Today I learned - Share your newly found knowledge! - leonardo1434 - 17.07.2012

Today I learned that strcat is 2x more fast than format and with a simple definition you can make a new model of format.


Re: Today I learned - Share your newly found knowledge! - RebeloX - 17.07.2012

Today I learned that dialogs can be defined inside the enumerator

pawn Code:
enum {
    DIALOG_1,
    DIALOG_2
};



Re: Today I learned - Share your newly found knowledge! - Ricop522 - 17.07.2012

Today I learned how to #emit


Re: Today I learned - Share your newly found knowledge! - Ironboy - 17.07.2012

Today i learned Enumerators (enums).


Re: Today I learned - Share your newly found knowledge! - Universal - 18.07.2012

Today I learned that OnGameModeExit is not being called when you shutdown the server console.


Re: Today I learned - Share your newly found knowledge! - Simon - 18.07.2012

TIL a little trick to extend the amount of statements executed in ternary statements.

Never thought about using the ',' operator this way. Group of statements must be enclosed in brackets. It's a neat little trick that might create some interesting constructs:

pawn Code:
main () {
    new bool:cond = true;
    cond ? (print("T - First"), print("T - Second")) : (print("F - First"), print("F - Second"));

    print("SWITCHING TRUTH");

    cond = false;
    cond ? (print("T - First"), print("T - Second")) : (print("F - First"), print("F - Second"));
}



Re: Today I learned - Share your newly found knowledge! - Night Dreamer - 18.07.2012

Today I learned more about bits
PHP Code:
const color = ((183)<<24|(115)<<16|(222)<<8); //purple!!!
GetPrintedRGB(color) return printf("Red: %d, Green: %d, Blue: %d", ((colorFrom >> 24) & 0xFF), ((colorFrom >> 16) & 0xFF), ((colorFrom >> 8) & 0xFF)); 



Re: Today I learned - Share your newly found knowledge! - RebeloX - 18.07.2012

Today I learned how to use #error

pawn Code:
#if !defined MAX_SLOTS
    #error You must define the MAX_SLOTS in your script
#endif



Re: Today I learned - Share your newly found knowledge! - RyDeR` - 18.07.2012

Today I learned that publics like OnPlayerText (in a filterscript) are still intact while the gamemode is restarting so you can, for example, actually still chat using Send(Player/Client)Message(ToAll)!


Re: Today I learned - Share your newly found knowledge! - admantis - 18.07.2012

Today I learned that filterscripts don't get reloaded when the servre is restarted, you have to reload the filterscripts manually.


Re: Today I learned - Share your newly found knowledge! - EV007 - 19.07.2012

Today I learned that I can use one line

pawn Code:
SetPlayerColor(playerid,(team[playerid] == team_one ) ? COLOR_RED : COLOR_BLUE );
instead of:

pawn Code:
if(team[playerid] == team_one)
{
SetPlayerColor(playerid,COLOR_RED);
}
if(team[playerid] == team_two)
{
SetPlayerColor(playerid,COLOR_BLUE);
}



Re: Today I learned - Share your newly found knowledge! - FireCat - 19.07.2012

Quote:
Originally Posted by EV007
View Post
Today I learned that I can use one line

pawn Code:
SetPlayerColor(playerid,(team[playerid] == team_one ) ? COLOR_RED : COLOR_BLUE );
instead of:

pawn Code:
if(team[playerid] == team_one)
{
SetPlayerColor(playerid,COLOR_RED);
}
if(team[playerid] == team_two)
{
SetPlayerColor(playerid,COLOR_BLUE);
}
Thats called the ternary operator


Respuesta: Today I learned - Share your newly found knowledge! - JoBullet - 19.07.2012

Today I learned that returning array from function works in such a way that array's address is stored in a following address:
current function frame address + (argcount + 3) * sizeof(cell)


Re: Today I learned - Share your newly found knowledge! - FireCat - 20.07.2012

Today I learned you can do this:
pawn Code:
enum Something
{
 hi,
 bye
}

printf("%s",Something:hi);



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

Today I learned how to make my cat speak.
Jks, Today I learned why there were # tags being used in colors. (To Encode Them)
pawn Code:
"#COL_ORANGE"
Plus, i learned that pawn will not give error if the color is defined or not if you use hash tag in color.