02.03.2012, 10:19
DarkScripter, remove the space in the macro and consider adding brackets.
Some time ago I was searching for convert timestamp to date and the only way that I found was use a plugin.
I found this on Pawn source, I think that it can be useful to someone else(be aware of your time zone). pawn Код:
|
stock SendFormatMessage(const iPlayer, const iColor, const szFormat[], { Float, _ }: ...) {
new
iArgs = (numargs() - 3) << 2
;
if(iArgs) {
static
s_szBuf[144],
s_iAddr1,
s_iAddr2
;
#emit ADDR.PRI szFormat
#emit STOR.PRI s_iAddr1
for(s_iAddr2 = s_iAddr1 + iArgs, iArgs += 12; s_iAddr2 != s_iAddr1; s_iAddr2 -= 4) {
#emit LOAD.PRI s_iAddr2
#emit LOAD.I
#emit PUSH.PRI
}
#emit CONST.PRI s_szBuf
#emit PUSH.S szFormat
#emit PUSH.C 144
#emit PUSH.PRI
#emit PUSH.S iArgs
#emit SYSREQ.C format
#emit LCTRL 4
#emit LOAD.S.ALT iArgs
#emit ADD.C 4
#emit ADD
#emit SCTRL 4
return (iPlayer != -1) ? SendClientMessage(iPlayer, iColor, s_szBuf) : SendClientMessageToAll(iColor, s_szBuf);
}
return (iPlayer != -1) ? SendClientMessage(iPlayer, iColor, szFormat) : SendClientMessageToAll(iColor, szFormat);
}
Here's my own version of SendFormatMessage:
pawn Код:
|
stock DoesPlayerHaveWeapon(playerid, weaponid)
{
new Gun[13];
new Ammo[13];
for(new i=0; i<13; i++)
{
GetPlayerWeaponData(playerid, i, Gun[i], Ammo[i]);
if(Gun[i] == weaponid)
{
return true;
}
}
return false;
}
Actually, that code uses a little trick in that the pre-processor doesn't limit the number of parameters:
pawn Код:
|
stock RemovePlayerWeapon(playerid, ...)
{
new iArgs = numargs();
while(--iArgs)
{
SetPlayerAmmo(playerid, getarg(iArgs), 0);
}
}
stock OddOrEven( _num_ ) { if( ( 1 & ( _num_ ) ) == 1 ) return 1; else return 0; }
if(OddOrEven(17) == 1) { printf("17 is an odd number"); } else printf("Number 17 is even");
stock UpdateTextDraw(Text: textid, str[], player = -1)
{
TextDrawSetString(textid, str);
return player != -1 ? TextDrawShowForPlayer(player, textid) : TextDrawShowForAll(textid);
}
stock ShiftRGBAToABGR(&color)
{
new r, g, b, a;
r = (color >>> 24);
g = (color >>> 16 & 0xFF);
b = (color >>> 8 & 0xFF);
a = (color & 0xFF);
color = (a & 0xFF) | ((b & 0xFF) << 8) | ((g & 0xFF) << 16) | (r << 24);
return color;
}