示例#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);
        }
示例#2
0
        CommandManager.ProcessCommandResult ProcessCommand(CommandManager.ProcessCommandContext context)
        {
            string command = context.command;

            string[] words            = CommandManager.SplitCommandIntoArguments(command);
            int      numWords         = words.Length;
            string   restOfTheCommand = CommandManager.GetRestOfTheCommand(command, 0);

            string response = "";


            if (2 == numWords && words[0] == "camera_disable")
            {
                int cameraDisable = int.Parse(words[1]);

                var cam = F.FindMainCameraEvenIfDisabled();

                if (cam != null)
                {
                    if (0 == cameraDisable)
                    {
                        cam.enabled = true;
                    }
                    else if (1 == cameraDisable)
                    {
                        cam.enabled = false;
                    }
                    else
                    {
                        response += "Invalid value. Use 0 or 1.";
                    }
                }
            }
            else if (words[0] == "uptime")
            {
                response += F.FormatElapsedTime(Time.realtimeSinceStartup);
            }
            else if (words[0] == "players")
            {
                // list all players

                response += "net id";
                if (NetUtils.IsServer && context.hasServerPermissions)
                {
                    response += " | ip";
                }
                response += "\n";

                foreach (var player in Player.AllPlayersEnumerable)
                {
                    response += player.netId;
                    if (NetUtils.IsServer && context.hasServerPermissions)
                    {
                        response += " | " + player.connectionToClient.address;
                    }
                    response += "\n";
                }
            }
            else if (words[0] == "kick")
            {
                if (NetUtils.IsServer)
                {
                    uint netId = uint.Parse(words[1]);
                    var  p     = Player.GetByNetId(netId);
                    if (null == p)
                    {
                        response += "There is no such player connected.";
                    }
                    else
                    {
                        p.Disconnect();
                    }
                }
            }
            else if (words[0] == "startserver" || words[0] == "starthost")
            {
                ushort portNumber = (ushort)NetManager.defaultListenPortNumber;

                if (numWords > 1)
                {
                    portNumber = ushort.Parse(words[1]);
                }

                if (words[0] == "startserver")
                {
                    NetManager.StartServer(portNumber);
                }
                else
                {
                    NetManager.StartHost(portNumber);
                }
            }
            else if (words[0] == "connect")
            {
                if (numWords != 3)
                {
                    response += CommandManager.invalidSyntaxText;
                }
                else
                {
                    string ip   = words[1];
                    int    port = int.Parse(words[2]);

                    NetManager.StartClient(ip, port);
                }
            }
            else if (words[0] == "exit")
            {
                GameManager.ExitApplication();
            }

            return(new CommandManager.ProcessCommandResult {
                response = response
            });
        }