06.07.2014, 01:39
(
Последний раз редактировалось Ghazal; 10.07.2014 в 23:34.
)
Hello there!
Today i am coming up with a new tutorial.
How to make a range command. For example: range freeze, range unfreeze.
Let's begin!
First Step: Define the includes.
We are going to use the following includes:
Question: Why are you using zcmd?
Answer: Because its the fastest command processor in my opinion.
Second Step: Lets define the variables
We need to define If the player is frozen or spawned.
Question: Why did we define this variables?
Answer: To avoid bugs.
Now we need to add the variable of isspawned = 1; under OnPlayerSpawn.
Now we need to add the variable of IsSpawned[playerid] = 0; under OnPlayerDeath.
Now we are going to start scripting the commands.
Lets begin with rfreeze (rangefreeze)
First we are going to add this for sure.
Now we are going to add some new variables like range and string
Now we are going to use sscanf to make sure that the players will use the command right.
Now we are going to add something to make sure that the player who will use the command is spawned.
And now, we are going to script the main part in the command.
We are going to check the players connected and the players near the player who use the command with the range he typed and toggle their control
Question:Why did we add IsFrozen[i] = 1;?
Answer: To set the players to frozen so when we can unfreeze them.
Question: Why did we add " [i] "
Answer: as you saw we defined i in the for(new to max_players which means we defined i as the all of the players connected.
And now we are going to end the command with
Full code for the /rfreeze
Also there is another important thing we should add.
Its a public and a forward for GetDistanceBetweenPlayers which let us know the distance between the players with meters.
Also here is a full filterscript for Range freeze and unfreeze.
Today i am coming up with a new tutorial.
How to make a range command. For example: range freeze, range unfreeze.
Let's begin!
First Step: Define the includes.
We are going to use the following includes:
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf>
Answer: Because its the fastest command processor in my opinion.
Second Step: Lets define the variables
We need to define If the player is frozen or spawned.
pawn Код:
new IsSpawned[MAX_PLAYERS];
new IsFrozen[MAX_PLAYERS];
Answer: To avoid bugs.
Now we need to add the variable of isspawned = 1; under OnPlayerSpawn.
pawn Код:
public OnPlayerSpawn(playerid)
{
IsSpawned[playerid] = 1;
return 1;
}
pawn Код:
public OnPlayerDeath playerid, killerid, reason)
{
IsSpawned[playerid] = 0;
return 1;
}
Lets begin with rfreeze (rangefreeze)
First we are going to add this for sure.
pawn Код:
CMD:rfreeze(playerid,params[])
{
pawn Код:
new range;
new string[128];
pawn Код:
if(sscanf(params,"i",range))
{
SendClientMessage(playerid,-1,"{CACA00}[INFO]{FFFFFF}: /rfreeze (Meters)");
return 1;
}
pawn Код:
if(IsSpawned[playerid] == 0)
{
SendClientMessage(playerid,-1,"{CACA00}[ERROR]{FFFFFF}You must be spawned in order to use this command.");
return 1;
}
We are going to check the players connected and the players near the player who use the command with the range he typed and toggle their control
pawn Код:
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i) && GetDistanceBetweenPlayers(playerid,i) < range)
{
format(string, sizeof(string), "%s(%d) have Freezed all players in range of %d meters.",PlayerName(playerid),playerid,range);
SendClientMessage(i,-1,string);
TogglePlayerControllable(i,0);
IsFrozen[i] =1;
}
}
Answer: To set the players to frozen so when we can unfreeze them.
Question: Why did we add " [i] "
Answer: as you saw we defined i in the for(new to max_players which means we defined i as the all of the players connected.
And now we are going to end the command with
pawn Код:
return 1;
}
pawn Код:
CMD:rfreeze(playerid,params[])
{
new string[128];
new range;
if(sscanf(params,"i",range))
{
SendClientMessage(playerid,-1,"{CACA00}[INFO]{FFFFFF}: /rfreeze (Meters)");
return 1;
}
if(IsSpawned[playerid] == 0)
{
SendClientMessage(playerid,-1,"{CACA00}[ERROR]{FFFFFF}You must be spawned in order to use this command.");
return 1;
}
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i) && GetDistanceBetweenPlayers(playerid,i) < range)
{
format(string, sizeof(string), "%s(%d) have Freezed all players in range of %d meters.",PlayerName(playerid),playerid,range);
SendClientMessage(i,-1,string);
TogglePlayerControllable(i,0);
IsFrozen[i] =1;
}
}
return 1;
}
Its a public and a forward for GetDistanceBetweenPlayers which let us know the distance between the players with meters.
pawn Код:
forward Float:GetDistanceBetweenPlayers(p1,p2);
public Float:GetDistanceBetweenPlayers(p1,p2)
{
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if (!IsPlayerConnected(p1) || !IsPlayerConnected(p2))
{
return -1.00;
}
GetPlayerPos(p1,x1,y1,z1);
GetPlayerPos(p2,x2,y2,z2);
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf>
new IsSpawned[MAX_PLAYERS];
new IsFrozen[MAX_PLAYERS];
forward Float:GetDistanceBetweenPlayers(p1,p2);
public OnFilterScriptInit()
{
SendClientMessageToAll(-1,"{878787}[NOTE] {FFFFFF}This server is using /rfreeze and /runfreeze by Maro06");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
public OnPlayerSpawn(playerid)
{
IsSpawned[playerid] = 1;
return 1;
}
public OnPlayerDeath playerid, killerid, reason)
{
IsSpawned[playerid] = 0;
return 1;
}
CMD:rfreeze(playerid,params[])
{
new string[128];
new range;
if(sscanf(params,"i",range))
{
SendClientMessage(playerid,-1,"{CACA00}[INFO]{FFFFFF}: /rfreeze (Meters)");
return 1;
}
if(IsSpawned[playerid] == 0)
{
SendClientMessage(playerid,-1,"{CACA00}[ERROR]{FFFFFF}You must be spawned in order to use this command.");
return 1;
}
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i) && GetDistanceBetweenPlayers(playerid,i) < range)
{
format(string, sizeof(string), "%s(%d) have Freezed all players in range of %d meters.",PlayerName(playerid),playerid,range);
SendClientMessage(i,-1,string);
TogglePlayerControllable(i,0);
IsFrozen[i] =1;
}
}
return 1;
}
CMD:runfreeze(playerid,params[])
{
new string[128];
new range;
if(sscanf(params,"i",range))
{
SendClientMessage(playerid,-1,"{CACA00}[INFO]{FFFFFF}: /runfreeze (Meters)");
return 1;
}
if(IsSpawned[playerid] == 0)
{
SendClientMessage(playerid,-1,"{CACA00}[ERROR]{FFFFFF}You must be spawned in order to use this command.");
return 1;
}
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i) && GetDistanceBetweenPlayers(playerid,i) < range)
{
format(string, sizeof(string), "%s(%d) have Un Freezed all players in range of %d meters.",PlayerName(playerid),playerid,range);
SendClientMessage(i,-1,string);
TogglePlayerControllable(i,1);
IsFrozen[i] =0;
}
}
return 1;
}
public Float:GetDistanceBetweenPlayers(p1,p2)
{
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if (!IsPlayerConnected(p1) || !IsPlayerConnected(p2))
{
return -1.00;
}
GetPlayerPos(p1,x1,y1,z1);
GetPlayerPos(p2,x2,y2,z2);
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
stock PlayerName(playerid) {
new name[255];
GetPlayerName(playerid, name, 255);
return name;
}