Useful Functions

Quote:
Originally Posted by ******
View Post
I would also like to point out that the other important part of YIJET's post is that they used the operators instead of the functions - I don't know WHY people still insist on using "floatadd" instead of "+"; they do exactly the same thing and one is VASTLY simpler to use than the other.
Well then mine would be just:
pawn Code:
Distance = floatsqroot(floatpower(floatabs(X1 - X2), 2) + floatpower(floatabs(Y1 - Y2), 2) + floatpower(floatabs(Z1 - Z2), 2));
And YIJET's would not return the correct value if X1 was a positive and X2 was a negative... It needs the absolute value.
Reply

Eh' I've been up all night, guess I over thought it. Thanks mate.
Reply

Removed.
Reply

Quote:
Originally Posted by ******
View Post
If you need the distance then you HAVE to use that function, the point is that most of the time you don't actually need the distance. If you are just checking if two things are within a certain range of each other then it is faster to square the range and compare to that than it is to square-root the distance and compare to the original range.
I know, but I don't know why the function is slow, calculating the square root of something is just simple division. But isn't there an alternative of floatsqroot for more speed?

Like on this page for example:
http://en.wikipedia.org/wiki/Square_...ebraic_formula
Reply

Removed.
Reply

....
Reply

You're releasing functions that have been posted since ages. Something new would be more useful.
Reply

But they're more efficient!!11

BeepComputer, beeps whatever computer the server is hosted on!

pawn Код:
stock BeepComputer()
{
    print("•");
}
Reply

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
But they're more efficient!!11

BeepComputer, beeps whatever computer the server is hosted on!

pawn Код:
stock BeepComputer()
{
    print("•");
}
LOL, I never thought that could be possibile. Printing a point means beeping the machine, tested and working nice one, (Bad because beeping is leaving one space just like \n).
Reply

Removed.
Reply

Still can't see anything more efficient than before. Anyway you can also use '\a' to beep, just some random information.
Reply

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
...and there's no other way to check if a player is near a vending machine without a loop.
Lol'd
Edit: ups, ****** was faster by 4 minutes, damn you
delete this post if its concider'd spam
Reply

I didn't know those functions exist. I'm not going to browse through 300 pages to find out.
My vending machine function doesn't exist though. I can prove it just by one ****** search.
Reply

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
I didn't know those functions exist. I'm not going to browse through 300 pages to find out.
My vending machine function doesn't exist though. I can prove it just by one ****** search.
Ever heard of the search button?
Reply

Removed.
Reply

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
No shit! I can't search threads though, and I already knew that the GetVehicleSpeed function existed, I just wanted to share my version??

More functions that will get me yelled at:

pawn Код:
new bool:FALSE = false;

#define INI: File:
#define INI_Open(%0)              fopen(%0, io_readwrite)
#define INI_WriteInt(%0,%1,%2)    INI_WriteString(%0, %1, #%2)
#define INI_WriteFloat(%0,%1,%2)  INI_WriteString(%0, %1, #%2)
#define INI_WriteString(%0,%1,%2) fwrite(%0, %1), fputchar(%0, '='), fwrite(%0, %2), fwrite(%0, "\r\n")
#define INI_Int(%0,%1,%2)         do{new _string[128];while(fread(%0,_string)){if(strcmp(_string,%1,false,strlen(%1))==0&&_string[strlen(%1)]=='='){strmid(_string,_string,strlen(%1)+1,strlen(_string)-2,128);%2=strval(_string);fseek(%0,0,seek_start);break;}}}while(FALSE)
#define INI_Float(%0,%1,%2)       do{new _string[128];while(fread(%0,_string)){if(strcmp(_string,%1,false,strlen(%1))==0&&_string[strlen(%1)]=='='){strmid(_string,_string,strlen(%1)+1,strlen(_string)-2,128);%2=floatstr(_string);fseek(%0,0,seek_start);break;}}}while(FALSE)
#define INI_String(%0,%1,%2,%3)   do{new _string[128];while(fread(%0,_string)){if(strcmp(_string,%1,false,strlen(%1))==0&&_string[strlen(%1)]=='='){strmid(%2,_string,strlen(%1)+1,strlen(_string)-2,%3);fseek(%0,0,seek_start);break;}}}while(FALSE)
#define INI_Close(%0)             fclose(%0)
pawn Код:
public OnFilterScriptInit()
{
    new
        INI:test,
        money,
        Float:health,
        string[24];
       
    test = INI_Open("file.txt");
    INI_WriteInt(test, "Money", 100);
    INI_WriteFloat(test, "Health", 75.0);
    INI_WriteString(test, "String", "Sup.");
    INI_Close(test);
   
    test = INI_Open("file.txt");
    INI_Int(test, "Money", money);
    INI_String(test, "String", string, 24);
    INI_Float(test, "Health", health);

    print(string);
    printf("You have $%d.", money);
    printf("%f", health);
   
    INI_Close(test);
    return 1;
}
Poor emmet.

OT: Those are some interesting macros, lol. I actually wasn't aware you could make them so long. Cool!
Reply

~~~~
Reply

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
[Offtopic]
I'd like to see quad-trees applied, it's the kind of thing I don't think I could just learn by reading the wiki page and I wouldn't know what else to search for. seeing it applied to a real situation (like that IsAtVendingMachine function) would be awesome, does anyone know of any nice simple examples of this or other useful algorithms that ****** mentioned?
Wikipedia has a nice pseudo-code on the Quadtree page, it's quite well explained if you ask me.
Reply

~~~~
Reply

~~~~
Reply


Forum Jump:


Users browsing this thread: 26 Guest(s)