Re: Useful Functions -
SlashPT - 20.09.2010
Quote:
Originally Posted by RyDeR`
@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?
Re: Useful Functions -
RyDeR` - 20.09.2010
Quote:
Originally Posted by DarK TeaM PT
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.
Re: Useful Functions -
SlashPT - 20.09.2010
gimme a example please... my engllish isnt the best...
Re: Useful Functions -
SlashPT - 20.09.2010
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
Re: Useful Functions -
RyDeR` - 20.09.2010
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;
}
Re: Useful Functions -
SlashPT - 20.09.2010
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
Re: Useful Functions -
RyDeR` - 20.09.2010
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:
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.
Re: Useful Functions -
SlashPT - 20.09.2010
heres returning into a integer
![Cheesy](images/smilies/biggrin.png)
:
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;
}
Re: Useful Functions -
smeti - 20.09.2010
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:
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.
|
![Tongue](images/smilies/razz.gif)
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
Re: Useful Functions -
RyDeR` - 20.09.2010
@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.
Re: Useful Functions -
SlashPT - 21.09.2010
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...
Re: Useful Functions -
RyDeR` - 21.09.2010
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.
Re: Useful Functions -
SlashPT - 21.09.2010
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;
}
Re: Useful Functions -
LarzI - 21.09.2010
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
Re: Useful Functions - [03]Garsino - 21.09.2010
it isnt foreach, it's just a simplier way to do for(new somevariable = 0; somevariable < somevalue; somevariable++)
Re: Useful Functions -
RyDeR` - 21.09.2010
@LarzI:
It's like AddStaticVehicle
Ex but this time it's for the for loop.
Like for
Ex. Just a shorter way of calling a loop.
Re: Useful Functions -
LarzI - 21.09.2010
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.
Re: Useful Functions -
SlashPT - 21.09.2010
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...
Re: Useful Functions -
Luka P. - 21.09.2010
EDIT: My bad -remove-
Re: Useful Functions - [03]Garsino - 21.09.2010
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