22.12.2013, 22:55
Hi, in this tutorial you will learn:
- How to use cases command
- How to develop/upgrade them.
- How to use range function.
Before going on, I wont explain how to create the Christmas box, since that's only a creation of object in the coordinates you get by /save in-game.
So, let's start over.
In order to get cases, we must make a function that will go through those cases and will stop on a random one. To do this, we must define this function on top of our script (Under includes part):
That's it, we are done with the top of the script. Was that hard? Not huh?...
Now let's move over. In my case, I'm going to use zCMD include, so, on top of the script you must include it.
Till now we got this code:
Now we are going to the part of creating the command for our system. First of all, we create the command without adding any function on it. The conclusion must be something like this:
Now, after we have created the command, we must remove the "//code here" part, so we can put the functions that are going to be ran when we use the command.
We shall see if the player is in range of the gift place, so we are going to use the "IsPlayerInRangeOfPoint" function. Let's see below how it will seem:
Now, let me explain what those parameters stand for.
"playerid" => This stands for the ID of player. With it you can define to who the command is working, in our case, the command will work for the player that is using it.
"Range" => Range stands for the range that the player is from the coordinates.
"X" => Stands for the X location of user.
"Y" => Stands for the Y location of user.
"Z" => Stands for the Z location of user.
Let's go further to the tutorial. Now we must define the cases and the random function also. The plain text without command will be something like this:
Each of those cases will be filled with our functions. Let's add this part of code to our command.
If you want to proceed by your self, this is the progress of our script till now:
Now, let's add some gifts for our users.
Now that we added the command, the conclusion of this will be something like this:
You can also add more features by your self and add more gifts for the user. This is a simple tutorial where you can start off from your huge ideas about Christmas! This is my first tutorial, so please do not think bad about me
Cheers!
- How to use cases command
- How to develop/upgrade them.
- How to use range function.
Before going on, I wont explain how to create the Christmas box, since that's only a creation of object in the coordinates you get by /save in-game.
So, let's start over.
In order to get cases, we must make a function that will go through those cases and will stop on a random one. To do this, we must define this function on top of our script (Under includes part):
pawn Код:
new Random;
Now let's move over. In my case, I'm going to use zCMD include, so, on top of the script you must include it.
pawn Код:
#include <zcmd>
pawn Код:
#include <a_samp>
#include <zcmd>
new Random;
pawn Код:
COMMAND:gifts(playerid, params[])
{
// code here
return 1;
}
We shall see if the player is in range of the gift place, so we are going to use the "IsPlayerInRangeOfPoint" function. Let's see below how it will seem:
pawn Код:
COMMAND:gifts(playerid, params[])
{
if(IsPlayerInRangeOfPoint(playerid, Range, X, Y, Z))
{
// Code here
}
return 1;
}
"playerid" => This stands for the ID of player. With it you can define to who the command is working, in our case, the command will work for the player that is using it.
"Range" => Range stands for the range that the player is from the coordinates.
"X" => Stands for the X location of user.
"Y" => Stands for the Y location of user.
"Z" => Stands for the Z location of user.
Let's go further to the tutorial. Now we must define the cases and the random function also. The plain text without command will be something like this:
pawn Код:
Random = random(3);
switch(Random)
{
case 0:
case 1:
case 2:
}
pawn Код:
COMMAND:gifts(playerid, params[])
{
if(IsPlayerInRangeOfPoint(playerid, Range, X, Y, Z))
{
Random = random(3);
switch(Random)
{
case 0:
case 1:
case 2:
}
}
return 1;
}
pawn Код:
#include <a_samp>
#include <zcmd>
new Random;
public OnFilterScriptInIt()
{
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
COMMAND:gifts(playerid, params[])
{
if(IsPlayerInRangeOfPoint(playerid, Range, X, Y, Z))
{
Random = random(3);
switch(Random)
{
case 0:
case 1:
case 2:
}
}
return 1;
}
pawn Код:
COMMAND:gifts(playerid, params[])
{
if(IsPlayerInRangeOfPoint(playerid, Range, X, Y, Z))
{
Random = random(3);
switch(Random)
{
case 0: // Let's add cash!
{
GivePlayerCash(playerid, 5000);
SendClientMessage(playerid, -1, "Santa Claus gifted you 5000$. Merry Christmas!");
}
case 1: // Let's add some score to the user!
{
SetPlayerScore(playerid, GetPlayerScore(playerid)+15);
SendClientMessage(playerid, -1, "Santa Claus gifted you 15 score. Merry Christmas!");
}
case 2: // Let's gift him nothing, he was a bad boy this year.
{
SendClientMessage(playerid, -1, "You were in Santa Claus blacklist and he didn't even pass over your house. Be a good guy next year");
}
}
}
return 1;
}
pawn Код:
#include <a_samp>
#include <zcmd>
new Random;
public OnFilterScriptInIt()
{
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
COMMAND:gifts(playerid, params[])
{
if(IsPlayerInRangeOfPoint(playerid, Range, X, Y, Z))
{
Random = random(3);
switch(Random)
{
case 0: // Let's add cash!
{
GivePlayerCash(playerid, 5000);
SendClientMessage(playerid, -1, "Santa Claus gifted you 5000$. Merry Christmas!");
}
case 1: // Let's add some score to the user!
{
SetPlayerScore(playerid, GetPlayerScore(playerid)+15);
SendClientMessage(playerid, -1, "Santa Claus gifted you 15 score. Merry Christmas!");
}
case 2: // Let's gift him nothing, he was a bad boy this year.
{
SendClientMessage(playerid, -1, "You were in Santa Claus blacklist and he didn't even pass over your house. Be a good guy next year");
}
}
}
return 1;
}
Cheers!