GTA-SAMP
Каталог статей

Меню сайта

Категории раздела

Мини-чат

Статистика


Онлайн всего: 1
Гостей: 1
Пользователей: 0

Делаем командный deathmatch.
Делаем командный deathmatch.
ТЕПЕРЬ Вы знаете как делать классы и устанавливать группы. Используем два класса. Классы перечислены в порядке от 0, так что первый класс в вашем файле - 0, второй - 1 и так далее. Мы установим две банды и выбираемые скины к ним(GROVE и BALLA), Вы можете посмотреть на возвраты и думать, что это войдет в функцию OnPlayerRequestClass, и Вы будете правы. Сначала нам нужно определять наши банды, под линией "# include"() вверху вашего файла добавлям эти линии:

#define TEAM_GROVE 1
#define TEAM_BALLA 2
#define TEAM_GROVE_COLOR 0x00FF00AA //Ярко зелёный
#define TEAM_BALLA_COLOR 0xFF00FFAA //Ярко пурпурный

Если вы захотите использовать число 1 в вашем сценарии вместо TEAM_GROVE, так как это упрощает вычисления и более понятно! Для того что бы заменить названия банд на цифры необходима некая константа. Под теми строками, добавьте:

new gTeam[MAX_PLAYERS];

Теперь мы можем установить группы:

public SetPlayerTeamFromClass(playerid, classid)
{
if (classid == 0)
{
gTeam[playerid] = TEAM_GROVE;
}
else
{
gTeam[playerid] = TEAM_BALLA;
}
}
Place that code OUTSIDE a function in your code (as it is a new function) and put these lines as the first things after the open curly braces in your OnPlayerRequestClass callback (notice the way the variables are not global so we are having to pass them to out function too):
SetPlayerTeamFromClass(playerid, classid);
This will save the players team to an array through our new function. Data in an array is referenced by a number, so array[0] is the first item of data, array[1] is the second and so on, as we are using gTeam[playerid], depending on which playerid we are passed will define where in the array to store the data, so for player 5 their data will be stored at array position 5 (remember, this is the 6th piece of data). Now copy this function:
public SetPlayerToTeamColor(playerid)
{
if (gTeam[playerid] == TEAM_GROVE)
{
SetPlayerColor(playerid, TEAM_GROVE_COLOR);
}
else if (gTeam[playerid] == TEAM_BALLA)
{
SetPlayerColor(playerid, TEAM_BALLA_COLOR);
}
}
And add the following line to OnPlayerSpawn:
SetPlayerToTeamColor(playerid);
We now have our teams, but what have we actually done?
if (classid == 0)
{
gTeam[playerid] = TEAM_GROVE;
}
In our first function, we check which class they chose (remember we said that the first class defined in your file was class 0?) "==" means "is equal to", a single equals sign simply sets the variable to the number given (as seen on the next line but one). The curly braces sepparate the functions between them from the rest of the code, bits in there are only executed if the selected class is 0 (cj), if it isn't, the else command comes into play and executes insted (this executes whenever the "if" command is false (i.e. the class isn't 0)), since we only have two classes to choose from this must mean we're Balla:
else
{
gTeam[playerid] = TEAM_BALLA;
}
We don't need a return here as there is no data to return.
The second half set the players' color when they spawn, so you can tell who's on which team. As we saved their team to a global array, we can still access the data even though it is in a separate function.
if (gTeam[playerid] == TEAM_GROVE)
{
SetPlayerColor(playerid, TEAM_GROVE_COLOR);
}
Hopefully you can see what this is doing now, if the player who just spawned (as referenced by playerid) is in TEAM_GROVE, we set their color to TEAM_GROVEs color.
else if (gTeam[playerid] == TEAM_BALLA)
{
SetPlayerColor(playerid, TEAM_BALLA_COLOR);
}
This next section is a little different, it could easilly have been done like this:
else
{
SetPlayerColor(playerid, TEAM_BALLA_COLOR);
}
But the way it is done allows you to set their color to TEAM_BALLAs color only if the first part is false (as sorted by the ELSE) AND if they are in TEAM_BALLA, this allows you to add more options by adding more "else if ()" blocks to the end as one will only be executed if all the blocks before it weren't.

Категория: Мои статьи | Добавил: Alecsey (28.12.2008)
Просмотров: 406 | Комментарии: 1
Всего комментариев: 0
Имя *:
Email *:
Код *:

Вход на сайт

Поиск