[Tutorial] Radius in SA-MP
#1

Radius

So, this is a tutorial completely based on radius, what it is, how you can use it in the code and what it will do in the game. You may get confused between radius and range, they're practically the same thing, nothing to worry about.

What is it?

The radius of something in SA-MP & PAWN is pretty much the same as the radius in maths, which is a straight line from the center of a circle / sphere to the circumference. I'll use the function of IsPlayerInRangeOfPoint for this example, remember, the parameters are this:

pawn Код:
#include <a_samp>

if(IsPlayerInRangeOfPoint(playerid, Float:range, Float:x, Float:y, Float:z))
So, using this in code is a bit like this:

pawn Код:
#include <a_samp>

if(IsPlayerInRangeOfPoint(playerid, 10.0, 50.0, 40.0, 30.0))
This here will check if the player is within the radius of 10 meters of the point X Y Z of 50.0, 40.0 and 30.0. From the point of 50.0, 40.0, 30.0 the GM will create something which you could call an 'invisible' radius from the X Y Z point, which ranges 10 meters out in a North facing direction, from there, the GM will create another 'invisible' which develops this circumference of the circle. Here's a picture explaining this into picture-form:



The center point will be 50.0, 40.0, and 30.0 from the parameters of the function that we used.

As you can see, the center point is the points that we gave upon the parameters of IsPlayerInRangeOfPoint function, then it has enhanced this and made a line that's 10 meters long from this point which thereon has made a circle with regards to that line.

What does it do?

After it has done all of the above, of using the radius and X Y Z points, and creating the circle. For everything / everyone inside of that circle, it will do whatever you want it do for them. i.e. you could do something like this:

pawn Код:
#include <a_samp>
#include <zcmd>

CMD:radius(playerid, params[])
{
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerInRangeOfPoint(i, 10.0, 50.0, 40.0, 30.0))
        {
            SendClientMessage(i, 0xFFFFFFFF, "You're within the range of the points 50.0, 40.0 and 30.0!");
        }
    }
    return 1;
}
This will send that message for everyone who is within 10 meters of the point 50.0, 40.0 and 30.0.

What can I use this for?

You can use this for a lot of useful stuff, and I mean A LOT! Here are a few examples:

pawn Код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>

CMD:rangeheal(playerid, params[])
{
    new Float:range, Float:health;
    if(sscanf(params, "ff", health)) return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /rangeheal [range] [health]");
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerInRangeOfPoint(i, range, x, y, z))
        {
            SetPlayerHealth(i, health);
            SendClientMessage(i, 0xFFFFFFFF, "You have been range healed!");
        }
    }
    return 1;
}

CMD:rangekick(playerid, params[])
{
    new Float:range;
    if(sscanf(params, "f", range)) return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /rangekick [range]");
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerInRangeOfPoint(i, range, x, y, z))
        {
            Kick(i);
        }
    }
    return 1;
}
Is there anything else I can relate radius with?

Yes! There are many other possibilities, you'll find them along the way of your scripting career.
Reply
#2

Great mate.
Reply
#3

Cool tutorial!! thanks for giving me some more idea's :P
Reply
#4

New Idea's Good!!!
Reply
#5

The function supports x, y and z so I'm pretty sure it should be ball shaped instead of a circle. The explenation stays the same just add a dimension
Reply
#6

Quote:
Originally Posted by FUNExtreme
Посмотреть сообщение
The function supports x, y and z so I'm pretty sure it should be ball shaped instead of a circle. The explenation stays the same just add a dimension
It would be a sphere yes, but this is just a rough idea on how it works, not the complete details. Thanks anyway for he feedback.

Thanks everyone else too.
Reply
#7

This is really a simple tut, if you think you could expand it to the basics of SA-MP mathematics like calculating the co - ordinates infront of the player using SIN and COS, offsets, and so on. Keep going
Reply
#8

Quote:
Originally Posted by Rajat_Pawar
Посмотреть сообщение
This is really a simple tut, if you think you could expand it to the basics of SA-MP mathematics like calculating the co - ordinates infront of the player using SIN and COS, offsets, and so on. Keep going
I will do sooner or later. And I know it's a simple tutorial because 1: I wrote it on an iPad :P 2: it's simple for noobs to understand what the radius is, because I've seen noobish scripts where the range of IsPlayerInRangeOfPoint is 0...

I could go on and on and relate much more maths to this tutorial, but I kept it simple and understandable.
Reply
#9

Good job my little Ciups ( Nuba-Ciups)!
Reply
#10

What about to calculate the proper distance between two points?
Hint: http://en.wikipedia.org/wiki/Pythagoras
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)