Useful Functions

Quote:
Originally Posted by Slice
Посмотреть сообщение
Create a TextDraw box. This is about as accurate as I could get it.
It's easier to create an accurate box by using sprite "LD_BUM:blkdot", but I am not sure if you can recolor that thing. :P

pawn Код:
new Text:box = TextDrawCreate(x1, y1, "LD_BUM:blkdot");
TextDrawFont(box, 4);
TextDrawTextSize(box, (x2 - x1), (y2 - y1));
Reply

Revamped the version someone posted about ConvertPrice itself, it now doesn't use valstr and supports negative numbers.

pawn Код:
stock ConvertPrice( price, no_price_tag = 0 )
{
    new
        szString[ 32 ],
        iNumbers = 0,
        bool: isneg = price < 0 ? true : false
    ;
    if( isneg ) price = price * -1;
   
    iNumbers = floatround( floatlog( price ), floatround_floor ) + 1;
    format( szString, sizeof( szString ), "%d", price );
    while( iNumbers >= 4 ) {
        iNumbers -= 3;
        strins( szString, ",", iNumbers );
    }
    if( !no_price_tag ) strins( szString, "$", 0 );
    if( isneg ) strins( szString, "-", 0 );
    return szString;
}
Warning: Can crash if using a integer over the 32 bit integer limit..

I fixed some little glitch with the logarithm... Should work fine now!
Reply

I remember posting this function almost two years ago, just if you're interested:
pawn Код:
stock convertNumber(iValue, iDelim[2] = ".", szNum[15] = "", iSize = sizeof(szNum)) {
    format(szNum, iSize, "%d", iValue < 0 ? -iValue : iValue);
   
    for(new i = strlen(szNum) - 3; i > 0; i -= 3) {
        strins(szNum, iDelim, i, iSize);
    }
    if(iValue < 0) {
        strins(szNum, "-", 0, iSize);
    }
    return szNum;
}
pawn Код:
printf("%s", convertNumber(1246645455, .iDelim = "_")); // 1_246_645_455
printf("%s", convertNumber(-145455, .iDelim = ".")); // -145.455
printf("%s", convertNumber(-94411254, .iDelim = ",")); // -94,411,254
Reply

Yeah, I noticed I could of optimized a few things but I'll be sure to use yours as it might be faster (from the looks of it, mines larger in code).
Reply

Yeah, for example the logarithm part to calculate the length is pretty unnecessary - just use strlen as you have already converted the number into a string.
Reply

I have been working on a wait function lately

One version with an global stack which and another one with SetTimerEx only

I just want that some people test it out since there were some problems with the second version

Pastebin

Usage

pawn Код:
// Usage:  wait(time)
wait(5000);
Reply

I wanna know if
pawn Код:
#define varGet(%0)              getproperty(0,%0)
#define varSet(%0,%1)           setproperty(0, %0, %1)


#define new_strcmp(%0,%1) \
                (varSet(%0, 1), varGet(%1) == varSet(%0, 0)) // by DraKiNs
is better than SA-MP strcmp?
Reply

Quote:
Originally Posted by [FeK]DraKiNs
Посмотреть сообщение
Hey RyDeR' !

You that like math, answer me



(GangZones Post)

---

I tried everything, but can not find anything (to create "circulation" must make "interpolation" of gangzones)
pawn Код:
stock RoundGangZone(const Float: radius, const Float: X , const Float: Y, const color, const size = 20) {  
    new
        Float: inc = 90.0 / size,
        Float: deg = inc,
        Float: cos,
        Float: sin,
        zone
    ;
    while(deg < 90.0) {
        cos = floatcos(deg, degrees) * radius;
        sin = floatsin(deg, degrees) * radius;

        zone = GangZoneCreate(X - cos, Y - sin, X + cos, Y + sin);
        GangZoneShowForAll(zone, color);

        deg += inc;
    }
    return zone;
}
The upper "circle" is your version, both use about the same number of zones in the picture



It doesnt look like a circle because of my resolution
Reply

edit: shit I just realized I double posted

pawn Код:
#include < YSI\y_scripting >

stock debugAllZCMDCommands( playerid, szAdditionParam[ ] = "500" ) // The first parameter will be 500 e.g /kick 500
{
    static
        szPublic[ 32 ],
        iCount
    ;

    while( ( iCount = Scripting_GetPublicFast( iCount, szPublic, ( Scripting_FastString('c', 'm', 'd', '_') ) ) ) )
    {
        if( !strcmp( szPublic, "cmd_testallcmds", true ) ) continue; // The command that you're placing this function in (so it doesn't repeat...)
        printf( "%s", szPublic );
        CallLocalFunction( szPublic, "ds", playerid, szAdditionParam );
    }
   
    // If your server crashes, then the last command called is the problem
    return 1;
}
Reply

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Revamped the version someone posted about ConvertPrice itself, it now doesn't use valstr and supports negative numbers.

pawn Код:
stock ConvertPrice( price, no_price_tag = 0 )
{
    new
        szString[ 32 ],
        iNumbers = 0,
        bool: isneg = price < 0 ? true : false
    ;
    if( isneg ) price = price * -1;
   
    iNumbers = floatround( floatlog( price ), floatround_floor ) + 1;
    format( szString, sizeof( szString ), "%d", price );
    while( iNumbers >= 4 ) {
        iNumbers -= 3;
        strins( szString, ",", iNumbers );
    }
    if( !no_price_tag ) strins( szString, "$", 0 );
    if( isneg ) strins( szString, "-", 0 );
    return szString;
}
Warning: Can crash if using a integer over the 32 bit integer limit..

I fixed some little glitch with the logarithm... Should work fine now!
Was it tested with numbers such as 1,000,000,000 (1 billion)? Most functions that convert into price tags (if you know what I mean) crash the server / fail to work when over 1,000,000,000 (which is under the 32-bit integer limit).

I'll test it later - thanks.

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
pawn Код:
stock RoundGangZone(const Float: radius, const Float: X , const Float: Y, const color, const size = 20) {  
    new
        Float: inc = 90.0 / size,
        Float: deg = inc,
        Float: cos,
        Float: sin,
        zone
    ;
    while(deg < 90.0) {
        cos = floatcos(deg, degrees) * radius;
        sin = floatsin(deg, degrees) * radius;

        zone = GangZoneCreate(X - cos, Y - sin, X + cos, Y + sin);
        GangZoneShowForAll(zone, color);

        deg += inc;
    }
    return zone;
}
The upper "circle" is your version, both use about the same number of zones in the picture



It doesnt look like a circle because of my resolution
This is great! If the player is wanted, it will show a circle on the map (like GTA IV). Thanks :P
Reply

fRemoveLine
pawn Код:
fRemoveLine(file[],line[])//By: Firecat
{
    new string[256],
        File:Temp = fopen("Temp.ini",io_append),
        File:Main = fopen(file,io_read);

    while(fread(Main,string))
    {
        if(strcmp(string,line) != 0)
        {
            fwrite(Temp,string);
        }
    }
    fclose(Main);
    fclose(Temp);
    fremove(file);
   
    Main = fopen(file, io_append);
    Temp = fopen("Temp.ini",io_read);
   
    while(fread(Temp,string))
    {
        fwrite(Main,string);
    }
    fclose(Main);
    fclose(Temp);
    fremove("Temp.ini");
    return 1;
}
fUpdateLine
pawn Код:
fUpdateLine(file[],oldline[],newline[])//By: Firecat
{
    new string[256],
        File:Temp = fopen("Temp.ini",io_append),
        File:Main = fopen(file,io_append);

    while(fread(Main,string))
    {
        if(!strcmp(oldline,string))
            fwrite(Temp,newline)
        else
            fwrite(Temp,string)
    }
    fclose(Main);
    fclose(Temp);
    fremove(file);

    File:Main = fopen(file,io_append);
    File:Temp = fopen("Temp.ini",io_read);
   
    while(fread(Temp,string))
    {
        fwrite(Main,string);
    }
    fclose(Temp);
    fclose(Main);
    fremove(Temp);
    return 1;
}
fChangeName
pawn Код:
fChangeName(file[],newname[])//By:Firecat
{
    new string[256],
        File:New = fopen(newname,io_append),
        File:Main = fopen(file,io_read);

    while(fread(Main,string))
    {
        fwrite(New,string);
    }
    fclose(Main);
    fclose(New);
    fremove(Main);
    return 1;
}
Reply

http://pastebin.com/zT3jhSay

lol firecat
Reply

Yeah, right here.
Reply

Quote:
Originally Posted by ******
Посмотреть сообщение
Have none of you heard of the ftemp function?
Not sure if that's me included, but:
Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Yeah, right here.
Reply

Question:
Is there a function that gives me a random X Axis, random Y axis, from a given Max X, Max Y?
Reply

Quote:
Originally Posted by FireCat
Посмотреть сообщение
Question:
Is there a function that gives me a random X Axis, random Y axis, from a given Max X, Max Y?
pawn Код:
stock Float: randomFloat(Float: fMin, Float: fMax, iDig) {
    iDig = _: floatpower(10.0, iDig);

    fMin = Float: (floatround(fMin * Float: iDig));
    fMax = Float: (floatround(fMax * Float: iDig));
   
    return (random((_: fMax - _: fMin)) + _: fMin) / Float: iDig;
}
This should work well.
Reply

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
pawn Код:
stock Float: randomFloat(Float: fMin, Float: fMax, iDig) {
    iDig = _: floatpower(10.0, iDig);

    fMin = Float: (floatround(fMin * Float: iDig));
    fMax = Float: (floatround(fMax * Float: iDig));
   
    return (random(_: (fMax - fMin)) + _: fMin) / Float: iDig;
}
This should work well.
That "iDig" is...?
Edit: and how would I use the function? What does it return ? e.e
Reply

Quote:
Originally Posted by FireCat
Посмотреть сообщение
That "iDig" is...?
Edit: and how would I use the function? What does it return ? e.e
Yeah sorry, I was kinda in a hurry. iDig is the amount of significant digits. A basic example would be:
pawn Код:
#define SIGNIFICANT_DIGITS (3)

printf("%.*f", SIGNIFICANT_DIGITS, randomFloat(6.123, 11.5, SIGNIFICANT_DIGITS)); // Possible output: 8.465
This would generate a random float between 6.123 and 11.548 with a maximum of 3 significant digits (465).

Quote:
Originally Posted by ******
Посмотреть сообщение
I don't think you've tested that! I can see at least one issue arising from your bizarre reuse of variables and the associated mash of tag overrides. I seem to recall another post of yours I commented on recently with odd float usage too.
No, I have tested it a couple of times and it did actually work with no problems.
Reply

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Yeah sorry, I was kinda in a hurry. iDig is the amount of significant digits. A basic example would be:
pawn Код:
#define SIGNIFICANT_DIGITS (3)

printf("%.*f", SIGNIFICANT_DIGITS, randomFloat(6.123, 11.5, SIGNIFICANT_DIGITS)); // Possible output: 8.465
This would generate a random float between 6.123 and 11.548 with a maximum of 3 significant digits (465).


No, I have tested it a couple of times and it did actually work with no problems.
Thanks! <3
Edit:
I'm using this code:
pawn Код:
for(new i; i < 1600; i++)
            {
                CreateExplosion(randomFloat(-341.5977,-135.6987,3),randomFloat(2796.9480,2589.1521,3),61.8585,2,50);
            }
Reply

Quote:
Originally Posted by FireCat
Посмотреть сообщение
Thanks! <3
Edit:
I'm using this code:
pawn Код:
for(new i; i < 1600; i++)
            {
                CreateExplosion(randomFloat(-341.5977,-135.6987,3),randomFloat(2796.9480,2589.1521,3),61.8585,2,50);
            }
< PICTURE >
I see a small problem, this should work better now:
pawn Код:
stock Float: randomFloat(Float: fMin, Float: fMax, iDig) {
    iDig = _: floatpower(10.0, iDig);

    fMin = Float: (floatround(fMin * Float: iDig));
    fMax = Float: (floatround(fMax * Float: iDig));
   
    return (random((_: fMax - _: fMin)) + _: fMin) / Float: iDig;
}
Also, the first parameter is fMin which means you have to put the smallest value in there, so this would be correct:
pawn Код:
CreateExplosion(randomFloat(-341.5977, -135.6987, 3), randomFloat(2589.1521, 2796.9480, 3), 61.8585, 2, 50);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)