Esempio n. 1
0
 public void DestroyObject(IObject obj)
 {
     obj.OnDestroy();
     _updateObjectPool.RemoveUpdateObject(obj);
 }
Esempio n. 2
0
        private void OnClientResourceStart(string resourceName)
        {
            if (GetCurrentResourceName() != resourceName)
            {
                return;
            }

            _updateObjectPool = new UpdateObjectPool(0);
            _updateObjectPool.Start();

            _cameraControl = new CameraControl();

            RegisterCommand("start", new Action <int, List <object>, string>((source, args, raw) =>
            {
                PrintToChat("Starting new camera...");

                if (_camera != null)
                {
                    _toggled = false;
                    RenderScriptCams(false, false, 0, true, true);

                    _updateObjectPool.RemoveUpdateObject(_cameraControl);

                    _camera.Delete();
                    _camera = null;

                    FreezeEntityPosition(Game.PlayerPed.Handle, false);
                }

                var cameraHandle = CreateCam("DEFAULT_SCRIPTED_CAMERA", true);
                _camera          = new Camera(cameraHandle);
                _camera.Position = GetPlayerHeadPosition() + Game.PlayerPed.ForwardVector * 1.5f;
                _camera.PointAt(GetPlayerHeadPosition());
                _camera.StopPointing();

                _toggled = true;
                RenderScriptCams(true, false, 0, true, true);

                _cameraControl.SetCamera(_camera);
                _updateObjectPool.AddUpdateObject(_cameraControl);

                FreezeEntityPosition(Game.PlayerPed.Handle, true);
            }), false);

            RegisterCommand("toggle", new Action <int, List <object>, string>((source, args, raw) =>
            {
                if (_camera == null)
                {
                    return;
                }

                if (!_toggled)
                {
                    _toggled = true;
                    RenderScriptCams(true, false, 0, true, true);
                }
                else
                {
                    _toggled = false;
                    RenderScriptCams(false, false, 0, true, true);
                }
            }), false);

            RegisterCommand("stop", new Action <int, List <object>, string>((source, args, raw) =>
            {
                if (_camera == null)
                {
                    return;
                }

                PrintToChat("Stopping camera...");

                _toggled = false;
                RenderScriptCams(false, false, 0, true, true);

                _updateObjectPool.RemoveUpdateObject(_cameraControl);

                _camera.Delete();
                _camera = null;

                FreezeEntityPosition(Game.PlayerPed.Handle, false);
            }), false);

            RegisterCommand("save", new Action <int, List <object>, string>((source, args, raw) =>
            {
                if (_camera == null)
                {
                    return;
                }

                PrintToChat("Saving camera configuration...");

                var offset = GetOffsetFromEntityGivenWorldCoords(Game.PlayerPed.Handle, _camera.Position.X,
                                                                 _camera.Position.Y, _camera.Position.Z);
                var headPosition = GetPlayerHeadPosition();
                var headOffset   = GetOffsetFromEntityGivenWorldCoords(Game.PlayerPed.Handle, headPosition.X,
                                                                       headPosition.Y, headPosition.Z);

                var result = offset - headOffset;
                Debug.WriteLine($"Camera offset: {result.X}f, {result.Y}f, {result.Z}f");

                var rotation = _camera.Rotation - Game.PlayerPed.Rotation;
                Debug.WriteLine($"Camera rotation: {rotation.X}f, {rotation.Y}f, {rotation.Z}f");

                var fov = _camera.FieldOfView;
                Debug.WriteLine($"Camera fov: {fov}f");
            }), false);
        }
Esempio n. 3
0
        private void OnClientResourceStart(string resourceName)
        {
            if (GetCurrentResourceName() != resourceName)
            {
                return;
            }

            _updateObjectPool.Start();

            RegisterCommand("spawnped", new Action <int, List <object>, string>(async(source, args, raw) =>
            {
                if (args.Count != 0)
                {
                    PrintToChat("Usage: /spawnped");
                    return;
                }

                var pedPosition = Game.PlayerPed.Position + Game.PlayerPed.ForwardVector * 3f;
                var pedHeading  = Game.PlayerPed.Heading + 180f;

                var pedHandle = await Utility.CreateRandomPedAsync(pedPosition, pedHeading);
                SetEntityAsMissionEntity(pedHandle, true, false);

                var pedChecker = new PedChecker(pedHandle);
                _pedCheckers.Add(pedChecker);
                _updateObjectPool.AddUpdateObject(pedChecker);

                PrintToChat($"Spawned ped with handle of {pedHandle}. PedChecker - {pedChecker}.");
            }), false);

            RegisterCommand("peds", new Action <int, List <object>, string>((source, args, raw) =>
            {
                if (args.Count != 0)
                {
                    PrintToChat("Usage: /peds");
                    return;
                }

                if (_pedCheckers.Count == 0)
                {
                    PrintToChat("There are no spawned peds.");
                    return;
                }

                var i = 0;
                foreach (var pedChecker in _pedCheckers)
                {
                    PrintToChat($"{i} - {pedChecker}");
                }
            }), false);

            RegisterCommand("removeped", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var pedIndex = 0;
                if (args.Count != 1 ||
                    !int.TryParse(args[0].ToString(), out pedIndex))
                {
                    PrintToChat("Usage: /removeped [ped_number]");
                    return;
                }

                if (pedIndex < 0 || pedIndex >= _pedCheckers.Count)
                {
                    PrintToChat($"Unable to find ped with number of {pedIndex}. Try /peds to see all peds.");
                    return;
                }

                var pedChecker = _pedCheckers[pedIndex];
                _pedCheckers.RemoveAt(pedIndex);
                _updateObjectPool.RemoveUpdateObject(pedChecker);

                var pedHandle = pedChecker.PedHandle;
                DeleteEntity(ref pedHandle);

                PrintToChat($"Removed ped with handle of {pedHandle}. PedChecker - {pedChecker}.");
            }), false);

            RegisterCommand("owner", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var pedNetId = 0;
                if (args.Count != 1 ||
                    !int.TryParse(args[0].ToString(), out pedNetId))
                {
                    PrintToChat("Usage: /owner [net_id]");
                    return;
                }

                var pedHandle = NetworkGetEntityFromNetworkId(pedNetId);
                var owner     = NetworkGetEntityOwner(pedHandle);

                PrintToChat($"Owner of ped with Net ID of {pedNetId} is {owner}.");
            }), false);

            RegisterCommand("handle", new Action <int, List <object>, string>((source, args, raw) =>
            {
                if (args.Count != 0)
                {
                    PrintToChat("Usage: /handle");
                    return;
                }

                var playerHandle = Game.Player.Handle;
                PrintToChat($"Your handle is {playerHandle}");

                var pedHandle = Game.PlayerPed.Handle;
                PrintToChat($"Your ped handle is {pedHandle}");

                var pedNetworkId = Game.PlayerPed.NetworkId;
                PrintToChat($"Your ped network id is {pedNetworkId}");
            }), false);

            RegisterCommand("id", new Action <int, List <object>, string>((source, args, raw) =>
            {
                if (args.Count != 0)
                {
                    PrintToChat("Usage: /id");
                    return;
                }

                var playerId = GetPlayerServerId(Game.Player.Handle);
                PrintToChat($"Your server id is {playerId}");
            }), false);

            RegisterCommand("anime", new Action <int, List <object>, string>(async(source, args, raw) =>
            {
                var handle = 0;
                if (args.Count != 1 ||
                    !int.TryParse(args[0].ToString(), out handle))
                {
                    PrintToChat("Usage: /anime [handle]");
                    return;
                }

                await Utility.LoadAnimDict("amb@world_human_cheering@male_a");

                TaskPlayAnim(handle, "amb@world_human_cheering@male_a", "base",
                             8f, 8f, -1, 0, 0,
                             false, false, false);
            }), false);

            RegisterCommand("hfn", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var networkId = 0;
                if (args.Count != 1 ||
                    !int.TryParse(args[0].ToString(), out networkId))
                {
                    PrintToChat("Usage: /hfn [network_id]");
                    return;
                }

                var handle = NetworkGetEntityFromNetworkId(networkId);
                PrintToChat($"Handle of entity with Network ID of {networkId} is {handle}.");
            }), false);

            RegisterCommand("exists", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var networkId = 0;
                if (args.Count != 1 ||
                    !int.TryParse(args[0].ToString(), out networkId))
                {
                    PrintToChat("Usage: /exists [network_id]");
                    return;
                }

                var handle = NetworkGetEntityFromNetworkId(networkId);
                PrintToChat($"Entity with Network ID of {networkId} exists: {DoesEntityExist(handle)}.");
            }), false);

            RegisterCommand("hide", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var playerNetworkId = 0;
                if (args.Count != 1 ||
                    !int.TryParse(args[0].ToString(), out playerNetworkId))
                {
                    PrintToChat("Usage: /hide [net_id]");
                    return;
                }

                if (_currentToken != null)
                {
                    _currentToken.Cancelled = true;
                }

                _currentToken = new Token(NetworkGetEntityFromNetworkId(playerNetworkId));
                _             = HidingLoop(_currentToken);
            }), false);

            RegisterCommand("unhide", new Action <int, List <object>, string>((source, args, raw) =>
            {
                if (args.Count != 0)
                {
                    PrintToChat("Usage: /unhide");
                    return;
                }

                if (_currentToken != null)
                {
                    _currentToken.Cancelled = true;
                }
            }), false);
        }