you sure it is made by you?...
heres a code that i found on my server pawn Код:
|
R << 24 G << 16 B << 8 A
R * 16777216 G * 65536 B * 256 A
R << 24 = R * 2^24 = R * 16777216 //and G << 16 = G * 2^16 = G * 65536 //and B << 8 = B * 2^8 = 256
(100 * 16777216) + (0 * 65536) + (255 * 256) + 0 //alpha is out of the picture for now //which equals 1677721600 + 0 + 65280 + 0 //which equals 1677786880 //which is correct
0b01100100000000000000000000000000 //31,30, and 27 turned on (1677721600) + 0 + 0b00000000000000001111111100000000 //9-16 bits turned on (65280) + 0 = 0b01100100000000001111111100000000 //which is (1677786880)
good but even DracoBlue released a HexToInt function in his DUtils (ofc it contains other useful functions)
But with his function you can insert strings pawn Код:
|
Oh lol, sorry about that but you never said that the color is notated in decimal (only that crap with the command)
|
And such a /color command is still useless, if rly needed than make something like the RGBA CONVERTER you posted in game
|
And simplify your RGBAToInt function, calculation with large numbers takes longer than with small numbers (although its not much)
|
Yes i am sure, however i know im not the first by any means. There are tons of implementations floating around. Just so you dont think i am trolling, i will explain it. First, i would like to explain that the RGBAToInt1 is pretty much the same as RGBAToInt2 (all of them are really), the only difference is it doesnt use the binary operators.
Lets take a look at both Код:
R << 24 G << 16 B << 8 A Код:
R * 16777216 G * 65536 B * 256 A Код:
R << 24 = R * 2^24 = R * 16777216 //and G << 16 = G * 2^16 = G * 65536 //and B << 8 = B * 2^8 = 256 Код:
(100 * 16777216) + (0 * 65536) + (255 * 256) + 0 //alpha is out of the picture for now //which equals 1677721600 + 0 + 65280 + 0 //which equals 1677786880 //which is correct Код:
0b01100100000000000000000000000000 //31,30, and 27 turned on (1677721600) + 0 + 0b00000000000000001111111100000000 //9-16 bits turned on (65280) + 0 = 0b01100100000000001111111100000000 //which is (1677786880) 01100100000000001111111100000000 if you convert those binary values, you'll get the original results (red=100,green=0,blue=255,alpha=0).Thats pretty much all there is to this really. If your wondering "why 8bit?" its because the color depth we are using is 8bit. There are higher options for color depth, but we cant store them all in pawn (work out r=255 g=255 b=255 a=255 and you'll see why). I can go into a bit more detail, but i think its best to keep it simple (dont want a mile long post here). That has nothing to do with my defines at all lol, i guess you dont get it :\. |
stock TicksConvert(ticks) { new d, h, m, s, ms; d = ticks/86400000; h = ticks/3600000 % 24; m = ticks/60000 % 60; s = ticks/1000 % 60; ms = ticks % 1000; new str[128]; format(str, 128, "%d days, %d hours, %d minutes, %d seconds, %d milliseconds", d, h, m, s, ms); // format(str, 128, "%d:%02d:%03d", m, s, ms); // format(str, 128, "%d mins, %d secs, %d msecs", m, s, ms); return str; }
stock TicksConvert(ticks) { new str[128]; format(str, 128, "%d:%02d:%03d", ticks/60000 % 60, ticks/1000 % 60, ticks % 1000); return str; }
forward IsPlayerInAnyPlane(playerid);
public IsPlayerInAnyPlane(playerid) {
if(IsPlayerInAnyVehicle(playerid)) {
new FXF_vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));
if(FXF_vehicle == 460 || FXF_vehicle == 476 || FXF_vehicle == 511 || FXF_vehicle == 512 || FXF_vehicle == 513 || FXF_vehicle == 519 || FXF_vehicle == 520 || FXF_vehicle == 553 || FXF_vehicle == 577 || FXF_vehicle == 592 || FXF_vehicle == 593) {
return 1; } }
return 0; }
forward IsPlayerInAnyHelicopter(playerid);
public IsPlayerInAnyHelicopter(playerid) {
if(IsPlayerInAnyVehicle(playerid)) {
new FXF_vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));
if(FXF_vehicle == 417 || FXF_vehicle == 425 || FXF_vehicle == 447 || FXF_vehicle == 469 || FXF_vehicle == 487 || FXF_vehicle == 488 || FXF_vehicle == 497 || FXF_vehicle == 548 || FXF_vehicle == 563) {
return 1; } }
return 0; }
forward IsPlayerOnAnyBoat(playerid);
public IsPlayerOnAnyBoat(playerid) {
if(IsPlayerInAnyVehicle(playerid)) {
new FXF_vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));
if(FXF_vehicle == 430 || FXF_vehicle == 446 || FXF_vehicle == 452 || FXF_vehicle == 453 || FXF_vehicle == 454 || FXF_vehicle == 472 || FXF_vehicle == 473 || FXF_vehicle == 484 || FXF_vehicle == 493 || FXF_vehicle == 595) {
return 1; } }
return 0; }
forward IsPlayerOnAnyBike(playerid);
public IsPlayerOnAnyBike(playerid) {
if(IsPlayerInAnyVehicle(playerid)) {
new FXF_vehicle = GetVehicleModel(GetPlayerVehicleID(playerid));
if(FXF_vehicle == 448 || FXF_vehicle == 461 || FXF_vehicle == 462 || FXF_vehicle == 463 || FXF_vehicle == 468 || FXF_vehicle == 471 || FXF_vehicle == 481 || FXF_vehicle == 409 || FXF_vehicle == 510 || FXF_vehicle == 521 || FXF_vehicle == 522 || FXF_vehicle == 523 || FXF_vehicle == 581 || FXF_vehicle == 586) {
return 1; } }
return 0; }
Easiest, shortest and fastest ticks converter that I was able to make, for races of whatever else you need.
Код:
stock TicksConvert(ticks) { new d, h, m, s, ms; d = ticks/86400000; h = ticks/3600000 % 24; m = ticks/60000 % 60; s = ticks/1000 % 60; ms = ticks % 1000; new str[128]; format(str, 128, "%d days, %d hours, %d minutes, %d seconds, %d milliseconds", d, h, m, s, ms); // format(str, 128, "%d:%02d:%03d", m, s, ms); // format(str, 128, "%d mins, %d secs, %d msecs", m, s, ms); return str; } Код:
stock TicksConvert(ticks) { new str[128]; format(str, 128, "%d:%02d:%03d", ticks/60000 % 60, ticks/1000 % 60, ticks % 1000); return str; } |
stock toUpper(c)
{
return ('a' <= c <= 'z') ? (c += 'A' - 'a') : (c);
}
stock isCharUpper(c)
{
return ('A' <= c <= 'Z');
}
stock toLower(c)
{
return ('A' <= c <= 'Z') ? (c += 'a' - 'A') : (c);
}
stock isCharLower(c)
{
return ('a' <= c <= 'z');
}
Nicely done, though I think it's already made.
But oh well, good effort anyway ![]() |
#define IntToRGBA(%0,%1,%2,%3,%4) \
(%1) = ((%0) >>> 24); (%2) = (((%0) >>> 16) & 0xFF); (%3) = (((%0) >>> 8) & 0xFF); (%4) = ((%0) & 0xFF)
#define IntToRGBA(%0,%1,%2,%3,%4) \
(%1) = ((%0) >>> 24); (%2) = (((%0) >>> 16) & 0xFF); (%3) = (((%0) >>> 8) & 0xFF); (%4) = ((%0) & 0xFF)
#define IntToRGBA2(%0,%1,%2,%3,%4) \
(%1) = ((%0) >>> 24); (%2) = (((%0) << 8) >>> 24); (%3) = (((%0) << 16) >>> 24); (%4) = (((%0) << 24) >>> 24)
#define IntToRGBA3(%0,%1,%2,%3,%4) \
(%1) = ((%0) >>> 24); (%2) = (((%0) * 256) >>> 24); (%3) = (((%0) * 65536) >>> 24); (%4) = (((%0) * 16777216) >>> 24)
IntToRGBA(1): R:28 || G:28 || B:81 || A:6 || Time: 4199ms
IntToRGBA(2): R:28 || G:28 || B:81 || A:6 || Time: 4332ms
IntToRGBA(3): R:28 || G:28 || B:81 || A:6 || Time: 4357ms
IntToRGBA(1): R:93 || G:173 || B:182 || A:3 || Time: 4147ms
IntToRGBA(2): R:93 || G:173 || B:182 || A:3 || Time: 4300ms
IntToRGBA(3): R:93 || G:173 || B:182 || A:3 || Time: 4310ms
#define toupper(%0) \
(((%0) >= 'a' && (%0) <= 'z') ? ((%0) & ~0x20) : (%0))
#define tolower(%0) \
(((%0) >= 'A' && (%0) <= 'Z') ? ((%0) | 0x20) : (%0))
Here are a few simple functions I want to share:
toUpper This function already exist but if someone wants the function here you go: pawn Код:
Returns true if the char is in upper case; otherwise false. pawn Код:
Same as toUpper. pawn Код:
Returns true if the char is in lower case; otherwise false. pawn Код:
|
Originally posted by core.inc native tolower©; native toupper©; |
#define rotx 1 #define roty 2 #define rotz 3 forward RotateObject(objectid, axis, Float:extent, Float:rspeed);
public RotateObject(objectid, axis, Float:extent, Float:rspeed) { if (rspeed <= 0.0) return 1; if ((extent > 0.0) && (extent < rspeed/10)) rspeed = extent*10; if ((extent < 0.0) && (extent > -rspeed/10)) rspeed = -extent*10; if (extent == 0.0) return 1; new Float:rx, Float:ry, Float:rz; GetObjectRot(objectid, rx, ry, rz); switch (axis) { case rotx: SetObjectRot(objectid, rx + ((extent > 0.0) ? (rspeed/10) : (-rspeed/10)), ry, rz); case roty: SetObjectRot(objectid, rx, ry + ((extent > 0.0) ? (rspeed/10) : (-rspeed/10)), rz); case rotz: SetObjectRot(objectid, rx, ry, rz + ((extent > 0.0) ? (rspeed/10) : (-rspeed/10))); } SetTimerEx("RotateObject", 10, 0, "ddff", objectid, axis, ((extent > 0.0) ? (extent - rspeed/10) : (extent + rspeed/10)), rspeed); return 1; }
new policebar;
policebar = CreateObject(...);
if (!strcmp(cmdtext, "/openbar", true)) { RotateObject(policebar, rotx, 90.0, 0.5); // Just an example, not sure this values will work for the object u putted, you need to find out the correct values depending on where you placed the object. return 1; }
if (!strcmp(cmdtext, "/rot", true)) { RotateObject(objectid, rotz, -90.0, 1.0); return 1; }
if (!strcmp(cmdtext, "/rot", true)) { RotateObject(objectid, rotz, -90.0, 1.0); RotateObject(objectid, rotx, 270.0, 5.0); RotateObject(objectid, roty, -180.0, 3.5); return 1; }
if (!strcmp(cmdtext, "/rot", true)) { RotateObject(objectid, rotz, 1440.0, 5.0); // Object will spin 4 times and then stop (1440/360 = 4) return 1; }
stock fibonacci(n)
{
new fn;
if(n<1)
fn=0;
else if(n==1)
fn=1;
else
{
new f0=0,f1=1;
for(new i=2;i<=n;i++)
{
fn=f1+f0;
f0=f1;
f1=fn;
}
}
return fn;
}
stock wait(time)
{
new t1=GetTickCount();
do {}
while((GetTickCount()-t1)<time);
}