[Tutorial] Single command multiple task
#1

Hi guys. Today i am going to show you how to make a command to do multiple task by just 1 command.
Before we start learning about what and how it works let me explain where can we use it.

Usage

Firstly, we use it mostly for ENTER and EXIT commands.
Secondly, for multiple timeattack races. Like if you want to start a race by a command. If you are near X point race number 1 will start. If other point race number 2 starts.
Mainly , for doing multiple task but by 1 command.

Let's start by making a simple ENTER command at multiple places.

Step 1

First you need to save 2 type of points. 1 from where the command must be typed. Second to where you must reach after you type the command.
So, get to co-ordinates. I am oping the position of 4 dragons casino and the interior of it.
The co-ordinates are :
Код:
2019.3992,1007.7200,10.8203 // Enter point
2015.4500,1017.0900,996.8750 // Reaching point
Now we have to define the ENTER point to one universal/global Float value.
Код:
new Float:Enter[][] =
{
//This will be our base.
};
Now let us define the co-ordinate.
Код:
new Float:Enter[][] =
{
    {2019.3992,1007.7200,10.8203}
};
Now we will start making our command.

Step 2

COMMAND, our command will be enter. I will use ZCMD here.

Код:
CMD:enter(playerid,params[])
{
        return 1;
}
This is our command base.
As this will be a loop from our global value of enter, we will use for loop.
Код:
CMD:enter(playerid,params[])
{
	for(new i = 0; i < sizeof(Enter);i++)
	{
        
	}
	return 1;
}
It is clear of what's done above. We will go forward now.
For making the command only to be used at the ENTER points. We will use Range Point.
So, we go further adding the condition that if the player is at the enter point he can use the command orelse he/she will receive a message.
Код:
CMD:enter(playerid,params[])
{
	for(new i = 0; i < sizeof(Enter);i++)
	{
        if(IsPlayerInRangeOfPoint(playerid,1.0,Enter[i][0],Enter[i][1], Enter[i][2])) // IF the player is in range of any of the enter points the command goes true. 
        {

        }
        else SendClientMessage(playerid,colorexit,"[ ! ] You must be near a valid enter point!");//If he is not then he will receive this message.
	}
	return 1;
}
Now as we have to define each of the co-ordinates a spawning point, we will use switch case here.
We will switch cases of the global enter value. Remember the first value will start from 0 in our codes. We can change it to start from 1 if we want.
So, the codes for the switch case would be as follow :
Код:
CMD:enter(playerid,params[])
{
	for(new i = 0; i < sizeof(Enter);i++)
	{
        if(IsPlayerInRangeOfPoint(playerid,1.0,Enter[i][0],Enter[i][1], Enter[i][2]))
        {
			switch(i) //Switching cases of ENTER point.
			{

			}

        }
        else SendClientMessage(playerid,colorexit,"[ ! ] You must be near a valid enter point!");
	}
	return 1;
}
Now our final last task. Our co-ordinates of ENTER point is in 0. So, our case would be 0.
Код:
CMD:enter(playerid,params[])
{
	for(new i = 0; i < sizeof(Enter);i++)
	{
        if(IsPlayerInRangeOfPoint(playerid,1.0,Enter[i][0],Enter[i][1], Enter[i][2]))
        {
			switch(i)
			{
			    case 0:
			    {
			    	SetPlayerInterior(playerid,10); // Interior of casino it can be checked by pressing /interior when you are inside any interior
			        SetPlayerPos(playerid,2015.4500,1017.0900,996.8750);// Position of the casino interior where the player will be spawned.
			        SetPlayerFacingAngle(playerid,90.0000);// Facing angle of the player.
			    }
			}
        
        }
        else SendClientMessage(playerid,colorexit,"[ ! ] You must be near a valid enter point!");
	}
	return 1;
}
Now the player will spawn at the point.
This was how we have learnt to make an ENTER command. The exit commands goes the same. So, you may try making an EXIT command to learn these codes.

Thank you. I have tried my best to explain it. Please let me know if there are any bugs/glitches/errors. And any easy method of things. I welcome your comments.

- John_Blaze ( WSRPG )
Reply
#2

Nice tut, simple and easy

Just try to edit the thread and add some colors to it to make it more readable and enjoyable
Reply
#3

Nice tutorial.
Reply
#4

Quote:
Originally Posted by fuckingcruse
Посмотреть сообщение
Nice tutorial.
I saw that 'thanks'. Forgot to switch accounts?
Reply
#5

Quote:
Originally Posted by AndySedeyn
Посмотреть сообщение
I saw that 'thanks'. Forgot to switch accounts?
Its my friends acc. ( john blaze ) so I said thanks then later I remember he said me not to do so. Even this acc was given to me by him. As I couldn't get an acc.
Reply
#6

I am getting error, sorry i can't figure it out

PHP код:
(321) : error 032: array index out of bounds (variable "gRange"
PHP код:
for(new 0sizeof(gRange);i++)

Line 321 :
PHP код:
if(IsPlayerInRangeOfPoint(playerid,5.0,gRange[i][0],gRange[i][1],gRange[i][2],gRange[i][3],gRange[i][4])) 
PHP код:
new Float:gRange[][] =
{
    {
141.04659,1970.46704,21.30360},
    {
141.89529,1963.32434,18.85600},
    {
213.60159,1850.90369,12.89270},
    {
256.99011,1845.92261,9.53800},
    {
248.82294,1842.09045,9.00760}
}; 
Reply
#7

IsPlayerInRangeOfPoint has only 5 arguments and not 7!:
PHP код:
IsPlayerInRangeOfPoint(playeridFloat:radiusFloat:xFloat:yFloat:z); 
You've declared the array to have an unknown amount of indexes (you resolve the unknown part by creating the indexes yourself) and with an unknown amount of sub-indexes. This seems very redundant since the purpose limits you to have only 3 values. Thus, gRange can only have 3 values:
Код:
X-coordinate
Y-coordinate
Z-coordinate
A player's position can have 4 coordinates (including facing angle):
Код:
X-coordinate
Y-coordinate
Z-coordinate
A-coordinate
But why would you need the facing angle for IsPlayerInRangeOfPoint? The function doesn't even accept it as an argument. So, to fix your problem:

PHP код:
new Float:gRange[][3] = 

    {
141.04659,1970.46704,21.30360}, 
    {
141.89529,1963.32434,18.85600}, 
    {
213.60159,1850.90369,12.89270}, 
    {
256.99011,1845.92261,9.53800}, 
    {
248.82294,1842.09045,9.00760
};
// This has to be in your loop:
if(IsPlayerInRangeOfPoint(playerid5.0gRange[i][0], gRange[i][1], gRange[i][2])) 
Reply
#8

Alright thanks, well explained
But does it means i can't use more that 3 gRange in that IsPlayerInRangeOfPoint? Because now i need 5 and i will use more than 5 later on.
Reply
#9

Why do you need 5?
Reply
#10

I mean doesn't this each line need to be filled in as gRange[i][0-4]?
PHP код:
new Float:gRange[][] =
{
    {
141.04659,1970.46704,21.30360},
    {
141.89529,1963.32434,18.85600},
    {
213.60159,1850.90369,12.89270},
    {
256.99011,1845.92261,9.53800},
    {
248.82294,1842.09045,9.00760}
}; 
Anyways, it does work with 3rd and 4th where i am confused xD

So i assume these means if I make even 20 of those float coordinates I only need fill x,y,z in IsPlayerInRangeOfPoint with gRange[i][0-2]
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)