Re: Useful Functions -
kakalakamakapaka - 08.08.2011
thx, but what is load speed with that code ?
Re: Useful Functions -
Sascha - 10.08.2011
hm here is a IsFloat function I just created..
no clue if someone already posted one here, however here it is
![Cheesy](images/smilies/biggrin.png)
as far as I've tested it it works good
pawn Код:
stock IsFloat(buf[])
{
new l = strlen(buf);
new dcount = 0;
for(new i=0; i<l; i++)
{
if(buf[i] == '.')
{
if(i == 0 || i == l-1) return 0;
else
{
dcount++;
}
}
if((buf[i] > '9' || buf[i] < '0') && buf[i] != '+' && buf[i] != '-' && buf[i] != '.') return 0;
if(buf[i] == '+' || buf[i] == '-')
{
if(i != 0 || l == 1) return 0;
}
}
if(dcount == 0 || dcount > 1) return 0;
return 1;
}
Re: Useful Functions -
RyDeR` - 15.08.2011
I posted one a while ago but it was not very useful since it was only for 2D coords and had constant line points.
GetDistancePointLine:
pawn Код:
#define GetDistancePointLine(%0,%1,%2,%3,%4,%5,%6,%7,%8) \
floatsqroot(floatpower((%4) * ((%8) - (%2)) - (%5) * ((%7) - (%1)), 2.0) + floatpower((%5) * ((%6) - (%0)) - (%3) * ((%8) - (%2)), 2.0) + floatpower((%3) * ((%7) - (%1)) - (%4) * ((%6) - (%0)), 2.0)) / floatsqroot((%3) * (%3) + (%4) * (%4) + (%5) * (%5))
Params:
Код:
%0 - Line start position X.
%1 - Line start position Y.
%2 - Line start position Z.
%3 - Line vector X.
%4 - Line vector Y.
%5 - Line vector Z.
%6 - Point X.
%7 - Point Y.
%8 - Point Z.
Example:
pawn Код:
GetDistancePointLine(0.0, 0.0, 0.0, 0.5, 0.5, 0.1, 500.0, 800.0, 10.0);
Returns '243.141204' which is the correct distance from point "500.0, 800.0, 10.0" to line starting from null point with direction vector 0.5, 0.5, 0.1.
Re: Useful Functions -
OUL - 15.08.2011
@Ryder - So when i use some cordinates i can get front line (vector) ? Something like this:
Код:
x> = player look at
--- = line
x> --------------------
And for example if that's do that then i can make example 'moving camera' with some cordinates and they will move on that ------------- (line)
Re: Useful Functions -
RyDeR` - 26.08.2011
Oh, well my computer tells me something different:
Код:
[07:09:54] [Strong] Execute in 892 ms
[07:09:55] [Ryder] Execute in 894 ms
I also want to point out, there's a no single difference between "your" function and mine except that yours is just written very shortly.
Discussion /closed.
Re: Useful Functions -
Diagram - 27.08.2011
Is there any function for randomizing letters?
I would just use random(26) and a series of case but that'll just slow down the code. Just curious if someone had done this the easy and faster kind of way.
Re: Useful Functions -
RyDeR` - 27.08.2011
Quote:
Originally Posted by Diagram
Is there any function for randomizing letters?
I would just use random(26) and a series of case but that'll just slow down the code. Just curious if someone had done this the easy and faster kind of way.
|
pawn Код:
random(26) + 'a'; // non-captial letters
random(26) + 'A'; // captial letters
Quote:
Originally Posted by [HLF]Southclaw
Well the only way I know of would be to use random bounds
pawn Код:
#define RandomBounds(%1,%2) (random((%2)-(%1))+(%1))
then randomize between the first and last letters of the alphabet [from the ascii table]
which I think is 0x61 to 0x7A
So the code would be
RandomBounds(0x61, 0x7A);
(sorry I forgot the actual numbers for some reason I can only remember the hex)
Hope that helps ![Tongue](images/smilies/razz.gif) ... if it's right (should be I think!)
|
You don't actually need the "numbers" actually, you could also do this:
pawn Код:
RandomBounds('a', 'z');
RandomBounds('A', 'Z');
Re: Useful Functions -
RyDeR` - 27.08.2011
Quote:
Originally Posted by Ak4
RyDeR's you have any sever ?
send for my in PM.
_________________
UpToLower In Macros:
following the post of RyDeR's i'm create this:
<code>
INT: FORUM SA-MP
OUT: forum sa-mp
StrToUpper
<code>
Int: forum sa-mp
Out: FORUM SA-MP
Credts: me.
|
No, I don't own any server (at least right now).
Also, there's a more basic way to do that. Here if you're interested:
pawn Код:
#define strToUpper(%0) \
for(new i; %0[i] != EOS; ++i) \
%0[i] = ('a' <= %0[i] <= 'z') ? (%0[i] += 'A' - 'a') : (%0[i])
pawn Код:
#define strToLower(%0) \
for(new i; %0[i] != EOS; ++i) \
%0[i] = ('A' <= %0[i] <= 'Z') ? (%0[i] += 'a' - 'A') : (%0[i])
Re: Useful Functions -
Diagram - 27.08.2011
Quote:
Originally Posted by [HLF]Southclaw
Well the only way I know of would be to use random bounds
pawn Код:
#define RandomBounds(%1,%2) (random((%2)-(%1))+(%1))
then randomize between the first and last letters of the alphabet [from the ascii table]
which I think is 0x61 to 0x7A
So the code would be
RandomBounds(0x61, 0x7A);
(sorry I forgot the actual numbers for some reason I can only remember the hex)
Hope that helps ![Tongue](images/smilies/razz.gif) ... if it's right (should be I think!)
|
Quote:
Originally Posted by RyDeR`
pawn Код:
random(26) + 'a'; // non-captial letters random(26) + 'A'; // captial letters
You don't actually need the "numbers" actually, you could also do this:
pawn Код:
RandomBounds('a', 'z'); RandomBounds('A', 'Z');
|
Thanks guys, will try both.
Anyway do these functions outputs the code in string or integer?
Re: Useful Functions - [S]trong - 27.08.2011
*****, hm.
The drakins create this:
http://pastebin.com/8Rby7WdE
is correct?
Re: Useful Functions -
RyDeR` - 27.08.2011
Quote:
Originally Posted by Diagram
Thanks guys, will try both.
Anyway do these functions outputs the code in string or integer?
|
Integer - you can print is as string though.
Quote:
Originally Posted by [S]trong
|
****** was far more
earlier than DraKiNs. But yes, it is correct.
Re: Useful Functions -
Lorenc_ - 28.08.2011
pawn Код:
#define Array:%1<%2> %1[(%2) char]
stock Array_Get(array[], index) return array{index};
Something small I did, tested it and it worked on a interger value. Quite handy for people wanting to keep there own scripts 'neat'.
Please do post problems
Re: Useful Functions -
Bakr - 28.08.2011
Quote:
Originally Posted by Lorenc_
pawn Код:
#define Array:%1<%2> %1[(%2) char] stock Array_Get(array[], index) return array{index};
Something small I did, tested it and it worked on a interger value. Quite handy for people wanting to keep there own scripts 'neat'.
Please do post problems ![Smiley](images/smilies/smile.png)
|
You may want to warn people that you won't be able to store values over 8 bits. You should also check to make sure the index is valid before returning it.
Re: Useful Functions -
Lorenc_ - 28.08.2011
Quote:
Originally Posted by Bakr
You may want to warn people that you won't be able to store values over 8 bits. You should also check to make sure the index is valid before returning it.
|
Will do soon, still studying more about the pre-processor of PAWN.
Rep++; for that
Re: Useful Functions -
RyDeR` - 28.08.2011
Quote:
Originally Posted by Lorenc_
<code>
Something small I did, tested it and it worked on a interger value. Quite handy for people wanting to keep there own scripts 'neat'.
Please do post problems ![Smiley](images/smilies/smile.png)
|
That's also exactly how rBits works for 8-bits.
Re: Useful Functions -
Lorenc_ - 28.08.2011
Quote:
Originally Posted by RyDeR`
That's also exactly how rBits works for 8-bits. ![Tongue](images/smilies/razz.gif)
|
![Shocked](images/smilies/surprised.gif)
, how couldn't I possibly check that out! Thanks i'll look more into rBits, it's so damn useful!
Re: Useful Functions -
Basicz - 28.08.2011
Maybe an ' useless ' function =D
But
pawn Код:
stock getPlayerFirstRPName( playerid, bool: oneCharAllowed = false )
{
new
pName[ MAX_PLAYER_NAME ]
;
GetPlayerName( playerid, szName, sizeof szName );
if ( !( 'A' <= pName[ 0 ] <= 'Z' ) ) // if ( !( szName[ 0 ] >= 'A' && szName[ 0 ] <= 'Z' ) )
return 0;
if ( !oneCharAllowed )
{
if ( szName[ 1 ] == '_' )
return 0;
}
new
iPos = strfind( szName, "_" )
;
strdel( szName, iPos, strlen( szName ) );
return szName;
}
The function was not tested; but the method was.
Lorenc_ returns Lorenc
Avada_Kedavra_Lumos returns Avada ( This was tested with the method; the string size was not 24. )
Police_A returns Police
IMPROVED Version by RyDeR'
pawn Код:
stock getPlayerFirstRPName( playerid, bool: oneCharAllowed = false )
{
new
pName[ MAX_PLAYER_NAME ]
;
GetPlayerName( playerid, szName, sizeof szName );
if ( !( 'A' <= pName[ 0 ] <= 'Z' ) ) // if ( !( szName[ 0 ] >= 'A' && szName[ 0 ] <= 'Z' ) )
return 0;
if ( !oneCharAllowed )
{
if ( szName[ 1 ] == '_' )
return 0;
}
new
iPos = strfind( szName, "_" )
;
if ( iPos == -1 )
szName[ iPos ] = EOS;
return szName;
}
Re: Useful Functions -
RyDeR` - 28.08.2011
You can change to last part to improve some performance:
pawn Код:
new
iPos = strfind(szName, "_")
;
if(iPos != -1)
szName[iPos] = EOS;
return szName;
Re: Useful Functions -
Basicz - 28.08.2011
OffTopic: May I ask what does ' szName[ iPos ] = EOS ' does ? And what's EOS?
Sorry if I act like a noob, I really want to know
And thanks, rep++
Re: Useful Functions -
Kar - 28.08.2011
Quote:
Originally Posted by Basicz
OffTopic: May I ask what does ' szName[ iPos ] = EOS ' does ? And what's EOS?
Sorry if I act like a noob, I really want to know
And thanks, rep++
|
the code finds a "_" right, if that "_" is found it sets it to "\0"
seems like ****** beat me
This forum requires that you wait 120 seconds between posts. Please try again in 60 seconds.
This forum requires that you wait 120 seconds between posts. Please try again in 42 seconds.
This forum requires that you wait 120 seconds between posts. Please try again in 23 seconds.
This forum requires that you wait 120 seconds between posts. Please try again in 1 seconds.