Useful Functions

pawn Код:
new day, hour, minute, second;

CountdownUntilNextMonth( day, hour, minute, second )
printf( "Countdown till next month: %d days %d hours %02d minutes and %02d seconds left", day, hour, minute, second );
pawn Код:
//Returns days-, hours-, minutes-, & seconds left until next month
    stock CountdownUntilNextMonth( &day, &hour, &minute, &second )
    {
        new year, month, days;
        getdate( year, month, day );
        gettime( hour, minute, second );
        //Fused this function with Ryder's GetDaysInMonth function, so the code you see below till dashed lines is Ryder's code
        switch( month )
        {
            case 1, 3, 5, 7, 8, 10, 12: days = 31;
            case 4, 6, 9, 11: days = 30;
            case 2: days = ( ( (!( year % 4 ) && ( year % 100 ) != 0 ) ) || !( year % 400 ) ) ? ( 29 ) : ( 28 );
        }
        //<-----------------------------------------------------By Ryder----------------------------------------------------->
        day = days-1 - day; hour = 23 - hour; minute = 59 - minute; second = 59 - second;
    }
Someone might find this useful ( e.g in December - countdown till new year )
Reply

Quote:
Originally Posted by iMonk3y
Посмотреть сообщение
pawn Код:
day = floatround( floatsqroot( ( days - day ) * ( days - day ) ) );
hour = floatround( floatsqroot( ( 23 - hour ) * ( 23 - hour ) ) );
minute = floatround( floatsqroot( ( 59 - minute ) * ( 59 - minute ) ) );
second = floatround( floatsqroot( ( 59 - second ) * (  59 - second ) ) );
Arent they always positive without doing a square and a root ?
Reply

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Arent they always positive without doing a square and a root ?
Ops, I just realized that too silly me... thanks, I'll fix it
Reply

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
You're using a global variable for the timer and not a global player variable, hence why it would only work for the last player you started the timer on (the killtimer part, etc.).
Do I need to use MinigunCheckTimer[MAX_PLAYERS]; ?

Код:
new MinigunCheckTimer[MAX_PLAYERS];

stock AllowMinigunForPlayer(playerid, allow)
{
    if(allow) return 1;
    MinigunCheckTimer[playerid] = SetTimerEx("MinigunCheck",2000,1,"i",playerid);
    return 1;
}

public MinigunCheck(playerid)
{
    if(GetPlayerWeapon(playerid) != 38) return 1;
    BanEx(playerid,"Minigun Cheat");
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    KillTimer(MinigunCheckTimer[playerid]);
    return 1;
}
Quote:
Originally Posted by dice7
Посмотреть сообщение
Also thats a snippet, not a fucntion.
What's the differecence between snippet and fucntion?
Reply

Quote:
Originally Posted by ******
Посмотреть сообщение
A function is a single thing which you call and which returns a value. A snippet is a small chunk of code which needs inserting in to your mode, possibly at correct positions. Your code consists of two functions ("AllowMinigunForPlayer" and "MinigunCheck") and code which needs to be placed in "OnPlayerDeath", thus it is a snippet.
"A function is a single thing"
That doesn't make sence.
Its not just single because in a function you can put
CallRemoteFunction and that won't make it single and btw its "this"
You putted thus. Speeling fail. Bah its ok. I spell fail sometimes.
Reply

Quote:
Originally Posted by TheAlienForce
Посмотреть сообщение
"A function is a single thing"
That doesn't make sence.
Its not just single because in a function you can put
CallRemoteFunction and that won't make it single and btw its "this"
You putted thus. Speeling fail. Bah its ok. I spell fail sometimes.
He spelled correctly, unlike you.

Bold = typo
Italic = bad forumlated sentence.

But let's not go to far into grammar.
Reply

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
He spelled correctly, unlike you.

Bold = typo
Italic = bad forumlated sentence.

But let's not go to far into grammar.
I agree Garsino, however can i point out that all quotes come out italic
Reply

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
He spelled [it] correctly, unlike you.

Bold = typo
Italic = bad forumlated sentence.

But let's not go to far into grammar.
Right.
Reply

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
He spelled correctly, unlike you.

Bold = typo
Italic = bad forumlated sentence.

But let's not go to far into grammar.
"I spell fail sometimes."
Yeh. Right.
Gotta luv you.
So if he's right, what does thus mean?
Reply

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
He spelled correctly, unlike you.

Bold = typo
Italic = bad forumlated sentence.

But let's not go to far into grammar.
Did you mean let's not go too far into grammar?

Oh and let's not even bring up the badly formulated sentence!

Anyways,
I might aswell share these functions I wrote a while back.

pawn Код:
// Macro to create a numeric IP; ex: MAKE_NUMERIC_IP(127,0,0,1)
#define MAKE_NUMERIC_IP(%0,%1,%2,%3) \
    ( ( ( ( %0 ) << 24 ) | ( ( %1 ) << 16 ) | ( ( %2 ) << 8 ) ) | ( %3 ) )

stock GetNumericIP( const szIP[ ] ) // Converts a dot-decimal notated IP into a numeric representation.
{
    new
        aiOctets[ 4 ]
    ;
   
    sscanf( szIP, "p<.>a<i>[4]", aiOctets );
   
    return ( ( aiOctets[ 0 ] << 24 ) | ( aiOctets[ 1 ] << 16 ) | ( aiOctets[ 2 ] << 8 ) ) | aiOctets[ 3 ];
}

stock GetDotDecimalIP( iIP ) // Converts a numeric IP into a dot-decimal notation.
{
    new
        szBuffer[ 16 ]
    ;
   
    format(
        szBuffer,
        sizeof( szBuffer ),
        "%d.%d.%d.%d",
        ( iIP & ( 255 << 24 ) ) >>> 24,
        ( iIP & ( 255 << 16 ) ) >>> 16,
        ( iIP & ( 255 <<  8 ) ) >>> 8,
        ( iIP & ( 255 ) )
    );
   
    return szBuffer;
}
Reply

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Right.
Oh no, the english troll is here!

But seriously, my post was directed to the one picking on ******'s grammar while he had many more typos himself.

And before anyone of you use the "your grammar isn't the best either, so stfu" argument - I never said it was.

Also, I had a lol at all the replies on my reply. I kind off fail this week.
Reply

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
Oh no, the english troll is here!

But seriously, my post was directed to the one picking on ******'s grammar while he had many more typos himself.

And before anyone of you use the "your grammar isn't the best either, so stfu" argument - I never said it was.

Also, I had a lol at all the replies on my reply. I kind off fail this week.
Well its hard for us who live out side coutry's who dont speak english.
Like you, norway.
Me, portugal.
Reply

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
Oh no, the english troll is here!

But seriously, my post was directed to the one picking on ******'s grammar while he had many more typos himself.

And before anyone of you use the "your grammar isn't the best either, so stfu" argument - I never said it was.

Also, I had a lol at all the replies on my reply. I kind off fail this week.
Run!

I'm only kidding, but I was just primarily pointing out that you were correcting someone and your post retained grammar mistakes too, therefore it [the corrections] was slightly void.
Reply

Quote:
Originally Posted by [FeK]DraKiNs
Посмотреть сообщение
Write Text in Console
PHP код:
stock WriteTextConsole(text[])
{
    new 
samp[100],count GetTickCount();
    for(new 
atext[a]; ++a)
    {
        while(
500 GetTickCount() - count)        {        }
        print(
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
        
format(samp,100,text),samp[a] = '\0';
        print(
samp),count GetTickCount();
    }
    return 
true;

Is not big work,but is cool.
And do not call optimization

Regards and Hugs
This was the code I tested.

WriteTextConsole("yo");

Here is the result...

Код:
[20:30:34] 

























[20:30:34] (null)
[20:30:35] 

























[20:30:35] y
So, what is this first of all, and second, why is it posting a bunch of blank spaces and just the first letter?
Reply

Quote:
Originally Posted by [FeK]DraKiNs
Посмотреть сообщение
WriteTextConsole("yo ");
Oh, I didn't get it, thanks.
Reply

Wow, lots of info!
Reply

Slice, so basically a static variable is only initialized once whereas a local variable is initialized every time the server passes that bit of code?
Reply

Yeah. I suppose you could say they're local global variables.
Reply

Some useful functions related to hex colors:
pawn Код:
stock hex2rgba(hex,&r,&g,&b,&a)
{
    r = (hexColor >> 24) & 0x000000FF;
    g = (hexColor >> 16) & 0x000000FF;
    b = (hexColor >> 8) & 0x000000FF;
    a = hexColor & 0x000000FF;
}
stock IntToHex(num)
{
    new ret[3];
    switch(num)
    {
        case 0: ret = "00";
        case 1: ret = "01";
        case 2: ret = "02";
        case 3: ret = "03";
        case 4: ret = "04";
        case 5: ret = "05";
        case 6: ret = "06";
        case 7: ret = "07";
        case 8: ret = "08";
        case 9: ret = "09";
        case 10: ret = "0A";
        case 11: ret = "0B";
        case 12: ret = "0C";
        case 13: ret = "0D";
        case 14: ret = "0E";
        case 15: ret = "0F";
        case 16: ret = "10";
        case 17: ret = "11";
        case 18: ret = "12";
        case 19: ret = "13";
        case 20: ret = "14";
        case 21: ret = "15";
        case 22: ret = "16";
        case 23: ret = "17";
        case 24: ret = "18";
        case 25: ret = "19";
        case 26: ret = "1A";
        case 27: ret = "1B";
        case 28: ret = "1C";
        case 29: ret = "1D";
        case 30: ret = "1E";
        case 31: ret = "1F";
        case 32: ret = "20";
        case 33: ret = "21";
        case 34: ret = "22";
        case 35: ret = "23";
        case 36: ret = "24";
        case 37: ret = "25";
        case 38: ret = "26";
        case 39: ret = "27";
        case 40: ret = "28";
        case 41: ret = "29";
        case 42: ret = "2A";
        case 43: ret = "2B";
        case 44: ret = "2C";
        case 45: ret = "2D";
        case 46: ret = "2E";
        case 47: ret = "2F";
        case 48: ret = "30";
        case 49: ret = "31";
        case 50: ret = "32";
        case 51: ret = "33";
        case 52: ret = "34";
        case 53: ret = "35";
        case 54: ret = "36";
        case 55: ret = "37";
        case 56: ret = "38";
        case 57: ret = "39";
        case 58: ret = "3A";
        case 59: ret = "3B";
        case 60: ret = "3C";
        case 61: ret = "3D";
        case 62: ret = "3E";
        case 63: ret = "3F";
        case 64: ret = "40";
        case 65: ret = "41";
        case 66: ret = "42";
        case 67: ret = "43";
        case 68: ret = "44";
        case 69: ret = "45";
        case 70: ret = "46";
        case 71: ret = "47";
        case 72: ret = "48";
        case 73: ret = "49";
        case 74: ret = "4A";
        case 75: ret = "4B";
        case 76: ret = "4C";
        case 77: ret = "4D";
        case 78: ret = "4E";
        case 79: ret = "4F";
        case 80: ret = "50";
        case 81: ret = "51";
        case 82: ret = "52";
        case 83: ret = "53";
        case 84: ret = "54";
        case 85: ret = "55";
        case 86: ret = "56";
        case 87: ret = "57";
        case 88: ret = "58";
        case 89: ret = "59";
        case 90: ret = "5A";
        case 91: ret = "5B";
        case 92: ret = "5C";
        case 93: ret = "5D";
        case 94: ret = "5E";
        case 95: ret = "5F";
        case 96: ret = "60";
        case 97: ret = "61";
        case 98: ret = "62";
        case 99: ret = "63";
        case 100: ret = "64";
        case 101: ret = "65";
        case 102: ret = "66";
        case 103: ret = "67";
        case 104: ret = "68";
        case 105: ret = "69";
        case 106: ret = "6A";
        case 107: ret = "6B";
        case 108: ret = "6C";
        case 109: ret = "6D";
        case 110: ret = "6E";
        case 111: ret = "6F";
        case 112: ret = "70";
        case 113: ret = "71";
        case 114: ret = "72";
        case 115: ret = "73";
        case 116: ret = "74";
        case 117: ret = "75";
        case 118: ret = "76";
        case 119: ret = "77";
        case 120: ret = "78";
        case 121: ret = "79";
        case 122: ret = "7A";
        case 123: ret = "7B";
        case 124: ret = "7C";
        case 125: ret = "7D";
        case 126: ret = "7E";
        case 127: ret = "7F";
        case 128: ret = "80";
        case 129: ret = "81";
        case 130: ret = "82";
        case 131: ret = "83";
        case 132: ret = "84";
        case 133: ret = "85";
        case 134: ret = "86";
        case 135: ret = "87";
        case 136: ret = "88";
        case 137: ret = "89";
        case 138: ret = "8A";
        case 139: ret = "8B";
        case 140: ret = "8C";
        case 141: ret = "8D";
        case 142: ret = "8E";
        case 143: ret = "8F";
        case 144: ret = "90";
        case 145: ret = "91";
        case 146: ret = "92";
        case 147: ret = "93";
        case 148: ret = "94";
        case 149: ret = "95";
        case 150: ret = "96";
        case 151: ret = "97";
        case 152: ret = "98";
        case 153: ret = "99";
        case 154: ret = "9A";
        case 155: ret = "9B";
        case 156: ret = "9C";
        case 157: ret = "9D";
        case 158: ret = "9E";
        case 159: ret = "9F";
        case 160: ret = "A0";
        case 161: ret = "A1";
        case 162: ret = "A2";
        case 163: ret = "A3";
        case 164: ret = "A4";
        case 165: ret = "A5";
        case 166: ret = "A6";
        case 167: ret = "A7";
        case 168: ret = "A8";
        case 169: ret = "A9";
        case 170: ret = "AA";
        case 171: ret = "AB";
        case 172: ret = "AC";
        case 173: ret = "AD";
        case 174: ret = "AE";
        case 175: ret = "AF";
        case 176: ret = "B0";
        case 177: ret = "B1";
        case 178: ret = "B2";
        case 179: ret = "B3";
        case 180: ret = "B4";
        case 181: ret = "B5";
        case 182: ret = "B6";
        case 183: ret = "B7";
        case 184: ret = "B8";
        case 185: ret = "B9";
        case 186: ret = "BA";
        case 187: ret = "BB";
        case 188: ret = "BC";
        case 189: ret = "BD";
        case 190: ret = "BE";
        case 191: ret = "BF";
        case 192: ret = "C0";
        case 193: ret = "C1";
        case 194: ret = "C2";
        case 195: ret = "C3";
        case 196: ret = "C4";
        case 197: ret = "C5";
        case 198: ret = "C6";
        case 199: ret = "C7";
        case 200: ret = "C8";
        case 201: ret = "C9";
        case 202: ret = "CA";
        case 203: ret = "CB";
        case 204: ret = "CC";
        case 205: ret = "CD";
        case 206: ret = "CE";
        case 207: ret = "CF";
        case 208: ret = "D0";
        case 209: ret = "D1";
        case 210: ret = "D2";
        case 211: ret = "D3";
        case 212: ret = "D4";
        case 213: ret = "D5";
        case 214: ret = "D6";
        case 215: ret = "D7";
        case 216: ret = "D8";
        case 217: ret = "D9";
        case 218: ret = "DA";
        case 219: ret = "DB";
        case 220: ret = "DC";
        case 221: ret = "DD";
        case 222: ret = "DE";
        case 223: ret = "DF";
        case 224: ret = "E0";
        case 225: ret = "E1";
        case 226: ret = "E2";
        case 227: ret = "E3";
        case 228: ret = "E4";
        case 229: ret = "E5";
        case 230: ret = "E6";
        case 231: ret = "E7";
        case 232: ret = "E8";
        case 233: ret = "E9";
        case 234: ret = "EA";
        case 235: ret = "EB";
        case 236: ret = "EC";
        case 237: ret = "ED";
        case 238: ret = "EE";
        case 239: ret = "EF";
        case 240: ret = "F0";
        case 241: ret = "F1";
        case 242: ret = "F2";
        case 243: ret = "F3";
        case 244: ret = "F4";
        case 245: ret = "F5";
        case 246: ret = "F6";
        case 247: ret = "F7";
        case 248: ret = "F8";
        case 249: ret = "F9";
        case 250: ret = "FA";
        case 251: ret = "FB";
        case 252: ret = "FC";
        case 253: ret = "FD";
        case 254: ret = "FE";
        case 255: ret = "FF";
    }
    return ret;
}
Reply

@Amit_B:
You can also make that second function (IntToHex) on a much easier and shorter way (using format).

EDIT: Ah, I didn't see the post above.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)