- Cod:
Am hotarat sa fac un topic unde sa postez cateva functii folositoare, facute de mine, dar si de alti scripteri, care va pot ajuta mult, pentru niste shit-uri pe care o sa vreti sa le faceti.
randomEx( MIN, MAX ):
Pawno Code: [Select]
//by Y_Less
stock randomEx( min, max )
return ( random( ( max - min ) ) + min );
- O functie foarte folositoare daca vreti un random de exemplu intre valoarea X si Y.
GivePlayerMultipleWeapons( playerid, ... ):
Pawno Code: [Select]
//by xxSPEEDYxx
stock GivePlayerMultipleWeapons( playerid, ... )
{
new c_args = numargs( );
for ( new i = 1; i < c_args; i += 2 )
{
if ( IsValidWeapon( getarg( i ) )
GivePlayerWeapon( playerid, getarg( i ), getarg( i + 1 ) );
else
printf( "[DEBUG]: You have inserted somewhere an invalid weapon! Weapon: %d", getarg( i ) );
}
return 1;
}
stock IsValidWeapon( weaponid )
{
if ( weaponid > 0 && weaponid < 19 || weaponid > 21 && weaponid < 47 )
return 1;
return 0;
}
- O alta functie foarte folositoare pentru ca sa nu mai aveti 10000 de linii doar de GivePlayerWeapon.
FormatMessage( playerid, color, fstring[ ], {Float, _}:... ):
Pawno Code: [Select]
//by Y_Less sau Slice
#define BYTES_PER_CELL 4
stock FormatMessage( playerid, color, fstring[ ], {Float, _}:... )
{
static const STATIC_ARGS = 3;
new n = (numargs() - STATIC_ARGS) * BYTES_PER_CELL;
if(n)
{
new message[144],arg_start,arg_end;
#emit CONST.alt fstring
#emit LCTRL 5
#emit ADD
#emit STOR.S.pri arg_start
#emit LOAD.S.alt n
#emit ADD
#emit STOR.S.pri arg_end
do
{
#emit LOAD.I
#emit PUSH.pri
arg_end -= BYTES_PER_CELL;
#emit LOAD.S.pri arg_end
}
while(arg_end > arg_start);
#emit PUSH.S fstring
#emit PUSH.C 144
#emit PUSH.ADR message
n += BYTES_PER_CELL * 3;
#emit PUSH.S n
#emit SYSREQ.C format
n += BYTES_PER_CELL;
#emit LCTRL 4
#emit LOAD.S.alt n
#emit ADD
#emit SCTRL 4
if(playerid == INVALID_PLAYER_ID)
{
#pragma unused playerid
return SendClientMessageToAll(color, message);
}
else
{
return SendClientMessage(playerid, color, message);
}
}
else
{
if(playerid == INVALID_PLAYER_ID)
{
#pragma unused playerid
return SendClientMessageToAll(color, fstring);
}
else
{
return SendClientMessage(playerid, color, fstring);
}
}
}
- O functie, care iti formateaza direct un string, fara sa ai nevoie de format.
ConvertDateAndTimeToString( ):
Pawno Code: [Select]
//by xxSPEEDYxx
stock ConvertDateAndTimeToString( )
{
new date[ 3 ], _time[ 3 ], str[ 128 ];
getdate( date[ 0 ], date[ 1 ], date[ 2 ] );
gettime( _time[ 0 ], _time[ 1 ], _time[ 2 ] );
format( str, sizeof str, "%d-%d-%d %d:%d:%d", date[ 0 ], date[ 1 ], date[ 2 ], _time[ 0 ], _time[ 1 ], _time[ 2 ] );
return str;
}
- Folositor pentru cei ce folosesc in MySQL, la cateva coloane, setarea ei, "DATETIME". Asa trebuie inserat intr-o coloana de tip "DATETIME", in formatul de mai sus: "%d-%d-%d %d:%d:%d".
HexToInt( const string[ ] ):
Pawno Code: [Select]
//Creator: I have no fucking idea =)
stock HexToInt( string[ ] )
{
if ( string[ 0 ] == 0 )
return 0;
new i, cur = 1, res = 0;
for ( i = strlen( string ); i > 0; i-- )
{
if ( string[ i - 1 ] < 58 ) res = res + cur *( string[ i - 1 ] - 48 );
else res = res + cur *( string[ i - 1 ] - 65 + 10 );
cur = cur *16;
}
return res;
}
- O functie folositoare pentru a face o culoare de tipul: '0xFFFFFFFF' intr-ul numar '123456789' de exemplu.
KickEx( playerid, const reason[ ] ):
Pawno Code: [Select]
//by xxSPEEDYxx
#define KICK_MESSAGE "%s has been kicked from the server. Reason: %s"
stock KickEx( playerid, const reason[ ] );
{
new string[ 128 ], n_Get[ MAX_PLAYER_NAME ];
GetPlayerName( playerid, n_Get, MAX_PLAYER_NAME );
if ( strlen( reason ) )
{
format( string, 128, KICK_MESSAGE, n_Get, reason );
SendClientMessage( playerid, ~1, string );
}
return SetTimerEx( "Call_KickFunction", 1000, false, "i", playerid );
}
PortalExper