PDA

Просмотр полной версии : [Вопрос] При выходе из зоны не убавляется количество игроков



alexei
25.03.2021, 21:05
Добрый вечер!
Решил написать систему DM/deagle зон для своего DM сервера.
Только только осваиваю АЗЫ Pawn и наткнулся на такую проблемку с подсчётом игроков в этих самых зонах
Не предлагайте варианты с использованием итераторов, т.к я не умею ими пользоваться :D

Код


new
gDeathMatchZone[MAX_PLAYERS], // ID DeathMatch зон
gOnlineDeathMatchZone[4] // DeathMatch арена (кол-во игроков)
;
static const Float: gSpawnDeathMatchStadium[][] =
{
{1403.9810, 2202.1292, 17.6719},
{1394.2520, 2168.1594, 9.7578},
{1369.9578, 2195.6909, 9.7578},
{1312.5732, 2115.9780, 11.0156},
{1357.4877, 2212.2000, 12.0156},
{1410.1544, 2119.0320, 12.0156},
{1300.5720, 2211.7346, 18.5391}
};
static const Float: gSpawnDeathMatchFactory[][] =
{
{-2184.0859, -262.9693, 40.7195},
{-2142.1843, -248.8317, 36.5156},
{-2184.1150, -248.2474, 40.7195},
{-2145.3604, -230.7242, 36.5156},
{-2178.4109, -223.8612, 36.5156},
{-2185.8975, -209.6532, 36.5156},
{-2170.8496, -232.8584, 36.5156}
};
static const Float: gSpawnDeathMatchMountains[][] =
{
{-1132.5338, 1022.8477, 1345.7262},
{-974.6190, 1076.7665, 1344.9867},
{-989.9135, 1024.6150, 1341.8586},
{-1023.8424, 1054.4359, 1342.8473},
{-1068.2717, 1092.0284, 1343.2631},
{-1092.8341, 1036.0883, 1343.2296},
{-1131.3907, 1057.4333, 1346.4139}
};
static const Float: gSpawnDeathMatchVillage[][] =
{
{1118.0991, -301.1047, 73.9922},
{1106.0769, -325.1150, 73.9922},
{1114.5728, -349.3468, 73.9851},
{1066.4485, -344.3152, 73.9922},
{1013.7222, -284.0286, 73.9889},
{1050.0624, -287.4358, 73.9931}
};

case DIALOG_DEATHMATCH_ARENA:
{
if(!response)
return 1;

switch(listitem)
{
case 0:
{
gDeathMatchZone[playerid] = 1;
gOnlineDeathMatchZone[0]++;

ResetPlayerWeapons(playerid);
SetPlayerHealth(playerid, 100);

new
rand = random(sizeof(gSpawnDeathMatchStadium))
;
fun_IntoInterior(playerid,
gSpawnDeathMatchStadium[rand][0],
gSpawnDeathMatchStadium[rand][1],
gSpawnDeathMatchStadium[rand][2],
0,
0,
1
);
new
string[82 + (- 6 + MAX_PLAYER_NAME + MAX_LENGTH_ID_PLAYER + 2)]
;
format(string, sizeof(string),
"Игрок %s[%d] телепортировался на \"Стадион\" (/dm) [Онлайн: {ffff00}%d{ffffff}]",
PlayerInfo[playerid][pName],
playerid,
gOnlineDeathMatchZone[0]
);
fun_SendClientMessageToAllAren(-1, string);

SendClientMessage(playerid, -1, !"Чтобы выйти с арены, используйте команду {ffff00}/exit");
GameTextForPlayer(playerid, "~r~Welcome~n~~g~Stadium", 3000, 1);

ShowPlayerDialogEx(playerid, DIALOG_SELECT_GUN_ONE, DIALOG_STYLE_LIST,
!"{ffff00}Выбор оружия №1",
!"1) MP5\n2) AK-47\n3) M4A1\n4) Deagle\n5) Sniper Rifle\n6) Shotgun",
!"Выбрать", ""
);
}
case 1:
{
gDeathMatchZone[playerid] = 2;
gOnlineDeathMatchZone[1]++;

ResetPlayerWeapons(playerid);
SetPlayerHealth(playerid, 100);

new
rand = random(sizeof(gSpawnDeathMatchFactory))
;
fun_IntoInterior(playerid,
gSpawnDeathMatchFactory[rand][0],
gSpawnDeathMatchFactory[rand][1],
gSpawnDeathMatchFactory[rand][2],
0,
0,
1
);
new
string[78 + (- 6 + MAX_PLAYER_NAME + MAX_LENGTH_ID_PLAYER + 2)]
;
format(string, sizeof(string),
"Игрок %s[%d] телепортировался на \"Завод\" (/dm) [Онлайн: {ffff00}%d{ffffff}]",
PlayerInfo[playerid][pName],
playerid,
gOnlineDeathMatchZone[1]
);
fun_SendClientMessageToAllAren(-1, string);

SendClientMessage(playerid, -1, !"Чтобы выйти с арены, используйте команду {ffff00}/exit");
GameTextForPlayer(playerid, "~r~Welcome~n~~g~Factory", 3000, 1);

ShowPlayerDialogEx(playerid, DIALOG_SELECT_GUN_ONE, DIALOG_STYLE_LIST,
!"{ffff00}Выбор оружия №1",
!"1) MP5\n2) AK-47\n3) M4A1\n4) Deagle\n5) Sniper Rifle\n6) Shotgun",
!"Выбрать", ""
);
}
case 2:
{
gDeathMatchZone[playerid] = 3;
gOnlineDeathMatchZone[2]++;

ResetPlayerWeapons(playerid);
SetPlayerHealth(playerid, 100);

new
rand = random(sizeof(gSpawnDeathMatchMountains))
;
fun_IntoInterior(playerid,
gSpawnDeathMatchMountains[rand][0],
gSpawnDeathMatchMountains[rand][1],
gSpawnDeathMatchMountains[rand][2],
0,
10,
1
);
new
string[77 + (- 6 + MAX_PLAYER_NAME + MAX_LENGTH_ID_PLAYER + 2)]
;
format(string, sizeof(string),
"Игрок %s[%d] телепортировался на \"Горы\" (/dm) [Онлайн: {ffff00}%d{ffffff}]",
PlayerInfo[playerid][pName],
playerid,
gOnlineDeathMatchZone[2]
);
fun_SendClientMessageToAllAren(-1, string);

SendClientMessage(playerid, -1, !"Чтобы выйти с арены, используйте команду {ffff00}/exit");
GameTextForPlayer(playerid, "~r~Welcome~n~~g~Mountains", 3000, 1);

ShowPlayerDialogEx(playerid, DIALOG_SELECT_GUN_ONE, DIALOG_STYLE_LIST,
!"{ffff00}Выбор оружия №1",
!"1) MP5\n2) AK-47\n3) M4A1\n4) Deagle\n5) Sniper Rifle\n6) Shotgun",
!"Выбрать", ""
);
}
case 3:
{
gDeathMatchZone[playerid] = 4;
gOnlineDeathMatchZone[3]++;

ResetPlayerWeapons(playerid);
SetPlayerHealth(playerid, 100);

new
rand = random(sizeof(gSpawnDeathMatchVillage))
;
fun_IntoInterior(playerid,
gSpawnDeathMatchVillage[rand][0],
gSpawnDeathMatchVillage[rand][1],
gSpawnDeathMatchVillage[rand][2],
0,
0,
1
);
new
string[82 + (- 6 + MAX_PLAYER_NAME + MAX_LENGTH_ID_PLAYER + 2)]
;
format(string, sizeof(string),
"Игрок %s[%d] телепортировался на \"Деревня\" (/dm) [Онлайн: {ffff00}%d{ffffff}]",
PlayerInfo[playerid][pName],
playerid,
gOnlineDeathMatchZone[3]
);
fun_SendClientMessageToAllAren(-1, string);

SendClientMessage(playerid, -1, !"Чтобы выйти с арены, используйте команду {ffff00}/exit");
GameTextForPlayer(playerid, "~r~Welcome~n~~g~Village", 3000, 1);

ShowPlayerDialogEx(playerid, DIALOG_SELECT_GUN_ONE, DIALOG_STYLE_LIST,
!"{ffff00}Выбор оружия №1",
!"1) MP5\n2) AK-47\n3) M4A1\n4) Deagle\n5) Sniper Rifle\n6) Shotgun",
!"Выбрать", ""
);
}
}
return 1;
}
public OnPlayerSpawn(playerid)
{
if(gDeathMatchZone[playerid])
{
//IssuingStoredWeapons(playerid); здесь я выдаю оружие, выбранное игроком при телепорте в опред. зону

switch(gDeathMatchZone[playerid])
{
case 1:
{
new
rand = random(sizeof(gSpawnDeathMatchStadium))
;
fun_IntoInterior(playerid,
gSpawnDeathMatchStadium[rand][0],
gSpawnDeathMatchStadium[rand][1],
gSpawnDeathMatchStadium[rand][2],
0,
0,
1
);
SendClientMessage(playerid, COLOR_WHITE, !"Вы заспавнились в 1 зоне.");
}
case 2:
{
new
rand = random(sizeof(gSpawnDeathMatchFactory))
;
fun_IntoInterior(playerid,
gSpawnDeathMatchFactory[rand][0],
gSpawnDeathMatchFactory[rand][1],
gSpawnDeathMatchFactory[rand][2],
0,
0,
1
);
SendClientMessage(playerid, COLOR_WHITE, !"Вы заспавнились во 2 зоне.");
}
case 3:
{
new
rand = random(sizeof(gSpawnDeathMatchMountains))
;
fun_IntoInterior(playerid,
gSpawnDeathMatchMountains[rand][0],
gSpawnDeathMatchMountains[rand][1],
gSpawnDeathMatchMountains[rand][2],
0,
10,
1
);
SendClientMessage(playerid, COLOR_WHITE, !"Вы заспавнились в 3 зоне.");
}
case 4:
{
new
rand = random(sizeof(gSpawnDeathMatchVillage))
;
fun_IntoInterior(playerid,
gSpawnDeathMatchVillage[rand][0],
gSpawnDeathMatchVillage[rand][1],
gSpawnDeathMatchVillage[rand][2],
0,
0,
1
);
SendClientMessage(playerid, COLOR_WHITE, !"Вы заспавнились в 4 зоне.");
}
}
return 1;
}
return 1;
}
public OnPlayerDisconnect(playerid)
{
gDeathMatchZone[playerid] = 0;
gOnlineDeagleMatchZoneID(playerid);
return 1;
}
stock gOnlineDeathMatchZoneID(playerid)
{
switch(gDeathMatchZone[playerid] == 1)
{
case 1: gOnlineDeathMatchZone[0]--;
case 2: gOnlineDeathMatchZone[1]--;
case 3: gOnlineDeathMatchZone[2]--;
case 4: gOnlineDeathMatchZone[3]--;
}
}
CMD:dm(playerid, params[])
{
if(gDeathMatchZone[playerid] == 1)
return SendClientMessage(playerid, -1, !"Покиньте режим DeathMatch, используя команду {ffff00}/exit");

new
string[91 + (- 8 + 8)]
;
format(string, sizeof(string),
"1. Стадион\t\t%d чел.\n\
2. Завод\t\t%d чел.\n\
3. Горы\t\t\t%d чел.\n\
4. Деревня\t\t%d чел.",
gOnlineDeathMatchZone[0],
gOnlineDeathMatchZone[1],
gOnlineDeathMatchZone[2],
gOnlineDeathMatchZone[3]
);
ShowPlayerDialogEx(playerid, DIALOG_DEATHMATCH_ARENA, DIALOG_STYLE_LIST,
!"{ffff00}Выбор локации",
string,
!"Выбрать", !"Закрыть"
);
return 1;
}
CMD:exit(playerid)
{
if(gDeathMatchZone[playerid] == 0)
return SendClientMessage(playerid, COLOR_WARNING, !"Вы не находитесь в режиме DeathMatch/Deagle.");

gDeathMatchZone[playerid] = 0;
gOnlineDeathMatchZoneID(playerid);

ResetPlayerWeapons(playerid);
SetPlayerHealth(playerid, 100.0);

SpawnPlayer(playerid);
return 1;
}

В завершении может можно как то оптимизировать и сделать иначе из данного кода

Pa4enka
25.03.2021, 21:12
Во-первых, что за синтаксис switch такой интересный?)

stock gOnlineDeathMatchZoneID(playerid)
{
switch(gDeathMatchZone[playerid] == 1) // <==
{
case 1: gOnlineDeathMatchZone[0]--;
case 2: gOnlineDeathMatchZone[1]--;
case 3: gOnlineDeathMatchZone[2]--;
case 4: gOnlineDeathMatchZone[3]--;
}
}

Во-вторых:

gDeathMatchZone[playerid] = 0;
gOnlineDeathMatchZoneID(playerid);
Присвоил переменной 0. Но вызвал сток в котором перечисления начинается с 1. Соответственно, свитч просто не выполнится.

alexei
25.03.2021, 21:36
Проблема решена, спасибо