Взять преступника под конвой - Форум
[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Взять преступника под конвой
AdminДата: Пятница, 13.05.2016, 12:50 | Сообщение # 1
Гл.Администратор
Группа: Пользователи
Сообщений: 65
Награды: 1
Репутация: 32767
Статус: Offline
Это урок по добавлению конвоя на сервер. Я уже видел команды тянуть за собой ну он как бы телепортирует к себе. А Здесь человек взятый под конвой будет идти следом.
Ко всем new добавляем:
Код
new FollowBy[MAX_PLAYERSS];
new TimerForPlayer[MAX_PLAYERSS];

Ко всем #define:
Код
#define MAX_PLAYERSS 330

В public OnPlayerConnect:
Код
TimerForPlayer [playerid]= MAX_PLAYERSS;
FollowBy [playerid]= MAX_PLAYERSS;
SetPVarInt(playerid, "TempFollowBy", -1);

В public OnPlayerDeath:
Код
new GotPVar = GetPVarInt(playerid, "TempFollowBy");
        if(FollowBy [playerid]!= MAX_PLAYERSS)
        {
                SetPVarInt(FollowBy[playerid], "TempFollowBy", -1);
                KillTimer(TimerForPlayer[playerid]);
                SendClientMessage(FollowBy[playerid], COLOR_LIGHTBLUE, "Ваш заключенный мертв");
                TimerForPlayer [playerid]= MAX_PLAYERSS;
                FollowBy [playerid]= MAX_PLAYERSS;
        }
        else if(GotPVar != -1)
        {
                SetPVarInt(playerid, "TempFollowBy", -1);
                KillTimer(TimerForPlayer[GotPVar]);
                SendClientMessage(FollowBy[playerid], COLOR_LIGHTBLUE, "Ваш конвой мертв.");
                TimerForPlayer [GotPVar]= MAX_PLAYERSS;
                FollowBy [GotPVar]= MAX_PLAYERSS;
        }

В public OnPlayerSpawn:
Код
new GotPVar = GetPVarInt(playerid, "TempFollowBy");
        if(FollowBy [playerid]!= MAX_PLAYERSS)
        {
                SetPVarInt(FollowBy[playerid], "TempFollowBy", -1);
                KillTimer(TimerForPlayer[playerid]);
                SendClientMessage(FollowBy[playerid], COLOR_LIGHTBLUE, "Ваш заключенный мертв.");
                TimerForPlayer [playerid]= MAX_PLAYERSS;
                FollowBy [playerid]= MAX_PLAYERSS;
        }

        else if(GotPVar != -1)
        {
                SetPVarInt(playerid, "TempFollowBy", -1);
                KillTimer(TimerForPlayer[GotPVar]);
                SendClientMessage(FollowBy[playerid], COLOR_LIGHTBLUE, "Ваш конвой мертв.");
                TimerForPlayer [GotPVar]= MAX_PLAYERSS;
                FollowBy [GotPVar]= MAX_PLAYERSS;
        }

В public OnPlayerCommandText:
Код
if(strcmp(cmd, "/drag", true) == 0)
        {
        new var[255];
        var = strtok(cmdtext, idx);
        if(!strlen(var)) return SendClientMessage(playerid, 0xAA3333AA, "Вы не ввели имя игрока");
        new gotplayer = strval(var);
        if(IsACop(playerid) || PlayerInfo[playerid] [pMember]== 3 || PlayerInfo[playerid] [pMember]== 7)
        {
        if(playerid == gotplayer) return SendClientMessage(playerid, 0xAA3333AA, "Вы не можите сопровождать самого себя ");
        else if(!IsPlayerConnected(gotplayer)) return SendClientMessage(playerid, 0xAA3333AA, "Такого игрока нет на сервере");
        else if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, 0xAA3333AA, "Вы не можете вести конвой с  машины!");
        else if(FollowBy [playerid]!= MAX_PLAYERSS) return SendClientMessage(playerid, 0xAA3333AA, "Вы не можете взять игрока под конвой, когда сами конвоируетесь!");
        else if(IsPlayerInAnyVehicle(gotplayer)) return SendClientMessage(playerid, 0xAA3333AA, "Вы не можете взять под конвой когда игрок в машине!");
        new Float: X, Float: Y, Float: Z; GetPlayerPos(gotplayer, X, Y, Z);
        if(!IsPlayerInRangeOfPoint(playerid, 1.5, X, Y, Z)) return SendClientMessage(playerid, 0xAA3333AA, "Игрок далеко от вас!");
        else if(FollowBy [gotplayer]!= MAX_PLAYERSS)
        {
                        //if(FollowBy [gotplayer]!= playerid)
        SetPVarInt(playerid, "TempFollowBy", -1);
        FollowBy [gotplayer]= MAX_PLAYERSS;
        KillTimer(TimerForPlayer[gotplayer]);
        TimerForPlayer [gotplayer]= MAX_PLAYERSS;
        ClearAnimations(playerid);
        TogglePlayerControllable(gotplayer, 1);
        SendClientMessage(playerid, 0x33AA33AA, "Вы успешно установили конвой за игроком!");
        return SendClientMessage(gotplayer, 0xFFFF00AA, "С вас был снят конвой!");
        }
        if(GetPVarInt(playerid, "TempFollowBy") != -1) return SendClientMessage(playerid, 0xAA3333AA, "Вы не можете сопровождать больше 2х игроков одновременно!");
        FollowBy [gotplayer]= playerid;
        SetPVarInt(playerid, "TempFollowBy", gotplayer);
        TimerForPlayer [gotplayer]= SetTimerEx("FollowToPlayer", 1000, 1, "i", gotplayer);
        SendClientMessage(playerid, 0x33AA33AA, "Вы успешно начали сопровождение этого игрока!");
        return SendClientMessage(gotplayer, 0xFFFF00AA, "вас взяли под конвой");
        }
        }

В конец мода вне пабликов вставить:
Код
stock SetPlayerToFacePlayer(playerid, targetid)
{
        new
                Float:pX,
                Float:pY,
                Float:pZ,
                Float:X,
                Float:Y,
                Float:Z,
                Float:ang;
        if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
        GetPlayerPos(targetid, X, Y, Z);
        GetPlayerPos(playerid, pX, pY, pZ);
        if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
        else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
        else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
        if(X > pX) ang = (floatabs(floatabs(ang) + 180.0));
        else ang = (floatabs(ang) - 180.0);
        SetPlayerFacingAngle(playerid, ang);
        return 0;
}
forward FollowToPlayer(playerid);
public FollowToPlayer(playerid)
{
        static AnimShot[MAX_PLAYERSS];
        if(!IsPlayerConnected(FollowBy[playerid]))
        {
                KillTimer(TimerForPlayer[playerid]);
                TimerForPlayer [playerid]= MAX_PLAYERSS;
                FollowBy [playerid]= MAX_PLAYERSS;
                TogglePlayerControllable(playerid, 1);
                ClearAnimations(playerid);
                AnimShot [playerid]= false;
                SendClientMessage(playerid, 0xFFFF00AA, "Вы свободны, конвой покинул сервер!");
                return 1;
        }
        else if(!IsPlayerConnected(playerid))
        {
                SetPVarInt(FollowBy[playerid], "TempFollowBy", -1);
                KillTimer(TimerForPlayer[playerid]);
                TimerForPlayer [playerid]= MAX_PLAYERSS;
                AnimShot [playerid]= false;
                SendClientMessage(FollowBy[playerid], 0xFFFF00AA, "Арестованный покинул сервер!");
                FollowBy [playerid]= MAX_PLAYERSS;
                return 1;
        }
        else if(FollowBy [playerid]== MAX_PLAYERSS)
        {
                KillTimer(TimerForPlayer[playerid]);
                TimerForPlayer [playerid]= MAX_PLAYERSS;
                AnimShot [playerid]= false;
                SendClientMessage(playerid, 0xFFFF00AA, "С вашем конвоем произошла беда, вы свободны !");
                TogglePlayerControllable(playerid, 1);
                ClearAnimations(playerid);
                return 1;
        }
        else if(IsPlayerInAnyVehicle(playerid))
        {
                SetPVarInt(FollowBy[playerid], "TempFollowBy", -1);
                KillTimer(TimerForPlayer[playerid]);
                TimerForPlayer [playerid]= MAX_PLAYERSS;
                AnimShot [playerid]= false;
                SendClientMessage(FollowBy[playerid], 0xFFFF00AA, "Ваш заключенный в машине. Конвой остановлен");
                FollowBy [playerid]= MAX_PLAYERSS;
                return 1;
        }
        else if(GetPlayerVirtualWorld(FollowBy[playerid]) != GetPlayerVirtualWorld(playerid) || GetPlayerInterior(FollowBy[playerid]) != GetPlayerInterior(playerid))
        {
                new Float: X, Float: Y, Float: Z;
                GetPlayerPos(FollowBy[playerid], X, Y, Z);
                SetPlayerPos(playerid, X, Y, Z);
                SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(FollowBy[playerid]));
                SetPlayerInterior(playerid, GetPlayerInterior(FollowBy[playerid]));
                TogglePlayerControllable(playerid, 0);
                AnimShot [playerid]= false;
                return 1;
        }
        new Float: GotDistance = GetDistanceBetweenPlayers(playerid, FollowBy[playerid]);
        if(GotDistance < 0.95)
        {
                TogglePlayerControllable(playerid, 0);
                SetPlayerToFacePlayer(playerid, FollowBy[playerid]);
                AnimShot [playerid]= false;
                return 1;
          }
        else if(GotDistance > 10.0)
        {
                SetPVarInt(FollowBy[playerid], "TempFollowBy", -1);
                SendClientMessage(FollowBy[playerid], 0xFFFF00AA, "Вы ушли слишком далеко. Конвой закончен");
                SendClientMessage(playerid, 0xFFFF00AA, "Ваш конвой ушел слишком далеко, вы свободны.");
                TogglePlayerControllable(playerid, 1);
                ClearAnimations(playerid);
                KillTimer(TimerForPlayer[playerid]);
                TimerForPlayer [playerid]= MAX_PLAYERSS;
                FollowBy [playerid]= MAX_PLAYERSS;
                return 1;
          }
          else
          {
                  TogglePlayerControllable(playerid, 1);
                  SetPlayerToFacePlayer(playerid, FollowBy[playerid]);
                  ApplyAnimation(playerid, "ped", "WALK_civi", 6.0, 1, 1, 1, 1, 0, 1);
        }
          return 1;
}


 
  • Страница 1 из 1
  • 1
Поиск: