public World() { _updateObjectPool = new UpdateObjectPool(REFRESH_RATE); _updateObjectPool.Start(); VehicleEventsManager = new VehicleEventsManager(); _updateObjectPool.AddUpdateObject(VehicleEventsManager); AimingManager = new AimingManager(); _updateObjectPool.AddUpdateObject(AimingManager); EntityDeathTracker = new EntityDeathTracker(); ObjectManager = new ObjectManager(REFRESH_RATE); }
public T AddObject <T>(T obj) where T : IObject { obj.OnCreate(); _updateObjectPool.AddUpdateObject(obj); return(obj); }
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); }
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); }
private void OnClientResourceStart(string resourceName) { if (GetCurrentResourceName() != resourceName) { return; } var configuration = new HubConfiguration { HubCenter = new Vector3(2049.88f, 3183.32f, 45.16f), HubRadius = 200f, SpawnConfigurations = new List <SpawnConfiguration> { new SpawnConfiguration { Position = new Vector3(2043f, 2198f, 45f), Heading = 234f, PedConfiguration = new PedConfiguration { Model = "a_m_o_acult_01" } }, new SpawnConfiguration { Position = new Vector3(2057.64f, 3195.24f, 45.19f), Heading = 114f, PedConfiguration = new PedConfiguration { Model = "a_m_o_acult_02" } }, new SpawnConfiguration { Position = new Vector3(2060.47f, 3174.21f, 45.17f), Heading = 57f, PedConfiguration = new PedConfiguration { Model = "a_m_y_acult_01" } }, new SpawnConfiguration { Position = new Vector3(2053.91f, 3175.48f, 45.17f), Heading = 356.26f, PedConfiguration = new PedConfiguration { Model = "a_m_y_methhead_01" } }, new SpawnConfiguration { Position = new Vector3(2039.88f, 3183.31f, 45.22f), Heading = 253.27f, PedConfiguration = new PedConfiguration { Model = "a_f_m_fatcult_01" } } } }; var updateObjectPool = new UpdateObjectPool(1000); updateObjectPool.Start(); var hub = new Hub(configuration); updateObjectPool.AddUpdateObject(hub); RegisterCommand("location", new Action <int, List <object>, string>((source, args, raw) => { var playerPosition = Game.PlayerPed.Position; Debug.WriteLine($"Position: {playerPosition.X}f, {playerPosition.Y}f, {playerPosition.Z}f"); var playerHeading = Game.PlayerPed.Heading; Debug.WriteLine($"Heading: {playerHeading}f"); }), false); }