10.11.2013, 15:02
(
Последний раз редактировалось DanishHaq; 10.11.2013 в 22:18.
)
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:
So, using this in code is a bit like this:
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:
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:
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.
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))
pawn Код:
#include <a_samp>
if(IsPlayerInRangeOfPoint(playerid, 10.0, 50.0, 40.0, 30.0))
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;
}
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;
}
Yes! There are many other possibilities, you'll find them along the way of your scripting career.