Ejemplo n.º 1
0
        CommandManager.ProcessCommandResult ProcessCommand(CommandManager.ProcessCommandContext context)
        {
            string[] arguments              = CommandManager.SplitCommandIntoArguments(context.command);
            int      numArguments           = arguments.Length;
            Player   player                 = context.player;
            var      pedNotAliveResult      = CommandManager.ProcessCommandResult.Error("You must control a ped to run this command");
            var      pedModelIdDoesNotExist = CommandManager.ProcessCommandResult.Error("Specified model id does not exist");

            if (arguments[0] == "skin")
            {
                if (null == player.OwnedPed)
                {
                    return(pedNotAliveResult);
                }

                if (!GetPedModelId(arguments, 1, out int modelId))
                {
                    return(pedModelIdDoesNotExist);
                }

                player.OwnedPed.PlayerModel.Load(modelId);

                return(CommandManager.ProcessCommandResult.Success);
            }
            else if (arguments[0] == "stalker")
            {
                if (null == player.OwnedPed)
                {
                    return(pedNotAliveResult);
                }

                if (!GetPedModelId(arguments, 1, out int modelId))
                {
                    return(pedModelIdDoesNotExist);
                }

                Ped.SpawnPedStalker(modelId, player.OwnedPed.transform, player.OwnedPed);

                return(CommandManager.ProcessCommandResult.Success);
            }
            else if (arguments[0] == "suicide")
            {
                if (null == player.OwnedPed)
                {
                    return(pedNotAliveResult);
                }

                player.OwnedPed.Kill();

                return(CommandManager.ProcessCommandResult.Success);
            }
            else if (arguments[0] == "teleport")
            {
                if (null == player.OwnedPed)
                {
                    return(pedNotAliveResult);
                }

                Vector3    position;
                Quaternion rotation;

                try
                {
                    position = CommandManager.ParseVector3(arguments, 1);
                    rotation = player.OwnedPed.transform.rotation;
                    if (numArguments > 4)
                    {
                        rotation = Quaternion.Euler(0f, float.Parse(arguments[4], CultureInfo.InvariantCulture), 0f);
                    }
                }
                catch
                {
                    return(CommandManager.ProcessCommandResult.Error("Invalid syntax. Example: teleport 2000 10.2 -1234.5 or teleport 2000 10.2 -1234.5 28.3"));
                }

                player.OwnedPed.Teleport(position, rotation);

                return(CommandManager.ProcessCommandResult.Success);
            }
            else if (arguments[0] == "veh")
            {
                int id = -1;
                if (numArguments > 1)
                {
                    id = int.Parse(arguments[1]);
                }

                if (null == player.OwnedPed)
                {
                    return(CommandManager.ProcessCommandResult.Error("Your ped must be alive to spawn a vehicle"));
                }

                if (!m_perPlayerData.TryGetValue(player, out PlayerData playerData))
                {
                    playerData = new PlayerData();
                }

                playerData.vehicles.RemoveDeadObjects();
                if (playerData.vehicles.Count >= this.maxVehiclesPerPlayer)
                {
                    return(CommandManager.ProcessCommandResult.Error($"You can have a maximum of {this.maxVehiclesPerPlayer} vehicles"));
                }

                var vehicle = Vehicle.CreateInFrontOf(id, player.OwnedPed.transform);

                playerData.vehicles.Add(vehicle);
                m_perPlayerData[player] = playerData;

                return(CommandManager.ProcessCommandResult.Success);
            }
            else if (arguments[0] == "dveh")
            {
                if (m_perPlayerData.TryGetValue(player, out var playerData))
                {
                    playerData.vehicles.RemoveDeadObjects();
                    foreach (var vehicle in playerData.vehicles)
                    {
                        vehicle.Explode();
                    }
                }

                return(CommandManager.ProcessCommandResult.Success);
            }
            else if (arguments[0] == "w")
            {
                if (arguments.Length < 2)
                {
                    return(CommandManager.ProcessCommandResult.Error("Invalid syntax. Example: w 355"));
                }

                int modelId = int.Parse(arguments[1]);

                if (null == player.OwnedPed)
                {
                    return(pedNotAliveResult);
                }

                var weapon = player.OwnedPed.WeaponHolder.SetWeaponAtSlot(modelId, 0);
                player.OwnedPed.WeaponHolder.SwitchWeapon(weapon.SlotIndex);
                WeaponHolder.AddRandomAmmoAmountToWeapon(weapon);

                return(CommandManager.ProcessCommandResult.Success);
            }
            else if (arguments[0] == "rand_w")
            {
                if (null == player.OwnedPed)
                {
                    return(pedNotAliveResult);
                }

                player.OwnedPed.WeaponHolder.AddRandomWeapons();

                return(CommandManager.ProcessCommandResult.Success);
            }
            else if (arguments[0] == "rem_w")
            {
                if (null == player.OwnedPed)
                {
                    return(pedNotAliveResult);
                }

                player.OwnedPed.WeaponHolder.RemoveAllWeapons();

                return(CommandManager.ProcessCommandResult.Success);
            }
            else if (arguments[0] == "rem_current_w")
            {
                if (null == player.OwnedPed)
                {
                    return(pedNotAliveResult);
                }

                var weapon = player.OwnedPed.CurrentWeapon;
                if (weapon != null)
                {
                    Destroy(weapon.gameObject);
                }

                return(CommandManager.ProcessCommandResult.Success);
            }
            else if (arguments[0] == "ammo")
            {
                if (null == player.OwnedPed)
                {
                    return(pedNotAliveResult);
                }

                foreach (var weapon in player.OwnedPed.WeaponHolder.AllWeapons)
                {
                    WeaponHolder.AddRandomAmmoAmountToWeapon(weapon);
                }

                return(CommandManager.ProcessCommandResult.Success);
            }

            return(CommandManager.ProcessCommandResult.UnknownCommand);
        }