Добро пожаловать на Pro Pawn - Портал о PAWN-скриптинге.
Показано с 1 по 3 из 3
  1. #1
    Аватар для alexei
    Пользователь

    Статус
    Оффлайн
    Регистрация
    20.08.2020
    Сообщений
    9
    Репутация:
    0 ±

    При выходе из зоны не убавляется количество игроков

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

    Код
    PHP код:
    new
        
    gDeathMatchZone[MAX_PLAYERS], // ID DeathMatch зон
        
    gOnlineDeathMatchZone[4// DeathMatch арена (кол-во игроков)
    ;
    static const 
    FloatgSpawnDeathMatchStadium[][] =
    {
        {
    1403.98102202.129217.6719},
        {
    1394.25202168.15949.7578},
        {
    1369.95782195.69099.7578},
        {
    1312.57322115.978011.0156},
        {
    1357.48772212.200012.0156},
        {
    1410.15442119.032012.0156},
        {
    1300.57202211.734618.5391}
    };
    static const 
    FloatgSpawnDeathMatchFactory[][] =
    {
        {-
    2184.0859, -262.969340.7195},
        {-
    2142.1843, -248.831736.5156},
        {-
    2184.1150, -248.247440.7195},
        {-
    2145.3604, -230.724236.5156},
        {-
    2178.4109, -223.861236.5156},
        {-
    2185.8975, -209.653236.5156},
        {-
    2170.8496, -232.858436.5156}
    };
    static const 
    FloatgSpawnDeathMatchMountains[][] =
    {
        {-
    1132.53381022.84771345.7262},
        {-
    974.61901076.76651344.9867},
        {-
    989.91351024.61501341.8586},
        {-
    1023.84241054.43591342.8473},
        {-
    1068.27171092.02841343.2631},
        {-
    1092.83411036.08831343.2296},
        {-
    1131.39071057.43331346.4139}
    };
    static const 
    FloatgSpawnDeathMatchVillage[][] =
    {
        {
    1118.0991, -301.104773.9922},
        {
    1106.0769, -325.115073.9922},
        {
    1114.5728, -349.346873.9851},
        {
    1066.4485, -344.315273.9922},
        {
    1013.7222, -284.028673.9889},
        {
    1050.0624, -287.435873.9931}
    };

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

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

                   
    ResetPlayerWeapons(playerid);
                   
    SetPlayerHealth(playerid100);

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

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

                
    ShowPlayerDialogEx(playeridDIALOG_SELECT_GUN_ONEDIALOG_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(playerid100);

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

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

                
    ShowPlayerDialogEx(playeridDIALOG_SELECT_GUN_ONEDIALOG_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(playerid100);

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

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

                
    ShowPlayerDialogEx(playeridDIALOG_SELECT_GUN_ONEDIALOG_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(playerid100);

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

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

                
    ShowPlayerDialogEx(playeridDIALOG_SELECT_GUN_ONEDIALOG_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(playeridCOLOR_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(playeridCOLOR_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(playeridCOLOR_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(playeridCOLOR_WHITE, !"Вы заспавнились в 4 зоне.");
                }
            }
            return 
    1;
        }
        return 
    1;
    }
    public 
    OnPlayerDisconnect(playerid)
    {
        
    gDeathMatchZone[playerid] = 0;
        
    gOnlineDeagleMatchZoneID(playerid);
        return 
    1;
    }
    stock gOnlineDeathMatchZoneID(playerid)
    {
        switch(
    gDeathMatchZone[playerid] == 1)
        {
            case 
    1gOnlineDeathMatchZone[0]--;
            case 
    2gOnlineDeathMatchZone[1]--;
            case 
    3gOnlineDeathMatchZone[2]--;
            case 
    4gOnlineDeathMatchZone[3]--;
        }
    }
    CMD:dm(playeridparams[])
    {
        if(
    gDeathMatchZone[playerid] == 1)
            return 
    SendClientMessage(playerid, -1, !"Покиньте режим DeathMatch, используя команду {ffff00}/exit");

        new
            
    string[91 + (- 8)]
        ;
        
    format(stringsizeof(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(playeridDIALOG_DEATHMATCH_ARENADIALOG_STYLE_LIST,
            !
    "{ffff00}Выбор локации",
            
    string,
            !
    "Выбрать", !"Закрыть"
        
    );
        return 
    1;
    }
    CMD:exit(playerid)
    {
        if(
    gDeathMatchZone[playerid] == 0)
            return 
    SendClientMessage(playeridCOLOR_WARNING, !"Вы не находитесь в режиме DeathMatch/Deagle.");

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

        
    ResetPlayerWeapons(playerid);
        
    SetPlayerHealth(playerid100.0);

        
    SpawnPlayer(playerid);
        return 
    1;

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

  2. #2
    Аватар для Pa4enka
    Пользователь

    Статус
    Оффлайн
    Регистрация
    22.04.2016
    Адрес
    Украина
    Сообщений
    157
    Репутация:
    35 ±
    Во-первых, что за синтаксис 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. Соответственно, свитч просто не выполнится.

  3. #3
    Аватар для alexei
    Пользователь

    Статус
    Оффлайн
    Регистрация
    20.08.2020
    Сообщений
    9
    Репутация:
    0 ±
    Проблема решена, спасибо

 

 

Информация о теме

Пользователи, просматривающие эту тему

Эту тему просматривают: 1 (пользователей: 0 , гостей: 1)

Ваши права

  • Вы не можете создавать новые темы
  • Вы не можете отвечать в темах
  • Вы не можете прикреплять вложения
  • Вы не можете редактировать свои сообщения
  •