Two things:
1) You just gave me -rep for the 3 digit random number code I posted a few posts back (don't forget that mods can see names). If you know a better way of writing that code I'm more than happy to hear it. I'm not bothered about the decrease itself, but if you're going to get upset about, and accuse me of something, don't have done the exact same thing yourself! 2) Whoever did -rep you (if someone claimed to be me it probably wasn't me), I fully support their decision regardless (mods can also view old post edits) - strtok is a terrible method of coding, there was a discussion about it recently in this very thread. In that case discussion didn't do much as the original function that sparked that debate is still there. Clearly your version has now gone, proving -rep as the better incentive to not post rubbish. |
stock SendClientMessageEx(playerid, color, const string[], {Float,_}:...)
{
new
temp[12],
value[128],
formatted[255],
argIndex = 3,
argCount = numargs();
strcat(formatted, string, sizeof(formatted));
for (new i = 0; i < strlen(formatted) && argIndex < argCount; i ++)
{
if (formatted[i] != '%')
continue;
else switch (formatted[i + 1])
{
case 'c', 'd', 'f', 'i':
{
strmid(temp, formatted, i, i + 2);
format(value, sizeof(value), temp, getarg(argIndex));
}
case 's':
{
for (new j, ch = 0; (ch = getarg(argIndex, j)) != '\0'; j ++) {
value[j] = ch;
if (j + 1 < sizeof(value)) value[j + 1] = '\0';
}
}
case '.', '0':
{
strmid(temp, formatted, i, i + 4);
format(value, sizeof(value), temp, getarg(argIndex));
}
default:
{
continue;
}
}
strdel(formatted, i, (formatted[i + 1] == '.' || formatted[i + 1] == '0') ? (i + 4) : (i + 2));
strins(formatted, value, i);
argIndex++;
}
return SendClientMessage(playerid, color, formatted);
}
new playername[24];
GetPlayerName(playerid, playername, sizeof(playername));
SendClientMessageEx(playerid, -1, "Hello there, %s. You have $%d money.", playername, GetPlayerMoney(playerid));
stock FindLastFreeSlot()
{
new slot = INVALID_PLAYER_ID;
for(new i = GetMaxPlayers() - 1; i != -1; i--)
{
if(IsPlayerConnected(i)) continue;
slot = i;
break;
}
return slot;
}
stock FindLastFreeSlot()
{
for(new i = GetMaxPlayers() - 1; i > -1; i--)
{
if(IsPlayerConnected(i)) continue;
return i;
}
return INVALID_PLAYER_ID; // no free slots
}
#define ConvertDays(%0) (gettime() + (86400 * (%0)))
stock ConvertToDays(n)
{
static d, h, m, s, r;
r = n-gettime();
s = r % 60, r /= 60;
m = r % 60, r /= 60;
h = r % 24, r /= 24, d = r;
static str[50];
if(d ^ 0)
{
format(str, sizeof(str), "%dd, %02dh %02dm %02ds", d, h, m, s);
return str;
}
if(h ^ 0)
{
format(str, sizeof(str), "%02dh %02dm %02ds", h, m, s);
return str;
}
format(str, sizeof(str), "%02dm %02ds", m, s);
return str;
}
bin2dec(n[]) {
static c, l, j;
c = 0;
for(l = strlen(n) - 1, j = l ; j > -1 ; j--) {
if(n[j] == '1') c += (1 << (l-j));
}
return c;
}
stock utf8encode(dest[], const source[], maxlength = sizeof(dest)) {
new len = strlen(source);
new packed = ispacked(source);
dest[0] = '\0';
new idx = 0;
for (new i = 0; i < len; i++) {
new c = packed ? source{i} : source[i];
if (c >= 0x80) {
if (c > 0x4000000) {
// 6 byte
dest[idx++] = 0b11111100 | ((c >>> 30) & 0b00000001);
dest[idx++] = 0b10000000 | ((c >>> 24) & 0b00111111);
dest[idx++] = 0b10000000 | ((c >>> 18) & 0b00111111);
dest[idx++] = 0b10000000 | ((c >>> 12) & 0b00111111);
dest[idx++] = 0b10000000 | ((c >>> 6) & 0b00111111);
dest[idx++] = 0b10000000 | (c & 0b00111111);
} else if (c > 0x200000) {
// 5 byte
dest[idx++] = 0b11111000 | ((c >>> 24) & 0b00000011);
dest[idx++] = 0b10000000 | ((c >>> 18) & 0b00111111);
dest[idx++] = 0b10000000 | ((c >>> 12) & 0b00111111);
dest[idx++] = 0b10000000 | ((c >>> 6) & 0b00111111);
dest[idx++] = 0b10000000 | (c & 0b00111111);
} else if (c > 0x10000) {
// 4 byte
dest[idx++] = 0b11110000 | ((c >>> 18) & 0b00000111);
dest[idx++] = 0b10000000 | ((c >>> 12) & 0b00111111);
dest[idx++] = 0b10000000 | ((c >>> 6) & 0b00111111);
dest[idx++] = 0b10000000 | (c & 0b00111111);
} else if (c > 0x800) {
// 3 byte
dest[idx++] = 0b11100000 | ((c >>> 12) & 0b00001111);
dest[idx++] = 0b10000000 | ((c >>> 6) & 0b00111111);
dest[idx++] = 0b10000000 | (c & 0b00111111);
} else {
// 2 byte
dest[idx++] = 0b11000000 | ((c >>> 6) & 0b00011111);
dest[idx++] = 0b10000000 | (c & 0b00111111);
}
} else if (c > 0) {
dest[idx++] = c;
}
}
dest[idx++] = '\0';
}
stock utf8decode(dest[], const source[], maxlength = sizeof(dest)) {
new len = strlen(source);
new packed = ispacked(source);
dest[0] = '\0';
new idx = 0;
for (new i = 0; i < len; i++) {
new c = source[i];
if (c & 0b10000000) {
if (c & 0b11100000 == 0b11000000) {
// 2 byte
if (i + 3 >= len) continue;
dest[idx++] = (c & 0b00011111) << 6 | (source[++i] & 0b00111111);
} else if (c & 0b11110000 == 0b11100000) {
// 3 byte
if (i + 4 >= len) continue;
dest[idx++] = (c & 0b00001111) << 12 |
(source[++i] & 0b00111111) << 6 |
(source[++i] & 0b00111111);
} else if (c & 0b11111000 == 0b11110000) {
// 4 byte
if (i + 5 >= len) continue;
dest[idx++] = (c & 0b00000111) << 18 |
(source[++i] & 0b00111111) << 12 |
(source[++i] & 0b00111111) << 6 |
(source[++i] & 0b00111111);
} else if (c & 0b11111100 == 0b11111000) {
// 5 byte
if (i + 6 >= len) continue;
dest[idx++] = (c & 0b00000011) << 24 |
(source[++i] & 0b00111111) << 18 |
(source[++i] & 0b00111111) << 12 |
(source[++i] & 0b00111111) << 6 |
(source[++i] & 0b00111111);
} else if (c & 0b11111110 == 0b11111100) {
// 6 byte
if (i + 7 >= len) continue;
dest[idx++] = (c & 0b00000001) << 30 |
(source[++i] & 0b00111111) << 24 |
(source[++i] & 0b00111111) << 18 |
(source[++i] & 0b00111111) << 12 |
(source[++i] & 0b00111111) << 6 |
(source[++i] & 0b00111111);
}
} else {
dest[idx++] = c;
}
}
dest[idx++] = 0;
}
#define doAdd%2(%0,%1) ((%0)+(%1))
#define doMul%2(%0,%1) ((%0)*(%1))
new a, b, c;
// Setting "a" and "b"
#emit CONST.pri 10
#emit STOR.S.pri a
#emit CONST.pri 20
#emit STOR.pri b
// c=a+b
#emit LOAD.S.pri a
#emit LOAD.S.alt b
#emit ADD
#emit STOR.S.pri c
new a, b, c;
// Stores "10" into "a" and "20" into "b", adds both values and stores into "c"
#emit CONST.pri 10
#emit CONST.alt 20
#emit STOR.S.pri a
#emit STOR.S.alt b
#emit ADD
#emit STOR.S.pri c
new a, b, c;
// Setting "a" and "b"
#emit CONST.pri 10
#emit STOR.S.pri a
#emit CONST.pri 20
#emit STOR.pri b
// c=a*b
#emit LOAD.S.pri a
#emit LOAD.S.alt b
#emit SMUL
#emit STOR.S.pri c
new a, b, c;
// Stores "10" into "a" and "20" into "b", multiplies both values and stores into "c"
#emit CONST.pri 10
#emit CONST.alt 20
#emit STOR.S.pri a
#emit STOR.S.alt b
#emit SMUL
#emit STOR.S.pri c
// Usage
main(){
printf("%d", hexToInt("FFFF"));
}
// Function
stock hexToInt(const szString[]) {
new
iVal = 0,
iLen = strlen(szString);
for (new x = 0; x != iLen; ++ x) {
if (szString[x] <= 57) {
iVal += (szString[x] -48)*(1 << (4*(iLen -1 -x)));
} else {
iVal += (szString[x] -55)*(1 << (4*(iLen -1 -x)));
}
}
return iVal;
}
SetAll(array[][], value = 0, size_1 = sizeof array, size_2 = sizeof array[]) {
static
x,
addr1,
addr2,
slot;
for( x = 0; x != size_2; ++x )
array[0][x] = value;
// get array
#emit load.s.pri array
// move to pri -> alt
#emit move.alt
// load in pri first idx of array
#emit load.i
// add pri with alt
#emit add
// stor in addr result
#emit stor.pri addr1
for( x = 1; x != size_1; ++x ) {
slot = x;
#emit LOAD.S.pri array
#emit SHL.C.alt 2
#emit ADD
#emit STOR.pri slot
#emit LOAD.I
#emit ADD
#emit STOR.pri addr2
#emit LOAD.pri addr1
#emit LOAD.alt slot
#emit SUB
#emit STOR.I
}
return true;
}
new array[6][3];
SetAll( array, -1 );
for(new x = 0; x != sizeof array; x++)
for(new i = 0;i != sizeof array[]; i++)
printf("%d", array[x][i]);
#define SetAll(%0,%1) \ for (new _a = 0; _a < sizeof(%0); _a ++) \ for (new _b = 0; _b < sizeof(%0[]); _b ++) \ %0[_a][_b] = %1
stock Float:ReturnDriftAngle(playerid)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(vehicleid == INVALID_VEHICLE_ID || !vehicleid) return 0.0;
new Float:v[3], Float:a[3];
GetVehicleVelocity(vehicleid, v[0], v[1], v[2]); GetVehicleZAngle(vehicleid, a[0]);
if(floatmul(floatsqroot(floatadd(floatadd(floatpower(v[0], 2), floatpower(v[1], 2)), floatpower(v[2], 2))), 181.5) < 20.0) return 0;
a[0] = (a[0] >= 360.0) ? (floatsub(a[0], 360.0)) : (a[0] < 0.0) ? (floatadd(a[0], 360.0)) : (a[0]);
a[0] = (a[0] > 180.0) ? (floatsub(0.0, floatsub(360.0, a[0]))) : (a[0]);
a[1] = floatsub(atan2(v[1], v[0]), 90.0);
a[1] = (a[1] >= 360.0) ? (floatsub(a[1], 360.0)) : (a[1] < 0.0) ? (floatadd(a[1], 360.0)) : (a[1]);
a[1] = (a[1] > 180.0) ? (floatsub(0.0, floatsub(360.0, a[1]))) : (a[1]);
a[2] = floatabs(floatsub(a[0], a[1]));
a[2] = (a[2] > 180.0) ? (floatsub(a[2], 180.0)) : (a[2]);
return (a[2] >= 90.0) ? (floatsub(180.0, a[2])) : (a[2]);
}
a[0] = (a[0] >= 360.0) ? (floatsub(a[0], 360.0)) : (a[0] < 0.0) ? (floatadd(a[0], 360.0)) : (a[0]); // Adjusts the angle between 0 and 360 degrees.
a[0] = (a[0] > 180.0) ? (floatsub(0.0, floatsub(360.0, a[0]))) : (a[0]); // Adjusts between -180 and 180 degrees.
a[1] = floatsub(atan2(v[1], v[0]), 90.0); // Gets the heading angle from the speed.
a[1] = (a[1] >= 360.0) ? (floatsub(a[1], 360.0)) : (a[1] < 0.0) ? (floatadd(a[1], 360.0)) : (a[1]); // Same things with heading angle.
a[1] = (a[1] > 180.0) ? (floatsub(0.0, floatsub(360.0, a[1]))) : (a[1]); // Again.
a[2] = floatabs(floatsub(a[0], a[1])); // Gets the difference between the angles.
a[2] = (a[2] > 180.0) ? (floatsub(a[2], 180.0)) : (a[2]); // Sets the value between 0 and 180 degrees.
return (a[2] >= 90.0) ? (floatsub(180.0, a[2])) : (a[2]); // Adjusts the value between 0 and 90 degrees.
// Returns pure drift.
stock bool:IsVehicleDrivingBackwards(vehicleid)
{
new Float:Float[3];
if(GetVehicleVelocity(vehicleid, Float[1], Float[2], Float[0])) {
GetVehicleZAngle(vehicleid, Float[0]);
if(Float[0] < 90) {
if(Float[1] > 0 && Float[2] < 0) return true;
} else if(Float[0] < 180) {
if(Float[1] > 0 && Float[2] > 0) return true;
} else if(Float[0] < 270) {
if(Float[1] < 0 && Float[2] > 0) return true;
} else if(Float[1] < 0 && Float[2] < 0) return true;
}
return false;
}
I misread the thing, didn't realise it said "difference". However, in that case what happens if you spin out instead of nicely drift?
|
stock visible_vehicles(playerid){ new Float:distrace,Float:pos[ 4 ], vid ; GetPlayerPos( playerid, pos[0], pos[1], pos[2] ); for(new i;i<MAX_VEHICLES;i++){ distrace = GetVehicleDistanceFromPoint(i, pos[0], pos[1], pos[2] ); if( distrace == 0.0 ) continue; if( distrace <= pos[ 3 ] ){ pos[ 3 ] = distrace; vid = i; }else if( pos[ 3 ] == 0.0 ){ pos[ 3 ] = 5000.0; } } if( pos[ 3 ] != 5000.0 ){ return vid; } return INVALID_VEHICLE_ID; }
CMD:puth_to_vehicle( playerid, params[] ){ new vehicle = visible_vehicles(playerid); if( vehicle == INVALID_VEHICLE_ID ) return 0; printf("vid %d", vehicle); PutPlayerInVehicle( playerid, vehicle, 0); return 1; }
#define Time_Convert(%0,%1,%2) new %1 = floatround(((%0) / 60)); new %2 = floatround((%0) - (60 * (%1))) #define Time_ConvertEx(%0,%1,%2,%3) new %1 = floatround(((%0) / 3600)); new %2 = floatround(((%0) / 60) % 60); new %3 = floatround(((%0) - (60 * (%2))) - (3600 * %1) )
public OnFilterScriptInit() { new czas = 99; Time_Convert(czas, tc_min, tc_sek); printf("%d sek to %dmin %ds", czas, tc_min, tc_sek); Time_ConvertEx(czas, tcex_h, tcex_min, tcex_sek); printf("%d sek to %dh %dmin %ds",czas, tcex_h, tcex_min, tcex_sek); return 1; }
#include a_samp #include zcmd #define Time_ConvertEx(%0,%1,%2,%3) new %1 = floatround(((%0) / 3600)); new %2 = floatround(((%0) / 60) % 60); new %3 = floatround(((%0) - (60 * (%2))) - (3600 * %1) ) new pOnline[MAX_PLAYERS]; public OnPlayerConnect(playerid) { pOnline[playerid] = gettime(); return 1; } CMD:ilegram(playerid, cmdtext[]) { new str[128]; Time_ConvertEx(gettime()-pOnline[playerid], h, m, s); format(str, sizeof(str), "Grasz %dh %dm %ds", h, m, s); SendClientMessage(playerid, -1, str); return 1; }
No, I mean spinning the car. So instead of drifting you end up going backwards (like a reverse J-turn).
|
a[2] = (a[2] > 180.0) ? (floatsub(a[2], 180.0)) : (a[2]);
return (a[2] >= 90.0) ? (floatsub(180.0, a[2])) : (a[2]);
stock CreateRandomPosInZonePerimeter(Count, Float:MinX, Float:MinY, Float:MaxX, Float:MaxY)
{
new Float:Width = floatabs(MaxX - MinX);
new Float:Height = floatabs(MaxY - MinY);
new Float:Perimeter = (Width * 2) + (Height * 2);
for(new i = 0; i != Count; i++) {
new Float:C[2],Float:dist = modulus(random(9000), Perimeter);
if(dist <= Width) {
C[0] = modulus(random(9000), Width) + MinX;
C[1] = MinY;
} else if(dist <= Width + Height) {
C[0] = MaxX;
C[1] = modulus(random(9000), Height) + MinY;
} else if(dist <= (Width * 2) + Height) {
C[0] = modulus(random(9000), Width) + MinX;
C[1] = MaxY;
} else {
C[0] = MinX;
C[1] = modulus(random(9000), Height) + MinY;
}
//Do something with X = (C[0]) Y = (C[1])
printf("%f : %f",C[0],C[1]);
}
}
stock Float:modulus(Float:a, Float:b)
{
while(a > b)
a -= b;
return a;
}
#define modulus(%0,%1) (floatround((%0)) % floatround((%1)))
Well this is the function that i made by a mistake but is working so...
pawn Код:
pawn Код:
This return a random point * Count in a zone perimeter ![]() |