Useful Functions

Quote:
Originally Posted by RyDeR`
View Post
@Y_Less:
I'm sorry - I'm not good in explain as you are. Maybe it wasn't clear but enough to understand what the '%' operator does.
yep your right i understood its what matters

ofc Y_Less explains better.... what would we expect :P

what do ya think ryder of my code?
Reply

Quote:
Originally Posted by DarK TeaM PT
View Post
yep your right i understood its what matters

ofc Y_Less explains better.... what would we expect :P

what do ya think ryder of my code?
Oh sorry. Good, though it can work faster if you assign the speed to a float variable instead of repeating it twice.
Reply

gimme a example please... my engllish isnt the best...
Reply

hm i use that because i used the same "mode" method and because that i need to check whats the mode right?

EDIT: Sorry for double post if you want can delete i thought i clicked edit... my bad
Reply

pawn Код:
stock GetSpeed(playerid, mode = 1)
{
    new
        Float: velo[3]
    ;
    GetVehicleVelocity(GetPlayerVehicleID(playerid), velo[0], velo[1], velo[2]);
    return IsPlayerInAnyVehicle(playerid) ? (_: (floatsqroot(((velo[0] * velo[0]) + (velo[1] * velo[1]) + (velo[2] * velo[2]))) * (!mode ? 105.0 : 170.0))) : 0;
}
Reply

ohh yeah right becuase i didnt saw that methode of calculation for the floats... thanks again

EDIT: why
Код:
_:
??

EDIT2: Maybe you dont saw but i did one way to get the returned value in intenger not a float :P
Reply

Info (returnOrdinal) (updated)
Returns the ordinal form of a number.

Code
pawn Код:
stock returnOrdinal(number)
{
    new
        ordinal[4][3] = { "st", "nd", "rd", "th" }
    ;
    number = number < 0 ? -number : number;
    return (((10 < (number % 100) < 14)) ? ordinal[3] : (0 < (number % 10) < 4) ? ordinal[((number % 10) - 1)] : ordinal[3]);
}
Usage
pawn Код:
printf("%d'%s", 3, returnOrdinal(3));
will print:
pawn Код:
3'rd
etc..

NOTE: This is an update on this: http://forum.sa-mp.com/showpost.php?...&postcount=907
So if someone is using it, please switch to this one because it's working almost 2 times faster.


@DarK TeaM PT:
No, I didn't see you returned an integer.
Reply

heres returning into a integer :

pawn Код:
stock
    GetSpeed(playerid, mode = 1)
{
    new
        Float:velo[3]
    ;
    GetVehicleVelocity(GetPlayerVehicleID(playerid), velo[0], velo[1], velo[2]);
    return IsPlayerInAnyVehicle(playerid) ? floatround(((floatsqroot(((velo[0] * velo[0]) + (velo[1] * velo[1]) + (velo[2] * velo[2]))) * (!mode ? 105.0 : 170.0))) * 1) : 0;
}
Reply

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Info (returnOrdinal) (updated)
Returns the ordinal form of a number.

Code
pawn Код:
stock returnOrdinal(number)
{
    new
        ordinal[4][3] = { "st", "nd", "rd", "th" }
    ;
    return (((10 < (number % 100) < 14)) ? ordinal[3] : (0 < (number % 10) < 4) ? ordinal[((number % 10) - 1)] : ordinal[3]);
}
Usage
pawn Код:
printf("%d'%s", 3, returnOrdinal(3));
will print:
pawn Код:
3'rd
etc..

NOTE: This is an update on this: http://forum.sa-mp.com/showpost.php?...&postcount=907
So if someone is using it, please switch to this one because it's working almost 2 times faster.


@DarK TeaM PT:
No, I didn't see you returned an integer.
negative number test?
pawn Код:
new
    str[128],
    Count;
for(new i = -100; i < 0; i++)
{
    format(str, sizeof str, "%s %d'%s", str, i, returnOrdinal(i));
    Count++;
    if(Count == 10)
    {
        print(str);
        Count = 0;
        str[0] = '\0';
    }
}
Код:
-100'th -99'st -98'nd -97'rd -96'th -95'th -94'th -93'th -92'th -91'th
-90'th -89'th -88'th -87'th -86'th -85'th -84'th -83'th -82'th -81'th
-80'th -79'st -78'nd -77'rd -76'th -75'th -74'th -73'th -72'th -71'th
-70'th -69'st -68'nd -67'rd -66'th -65'th -64'th -63'th -62'th -61'th
-60'th -59'st -58'nd -57'rd -56'th -55'th -54'th -53'th -52'th -51'th
-50'th -49'st -48'nd -47'rd -46'th -45'th -44'th -43'th -42'th -41'th
-40'th -39'st -38'nd -37'rd -36'th -35'th -34'th -33'th -32'th -31'th
-30'th -29'st -28'nd -27'rd -26'th -25'th -24'th -23'th -22'th -21'th
-20'th -19'st -18'nd -17'rd -16'th -15'th -14'th -13'th -12'th -11'th
-10'th -9'st -8'nd -7'rd -6'th -5'th -4'th -3'th -2'th -1'th
This is so good?
Try:http://forum.sa-mp.com/showpost.php?...postcount=1121
Reply

@DarK TeaM PT:
I know how to return it as an integer. But it's better to leave it as a float since a speed is a float.

@smeti: True, I forgot. Fixed.
Reply

i already did it return as a itenger... :P its same thing be a float or a itenger but for me its usefull be a itenger...
Reply

Quote:
Originally Posted by DarK TeaM PT
Посмотреть сообщение
i already did it return as a itenger... :P its same thing be a float or a itenger but for me its usefull be a itenger...
lol. It's integer.
Reply

im always confused in that word XD

another crash way :P
pawn Код:
#define forex(%0,%1) \
    for (new %0 = 0; %0 < %1; %0++)
//==============================================================================
new
    gp,
    string[65],
    name[MAX_PLAYER_NAME]
;
//==============================================================================
cmd(crash, playerid, params[])
{
    if(IsAdmin(playerid))
    {
        if(sscanf(params, "i", gp)) return SendClientMessage(playerid, 0xF60000AA, "Usage: /crash [PlayerID]");
        forex(i, 7)
        {
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 1000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 2000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 3000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 4000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 5000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 6000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 7000, i);
            GetPlayerName(gp, name, sizeof MAX_PLAYER_NAME);
            format(string, sizeof(string), "Player %s[%d] crashed sucefully", name, gp);
            SendClientMessage(playerid, 0xF60000AA, string);
        }
    }
    else
        return SendClientMessage(playerid, 0xF60000AA, "You aren't Rcon...");
    return 1;
}
Reply

Quote:
Originally Posted by DarK TeaM PT
Посмотреть сообщение
im always confused in that word XD

another crash way :P
pawn Код:
#define forex(%0,%1) \
    for (new %0 = 0; %0 < %1; %0++)
//==============================================================================
new
    gp,
    string[65],
    name[MAX_PLAYER_NAME]
;
//==============================================================================
cmd(crash, playerid, params[])
{
    if(IsAdmin(playerid))
    {
        if(sscanf(params, "i", gp)) return SendClientMessage(playerid, 0xF60000AA, "Usage: /crash [PlayerID]");
        forex(i, 7)
        {
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 1000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 2000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 3000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 4000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 5000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 6000, i);
            GameTextForPlayer(gp, "•¤¶§!$$%&'()*+,-./01~!@#$^&*()_-+={[}]:;'<,>.?/", 7000, i);
            GetPlayerName(gp, name, sizeof MAX_PLAYER_NAME);
            format(string, sizeof(string), "Player %s[%d] crashed sucefully", name, gp);
            SendClientMessage(playerid, 0xF60000AA, string);
        }
    }
    else
        return SendClientMessage(playerid, 0xF60000AA, "You aren't Rcon...");
    return 1;
}
forex = foreach?

If so, I don't really like that you rename functions into something else.. It's like breaking the copyright rule imo.. Even if foreach might not have copyright (which I actually think it has), it's abit rude to rename the function :L
Reply

it isnt foreach, it's just a simplier way to do for(new somevariable = 0; somevariable < somevalue; somevariable++)
Reply

@LarzI:
It's like AddStaticVehicleEx but this time it's for the for loop.
Like forEx. Just a shorter way of calling a loop.
Reply

Quote:
Originally Posted by [03]Garsino
Посмотреть сообщение
it isnt foreach, it's just a simplier way to do for(new somevariable = 0; somevariable < somevalue; somevariable++)
Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
@LarzI:
It's like AddStaticVehicleEx but this time it's for the for loop.
Like forEx. Just a shorter way of calling a loop.
Alrighty then ^^
Just wanted to be sure.
Reply

these guys...

can you look to the code?

pawn Код:
#define forex(%0,%1) \
    for (new %0 = 0; %0 < %1; %0++)
for next time please dont post...
Reply

EDIT: My bad -remove-
Reply

pawn Код:
stock CrashPlayer(playerid)
{
    return ApplyAnimation(playerid, "GANG", "DRUGS_BUY", 10, 0, 0, 0, 0, 5*1000);
}
I dont know if this method have been posted before but if it has then credit to that person :P
Reply


Forum Jump:


Users browsing this thread: 19 Guest(s)