Today I learned - Share your newly found knowledge!
#41

Today I learned that while(cond) and for(; cond; ) are running with exactly the same speed, and thus probably compile to the same amx instructions. (would be strange if they wouldnt)
Reply
#42

Today I learned I can use
pawn Код:
new RandomVar[][128]
{
"Some string",
"Some string",
"Some string",
"Some string"
};
Instead of
pawn Код:
new RandomVar[4][128]
{
"Some string",
"Some string",
"Some string",
"Some string"
};
Reply
#43

Today I learned that the strcat function is much more faster than the format function.
Reply
#44

Quote:
Originally Posted by Xenoyia
Посмотреть сообщение
not enough to merit converting a 200 command script to it.
I converted a ravens rp edit (~650 commands) to zcmd and it was worth it.


OT: Today i learned when using optional strings in SSCANF you must tell the script they are empty to avoid warnings in your console

PHP код:
new forcedparam[24],optionalparam[24];
if(
sscanf(params"s[24],S[24]()",forcedparamoptionalparam)) 
Reply
#45

Today I learned that indentation doesn't matter while defining variables.

For example, you can do:

pawn Код:
new bool: IsAMoron [ MAX_PLAYERS ],
OtherVariable;
and..

pawn Код:
new
                  OtherVariable,
    bool:         IsAMoron [ MAX_PLAYERS ] = false;
Reply
#46

Today I learnt that Include Foreach is case sensitive.

Like -

As I love to keep my scripts clean I write my every piece of code in this manner -

pawn Код:
new LawlVar [ MAX_PLAYERS ] ;
LawlVar [ playerid ] = 1 ;
if ( LawlVar [ playerid ] == 1 )
{
...
}
So if we do the same for the foreach -

pawn Код:
foreach ( new i : Player )
{
...
}
Surprisingly it shows some sort of errors.
Reply
#47

Today I learned about gettime(); now i find how 'powerfull' is this function
Reply
#48

Today i learnt that there is a function known as AttachObjectToVehicle
Reply
#49

Today i learnt that the variable length doesn't mean much
pawn Код:
new aaaaaaaaaaaaaaaaaaaaaaaaa;
is only slower by some picoseconds than
pawn Код:
new a;
Reply
#50

Today i learnt that i can use named parameters instead of ordered parameters, which is more cool and readable than the ordered style.

E.g you have a teleport function:
pawn Код:
stock Teleport(playerid, Float:x, Float:y, Float:z, Int = -1, VW = -1)
{
  some code...
}
If you use the old style you have to write all parameters:
pawn Код:
Teleport(playerid, 1.0, 2.0, 3.0, -1, 5);
But with named, you dont have to write the 4th parameter:
pawn Код:
Teleport(playerid, 1.0, 2.0, 3.0, .VW = 5);
I think many developer will use this :P
Reply
#51

Quote:
Originally Posted by thefatshizms
View Post
Today i learned:
How to use the ternary operator. I knew it already in php but before was unsure if it worked in pawn.
Quote:
Originally Posted by dr.lozer
View Post
Today i Learned that how to make a full admin sys
Did you bother to read the first post?
Reply
#52

Today i learned how to check via SAMP Script that a SQLite Database exists with in the opened database.

This is how you can do it , custom function.

pawn Code:
stock IsSQLiteDatabaseExists(dbname[])
{
    format(query,sizeof(query),"SELECT * FROM `%s` LIMIT 1",dbname);
    if(!db_query(DB: database, query)) return 0; else return 1;
}
Usage of the function!

pawn Code:
if(!IsSQLiteDatabaseExists("SAMP"))
    {
              printf("[SQLite] SAMP Table does not exists , Creating one...  Created Successfully!");
    }
//Note: You must have opened have declared the dbname as "database" or you change the dbname used in the above function which is opened by the script and operations are done on it.
Reply
#53

Today I learned that even if you use "return 0;" in OnPlayerSpawn,OnPlayerConnect etc in all scripts you use, it still wont be called if you have used SendRconCommand("loadfs FSname"); in the main gamemode eg. OnGameModeInit, after you add the same FS in server.cfg file it gets called as need.

Also FS dont change loaded filterscipts order, example: if you got FS1,FS2.. and reload FS1, it wont become FS3, nothing much but its good to know, because if you use rcon to reload your fs what is in the server.cfg, that thing what I said above about what I leanred still works, even if you have used SendRconCommand("loadfs FS1"); with a custom cmd in your gamemode.
Reply
#54

Today I learned (more realised) that you can do:

pawn Code:
stock const STR[] = "hi";

main()
{
    if (strcmp(STR, OTHER_STRING, false, sizeof (STR) - 1) {}
}
Instead of:

pawn Code:
main()
{
    if (strcmp("hi", OTHER_STRING, false, 2) {}
}
Or the more stupid:

pawn Code:
main()
{
    if (strcmp("hi", OTHER_STRING, false, strlen("hi")) {}
}
That way you get the compiler to do the lengths for you (assuming of course that you want the length - this is just one example) instead of miscounting or forgetting to update it. I've also previously written about why using "stock const"s are better than straight string literals here:

https://sampforum.blast.hk/showthread.php?tid=216730

So this is just an added bonus.
Reply
#55

Today I learned you can have (almost) arbitrary placed numeric placeholders(they are skipped while parsing though):
All of these are valid:
Code:
0b_10_1
0x_1DEAD
1_3_4_5
1_2.1_e-4
And as a added bonus, here's (pseudo) yacc grammar for these:
Code:
digit: [0-9]
hex: [a-fA-f0-9]
boolean: 0b[01_]+
integer: {digit}({digit}|_)*
hexadec: ({digit}|(0x)?)({hex} | '_')*
float: {digit}({digit} | '_')*\.{digit}({digit} | '_')*(e(-)?{digit}*)?
Reply
#56

Today i learned that you can check var multiply times, like this:
Code:
if ('0' <= string[0] <= '9')
(SSCANF2 Y_Less)
Reply
#57

Today I learned that you can load any amx file from any SAMP directory, or even custom ones

use "loadfs ../gamemodes/YourGmName" and you can load your own gamemode again or even reload it ofc it will crash the server :P

but thing what wont crash and could be handy is "loadfs ../CustomFolderName/YourFS" and it will load it same as from filterscripts folder
Reply
#58

Today I learned how to add strings!
pawn Код:
CMD:kill(playerid,params[])
{
    SetPlayerHealth(playerid,0.0);
    SendClientMessage(playerid, 0xFFFF0000, "Stupid, why did you commit suicide!?");
    new name[MAX_PLAYER_NAME],string[128];
    GetPlayerName(playerid, name, sizeof(name));
    format (string, sizeof(string), "%s has suicided.", name);
    SendClientMessageToAll(0xFB0000AA, string);
    return 1;
}
Reply
#59

Today i learned ... That GetPlayerFPS is not a function. You have to stock it with drunk level
Reply
#60

Today I learned how to use strcat, example:
pawn Код:
CMD:cmds(playerid,params[])
{
    new string[1024];
    new longstring[1024];
    format(string, sizeof(string),"/kill - Suicide\n/car - Spawns a car\n/tcar - Spawns a pre-tuned car\n/fix - Fix a car\n/nos - Add nitrous on your car\n");
    strcat(longstring,string,sizeof(longstring));
    format(string, sizeof(string),"/xnos - Remove nitrous from your car\n/godcar - Make the car god\n/teles - Teleports\n/updates - Check the current update\n/website - Our forum!\n");
    strcat(longstring,string,sizeof(longstring));
    format(string, sizeof(string),"/gps - Find the player\n/setmytime - Set your time\n/radio - Play radio\n/music - Play music\n/stop - Stop everything that you're playing\n");
    strcat(longstring,string,sizeof(longstring));
    format(string, sizeof(string),"/pc  - Parachute\n/respawn - Respawn\n/antifall - Toggle Antifall\n/autofix - Toggle Autofix\n/god - Toggle GodMode");
    strcat(longstring,string,sizeof(longstring));
    ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, "Commands", longstring, "OK", "");
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)