26.01.2011, 03:46
(
Последний раз редактировалось kin; 26.01.2011 в 21:47.
Причина: Fixing some mistakes
)
Hello everyone, welcome to my first tutorial on this account. Before i start i want to say just one thing, the methods i use may not be up to date, or they may not be the simplest way. I am teaching you, the SA-MP community, how to create a basic mini game base. This is more for learning purposes then to create a mini game, indeed we are making one, but i want you to learn from it and one day be able to create a more advanced mini game for your servers.Introduction
In this tutorial i will be teaching you how to create a simple DM mini game base, i will be using the following techniques in this tutorial:Creating Player Values, Setting It Up
If you do not own the dcmd define i will provide it to you now.
- dcmd
- player values
With that we can start learning how to make a simple mini game.pawn Код:#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
NOTE: This mini game is just a base, so the spawn position will be only one coordinate, you can change it up when you make the mini game.
Before we can get started on making the mini game base, we will need to make some player values that will setup the player and allow them to play the mini game. First we will have to create a way to save/check if the player is in a mini game, we do this by creating a new variable and storing a special value in it.Command Creation Unit
Explanation:pawn Код:new IsInMini[MAX_PLAYERS];
This line creates a new variable called "IsInMini" and stores a special value, this value is MAX_PLAYERS. As indicated MAX_PLAYERS means the max players the server at max can hold regarding the SA Limits. You will understand the use of this a bit later in the tutorial, but for now just ignore it.
Now we want the server to get the players name right? We will achieve this by creating yet another variable, and we will place this just below the #include <samp>.
Explanation:pawn Код:new name[129]
This line is used to store the value of the players name, if you haven noticed yet, their is a weird block of numbers next to the word name, this is called an array. I will not get into this in this tutorial, in fact their is a tutorial on the forums explaining arrays, i will put a link at the end of the tutorial so you can veiw it. Anyways lets get back on topic, the reason we are using this is because we want it to store the players name we achieve this by creating an array, you probably noticed the 129 next to name, basically this means the array can carry 128 characters(Cells). You are probably wonder why 128 when it has 129, its 128 because, for every array you need to have one spare cell for a null or in other words, a " ", or 0. We will use this array in a function that lets us retrieve the players name easily.
Explanation:pawn Код:GetPlayerName(playerid,const string[],len);
This is the basic outline of the function, it will retrieve the players id, then it will store the name in the array we created earlier. Then we get the size of the array using, sizeof(). This is basically self explainable so i will not go into serious depth with it. Now we have all the basic variables needed to start our mini game.
Substituted with our information:
we will place this in our command so that when a player uses the command to join it instantly retrieves the players name, and we can use it to display that the player connected.pawn Код:GetPlayerName(playerid,name,sizeof(name));
[INDENT]In this section we will be creating the command that allows the player to join the mini game, we will be using dcmd to create it, just so you can get used to
dcmd's structure. We will start off by creating the basic layout of the cmd
pawn Код:
dcmd_mini(playerid,params[])
{
GetPlayerName(playerid,name,sizeof(name));
new msg[129];
IsInMini[playerid] = 1;
format(msg,sizeof(msg),"%s has joined the mini game!",name);
return 1;
}
Here we created a new array called msg and set the size to 129 like we did before, you can set this number to anything more than the length of the message plus one.
Then we formated the message using format
pawn Код:
format(output[], len, const string[], float{}....);
len = the size of the array
cont string = the text we want to format, SPECIAL CHARACTERS: %s = string, %d = single number, %i = integer, %% = regular %.
float = what every you want the special characters to say, This can be virtually anything.
in our case we made the message display "(PLAYERSNAME) has joined the mini game". Players name will be substituted by the player that typed the command.
next we will have to make it display the message, we can achieve this by using
pawn Код:
SendClientMessageToAll(playerid,const string[]);
This basically will send a message to every player playing on the server.
so our code so far should look like this:
pawn Код:
dcmd_mini(playerid,params[])
{
GetPlayerName(playerid,name,sizeof(name));
new msg[129];
IsInMini[playerid] = 1;
format(msg,sizeof(msg),"%s has joined the mini game!",name);
SendClientMessageToAll(playerid,msg);
return 1;
}
Now we want to put the player in a different world so they dont get disturbed while playing, we also want them to spawn at the correct positions. We achieve this by
using 2 functions,
pawn Код:
SetPlayerPos(playerid,1958.3783, 1343.1572, 15.3746);
pawn Код:
SetPlayerVirtualWorld(playerid,50);
choose from. So be creative and use your own.
Our code should look like this now:
pawn Код:
dcmd_mini(playerid,params[])
{
new msg[129];
IsInMini[playerid] = 1;
format(msg,sizeof(msg),"%s has joined the mini game!",name);
SendClientMessageToAll(playerid,msg);
SetPlayerPos(playerid,1958.3783, 1343.1572, 15.3746);
SetPlayerVirtualWorld(playerid,50);
return 1;
}
value of IsInMini to 0.
and return them back to world 0
pawn Код:
dcmd_exit(playerid,params[])
{
IsInMini[playerid] = 0;
SetPlayerVirtualWorld(playerid,0);
return 1;
}
Note: you will have to put the dcmd function in your onplayercommandtext call back, what i mean is, you will have to put this into that call back:
pawn Код:
dcmd(mini,4,cmdtext);
dcmd(exit,4,cmdtext);
This will enable the function to be able to be treated like a command, it basically is setup like this
pawn Код:
dcmd(name of the command created, the size of the command, and cmdtext to tell SA its a command);
Now its time to create what happens when a player dies :P
Finishing Touches
Now its the final moment, the finishing touches, in this section we will be creating what happens when the player dies if their in the mini game.
We will do this by checking if they are in the mini game, and if they are it will spawn them back at the spawn location, and make the killer gain one dollar each kill, and it will display who has died, and who killed them. I will put this in a bulk since i am getting a little to close to the limit i believe, if there is one.
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
new killer[129],killed[129];
GetPlayerName(killerid,killer,sizeof(killer));
GetPlayerName(playerid,killed,sizeof(killed));
if(IsInMini[playerid] == 1)
{
new killmsg[129];
format(killmsg,sizeof(killmsg),"%s has killed %s",killer,killed);
SendClientMessageToAll(0xFFF000FF,killmsg);
GivePlayerMoney(killerid,1);
}
return 1;
}
This just basically sends a message to everyone saying someone killed someone, and gives the killer 1 dollar, you can change the amount. If they are not in the minigame it does nothing.
Thats about it, hope this tutorial helped you learn how to create a simple mini game. Thank you for reading this, hope you have a great day/night/evening.
Tips
- You can add more things to what the player earns just by adding another function of your choice to the death portion.
- If you get an error like so: (252) : warning 203: symbol is never used: "params", just do #pragma unused params in bothe of the commands
NOTE: If you find any errors in the script post them here, i compiled it and it compiled with two errors, this is told how to be fixed in the tips section, also if you find anything wrong with the tutorial please tell me, something happened with it when i was almost done and i had to put it back together. So things might sound weird to you, if they do tell me.
Thanks again for reading this and i hope you enjoyed it