Today I learned - Share your newly found knowledge!

Today, I've learned that you can use "strunpack" as opposed to "format" to copy strings:

pawn Code:
new
    str[13];

strunpack(str, "Hello there!");
I've not yet found any abnormalities or issues (I've tested smaller cells and bigger outputs), but it's significantly faster than using "format".
Reply

TIL GetPlayerTime is just a server-sided value meaning:

pawn Code:
public OnPlayerSpawn(playerid) {
    SetPlayerTime(playerid, 7, 0);
    TogglePlayerClock(playerid, 1);
   
    SetTimerEx("ClockUpdate", 5000, 0, "d", playerid);
}

forward ClockUpdate(playerid);
public ClockUpdate(playerid) {
    new hour, minute;
    GetPlayerTime(playerid, hour, minute);
    printf("%02d:%02d", hour, minute);
}
if the user is using a speedhack (via cheat engine for example) it will return an increase of only 5 seconds no matter what even if your time is completely different on client-side.

Reply

Today, I learned that you can access the index of a returned string from a function!

pawn Code:
stock returnString() {
    static str[24];
   
    str = "Hello there!";
   
    return str;
}

public OnFilterScriptInit() {
    print((returnString())[1]);
}
Prints:

Code:
ello there!
Reply

Today I Learned that there is no plugin or support for casinos! Would be great if someone made something like this, could be useful for roleplay servers.
Reply

Today I learned that you can actually pass "inline" arrays to functions;
pawn Code:
if(in_array(GetPlayerWeapon(playerid), {22,26,28,29,30,31,32}))
{
    printf("stuff");
}
else
{
    printf("no stuff");
}
pawn Code:
in_array(needle, const haystack[], size = sizeof haystack)
{
    for(new i; i < size; i++)
        if(haystack[i] == needle) return true;
       
    return false;
}
Reply

Warning: bit off topic


Quote:
Originally Posted by Slice
View Post
Today I learned that the anti-DoS timeout issues can be fixed by constantly unbanning the IP of a player experiencing problems.

Obviously a pretty bad solution, but it's better than nothing.
out of curiosity can this also fix the reconnect issues on test servers when restarting/gmxing? (with fixes2 plugin maybe? - since OnPlayerConnect is never called, and only that "incoming connection..."). since 0.3z, it seems as though kye "whitelisted" 127.0.0.1. you don't get that message only if your hosting the server, but when I need to test with more than 1 PC that obviously doesn't work (why is 192.168.*.* not whitelisted?) more-over, I thought this was "increased connection security to sa-mp servers against cheaters" when it was first added, but yet, the cheaters have long bypassed it so why is it not removed all together since it's just causing problems on test servers?
Reply

Sorry to bump this topic, but i don't think last post is old enough.

Today i learned that i can just simply use return on function for a true/false statement.
Example:
pawn Code:
IsValidSkin(skinid) // For 0.3d RC5 and upper!
{
    if(skinid >= 0 && skinid <= 299 && skinid != 74)
    {
        return true;
    }
    return false;
}
can be also written like:
pawn Code:
IsValidSkin(skinid)  // For 0.3d RC5 and upper!
    return (0 <= skinid <= 299 && skinid != 74);
Reply

New function i know its in the pawno
pawn Code:
GetPlayerID()
Reply

Learned some "new File:...." stuff thanks to Konstantinos
(Checking for strings/parts-or something close to that- and other stuff xd)
Reply

Today I learned that INVALID_PLAYER_ID holds a single integer value.
Reply

Quote:
Originally Posted by TomatoRage
View Post
New function i know its in the pawno
pawn Code:
GetPlayerID()
ah no its not? i think this is a custom function its an include not default function
Reply

Quote:
Originally Posted by AssMunchingFool
View Post
ah no its not? i think this is a custom function its an include not default function
I didn't include anything new and the function worked fine
Reply

Quote:
Originally Posted by TomatoRage
View Post
I didn't include anything new and the function worked fine
no idea how that even worked without include cuz i am quite sure there is no native function like that exist unless you create a function in your gamemode/fs itself or it is included through other includes (non samp package ones).

Even wiki says: https://sampwiki.blast.hk/wiki/GetPlayerID , that - "Important Note: This is a custom function, which can be found in Useful_Functions." which clears it doesnt exist by default anyway.



Quote:
Originally Posted by Robo_N1X
View Post
Sorry to bump this topic, but i don't think last post is old enough.
lol , otherwise too there should be no problem in bumping a thread like this :P
Reply

Recently I learned this

pawn Code:
// I define some values as the powers of 2
#define A 1 // 2^0
#define B 2 // 2^1
#define C 4 // 2^2
#define D 8 // 2^3
#define E 16 // 2^4
#define F 32 // 2^5
#define G 64 // 2^6
#define H 128 // 2^7
#define I 256 // 2^8

// the variable can be one of those values
variable = D;

// but the variable can also be multiple values
variable = F + H; //  = 32 + 128 = 160, and there are no other sums of those values that equal 160
variable = A + F + E + H;

// you can check if the variable equals one of the values
if(variable == I)

// you can also check if the variable is the sum of more of these values
if(variable == T + H + C)

// and finally you can also check if the variable's value has one of the values as addend
if(variable & I)
if(variable & B && variable & D)
I think that's very useful, learn and use it (y)
Reply

So you learned binary?
Reply

Quote:
Originally Posted by Y_Less
View Post
So you learned binary?
I thought binary was 0's and 1's?
Reply

binary IS bits. and he's using the bit operations.

binary is 1's and 0's. bit's are 1's and 0's as well.
Reply

Binary is a numerical system based on base-2, bits are a method of storing data, data that is often binary numbers.
Reply

Today I learned Y_Less is not in-fact a robot. Put this in your signature if you thought he was a robot!

NOTICE: Please don't give me an infraction for this! Cheers!
Reply

No, the correct term is "cyborg".
Reply


Forum Jump:


Users browsing this thread: 9 Guest(s)