[2 Random Questions] About zcmd/dcmd and some math operators
#1

Hey! Just some questions to kill my curiosity.

I want to ask if is there possible to create something like this:
Код:
if(strcmp(cmd, "/kill", true) == 0 || strcmp(cmd, "/suicide", true) == 0)
but in zcmd and dcmd.

-And-

How can I perform Equations and Square Roots in Pawno
( I guess that its how its called, here's an image to confirm )
Reply
#2

Quote:

if(strcmp(cmd, "/kill", true) == 0 || strcmp(cmd, "/suicide", true) == 0)

Would be this:
Код:
zcmd(command1, playerid, params[])
{
	do stuff
	return 1;
}

zcmd(command2, playerid, params[])
{
	return zcmd_command1(playerid, params);
}
Replacing "do stuff" with your code obviously.

For square roots, you could use the floatsqroot function.

Equations could be done something like this, I guess.
Код:
new a = 2;
new b = 4;
new c = 11;
new d = a+(b*c);
The output would be 2+(4*11) which is 2+44 which is 46.
Reply
#3

or you could avoid using the floatsqroot, because it is probably the slowest native function (don't quote me on this, in fact this whole theory of mine may be incorrect)
but you could do it like this
(my logic just failed me, so i will post something that most likely works, but may or may not be effective
pawn Код:
floatpower(16, 0.5)
gets the sq root of 16.

okay, a quick check in the language guide proved this theory as completely false, use above ver.
Reply
#4

Regarding your first question, you can use the method posted by someone earlier, or this method:

Quote:
Originally Posted by ZeeX
You can also add simple macro like this:
pawn Код:
#define ALTCOMMAND:%1->%2;           \
            COMMAND:%1(playerid, params[])   \
                return cmd_%2(playerid, params);
and then do:
pawn Код:
COMMAND:cmd1(playerid, params[])
{
    SendClientMessage(playerid, 0xFFFFFFFF, "test message");
    return 1;
}

ALTCOMMAND:cmd2->cmd1;
ALTCOMMAND:cmd3->cmd1;
Reply
#5

Quote:
Originally Posted by Daren_Jacobson
or you could avoid using the floatsqroot, because it is probably the slowest native function (don't quote me on this, in fact this whole theory of mine may be incorrect)
but you could do it like this
(my logic just failed me, so i will post something that most likely works, but may or may not be effective
pawn Код:
floatpower(16, 0.5)
gets the sq root of 16.

okay, a quick check in the language guide proved this theory as completely false, use above ver.
Actually floatsqroot(x) is more than 2 times faster than floatpower(x, 0.5) for positive values, and vice-versa for negative values :P
Reply
#6

Quote:
Originally Posted by Y_Leѕѕ
The first question is WHY you want to use square root, the only real use I've seen it for is distance calculations using pythagoras, and I've written many times why you don't need it as it's slow.
I want to create a loop that could generate a perfect circumference with objects using the Cartesian coordinates. If is there an alternative method to that, please do tell or, if you dont mind, teach me that method.

And after all this, I would like to learn how to create a Torus. I already searched and got some results but I need to start with easier maths, like that perfect circumference thing.

Im out of words, dunno why, if you didnt understand that I just said something, just let me know.

ps. Thank you all for your replyes.
Reply
#7

trig time!!

pawn Код:
newx = radius * floatcos(angle, degrees) + basex;
newy = radius * floatsin(angle, degrees) + basey;
so...
pawn Код:
new Float:pos[722]
for (new angle; angle < 360.0; angle += 0.5)
{
  newx = radius * floatcos(angle, degrees) + basex;
  newy = radius * floatsin(angle, degrees) + basey;
}
have fun.
Reply
#8

Yeh I knew it was something about trigonometry but I never understanded how it really works.

Anyway, I'll try to understand by myself.

Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)