public void Destroy(bool check_players = false) { if (check_players) { foreach (var player in Main.Players.Keys.ToList()) { if (!Main.Players.ContainsKey(player)) { continue; } if (player.Position.DistanceTo(colShape.Position) > 1.5f) { continue; } Trigger.ClientEvent(player, "SetSafeNearby", false); player.ResetData("temp_SafeID"); } } Object.Delete(); DoorObject.Delete(); Label.Delete(); NAPI.ColShape.DeleteColShape(colShape); if (Timer != null) { Timers.Stop(Timer); } }
private void OnGarbageCollectedTimer(object playerObject) { Client player = (Client)playerObject; Client driver = player.GetData(EntityData.PLAYER_JOB_PARTNER); // Get garbage bag GTANetworkAPI.Object garbageBag = player.GetData(EntityData.PLAYER_GARBAGE_BAG); player.StopAnimation(); garbageBag.Delete(); // Get the remaining checkpoints int route = driver.GetData(EntityData.PLAYER_JOB_ROUTE); int checkPoint = driver.GetData(EntityData.PLAYER_JOB_CHECKPOINT) + 1; int totalCheckPoints = Constants.GARBAGE_LIST.Where(x => x.route == route).Count(); // Get the current checkpoint Checkpoint garbageCheckpoint = player.GetData(EntityData.PLAYER_JOB_COLSHAPE); garbageCheckpoint.Delete(); NAPI.Task.Run(() => { if (checkPoint < totalCheckPoints) { Vector3 currentGarbagePosition = GetGarbageCheckPointPosition(route, checkPoint); Vector3 nextGarbagePosition = GetGarbageCheckPointPosition(route, checkPoint + 1); // Show the next checkpoint garbageCheckpoint = NAPI.Checkpoint.CreateCheckpoint(CheckpointType.CylinderSingleArrow, currentGarbagePosition, nextGarbagePosition, 2.5f, new Color(198, 40, 40, 200)); driver.SetData(EntityData.PLAYER_JOB_CHECKPOINT, checkPoint); player.SetData(EntityData.PLAYER_JOB_CHECKPOINT, checkPoint); driver.TriggerEvent("showGarbageCheckPoint", currentGarbagePosition); player.TriggerEvent("showGarbageCheckPoint", currentGarbagePosition); // Add the garbage bag garbageBag = NAPI.Object.CreateObject(628215202, currentGarbagePosition, new Vector3(0.0f, 0.0f, 0.0f)); player.SetData(EntityData.PLAYER_GARBAGE_BAG, garbageBag); } else { garbageCheckpoint = NAPI.Checkpoint.CreateCheckpoint(CheckpointType.CylinderCheckerboard, new Vector3(-339.0206f, -1560.117f, 25.23038f), new Vector3(), 2.5f, new Color(198, 40, 40, 200)); driver.SendChatMessage(Constants.COLOR_INFO + InfoRes.route_finished); driver.TriggerEvent("showGarbageCheckPoint", garbageCheckpoint.Position); player.TriggerEvent("deleteGarbageCheckPoint"); } player.SendChatMessage(Constants.COLOR_INFO + InfoRes.garbage_collected); }); if (garbageTimerList.TryGetValue(player.Value, out Timer garbageTimer) == true) { garbageTimer.Dispose(); garbageTimerList.Remove(player.Value); } }
private void OnGarbageCollectedTimer(object playerObject) { Client player = (Client)playerObject; Client driver = player.GetData(EntityData.PLAYER_JOB_PARTNER); // Get garbage bag GTANetworkAPI.Object garbageBag = player.GetData(EntityData.PLAYER_GARBAGE_BAG); player.StopAnimation(); garbageBag.Delete(); // Get the remaining checkpoints int route = driver.GetData(EntityData.PLAYER_JOB_ROUTE); int checkPoint = driver.GetData(EntityData.PLAYER_JOB_CHECKPOINT) + 1; int totalCheckPoints = Constants.GARBAGE_LIST.Where(x => x.route == route).Count(); // Get the current checkpoint Checkpoint garbageCheckpoint = player.GetData(EntityData.PLAYER_JOB_COLSHAPE); if (checkPoint < totalCheckPoints) { Vector3 currentGarbagePosition = GetGarbageCheckPointPosition(route, checkPoint); Vector3 nextGarbagePosition = GetGarbageCheckPointPosition(route, checkPoint + 1); // Show the next checkpoint garbageCheckpoint.Position = currentGarbagePosition; garbageCheckpoint.Direction = nextGarbagePosition; driver.SetData(EntityData.PLAYER_JOB_CHECKPOINT, checkPoint); player.SetData(EntityData.PLAYER_JOB_CHECKPOINT, checkPoint); driver.TriggerEvent("showGarbageCheckPoint", currentGarbagePosition); player.TriggerEvent("showGarbageCheckPoint", currentGarbagePosition); // Add the garbage bag garbageBag = NAPI.Object.CreateObject(628215202, currentGarbagePosition, new Vector3(0.0f, 0.0f, 0.0f)); player.SetData(EntityData.PLAYER_GARBAGE_BAG, garbageBag); } else { NAPI.Entity.SetEntityModel(garbageCheckpoint, 4); garbageCheckpoint.Position = new Vector3(-339.0206f, -1560.117f, 25.23038f); driver.SendChatMessage(Constants.COLOR_INFO + Messages.INF_ROUTE_FINISHED); driver.TriggerEvent("showGarbageCheckPoint", garbageCheckpoint.Position); player.TriggerEvent("deleteGarbageCheckPoint"); } if (garbageTimerList.TryGetValue(player.Value, out Timer garbageTimer) == true) { garbageTimer.Dispose(); garbageTimerList.Remove(player.Value); } player.SendChatMessage(Constants.COLOR_INFO + Messages.INF_GARBAGE_COLLECTED); }
public static void OnPlayerDisconnected(Client player, DisconnectionType type, string reason) { if (player.HasData(EntityData.PLAYER_HANDCUFFED) == true) { // Remove player's cuffs GTANetworkAPI.Object cuff = player.GetData(EntityData.PLAYER_HANDCUFFED); cuff.Detach(); cuff.Delete(); } }
public static void RemoveWeaponProp(Client player, WeaponAttachmentType type) { int type_int = (int)type; if (!NAPI.Data.HasEntityData(player.Handle, WeaponKeys[type_int])) { return; } GTANetworkAPI.Object obj = NAPI.Data.GetEntityData(player.Handle, WeaponKeys[type_int]); obj.Delete(); NAPI.Data.ResetEntityData(player.Handle, WeaponKeys[type_int]); }
private void OnGarbageCollectedTimer(object playerObject) { NAPI.Task.Run(() => { Client player = (Client)playerObject; Client driver = player.GetData(EntityData.PLAYER_JOB_PARTNER); if (garbageTimerList.TryGetValue(player.Value, out Timer garbageTimer) == true) { garbageTimer.Dispose(); garbageTimerList.Remove(player.Value); } // Get garbage bag GTANetworkAPI.Object garbageBag = player.GetData(EntityData.PLAYER_GARBAGE_BAG); player.StopAnimation(); garbageBag.Delete(); // Get the remaining checkpoints int route = driver.GetData(EntityData.PLAYER_JOB_ROUTE); int checkPoint = driver.GetData(EntityData.PLAYER_JOB_CHECKPOINT) + 1; int totalCheckPoints = Constants.GARBAGE_LIST.Where(x => x.route == route).Count(); if (checkPoint < totalCheckPoints) { Vector3 currentGarbagePosition = GetGarbageCheckPointPosition(route, checkPoint); Vector3 nextGarbagePosition = GetGarbageCheckPointPosition(route, checkPoint + 1); driver.SetData(EntityData.PLAYER_JOB_CHECKPOINT, checkPoint); player.SetData(EntityData.PLAYER_JOB_CHECKPOINT, checkPoint); // Add the garbage bag garbageBag = NAPI.Object.CreateObject(628215202, currentGarbagePosition, new Vector3(0.0f, 0.0f, 0.0f)); player.SetData(EntityData.PLAYER_GARBAGE_BAG, garbageBag); // Create the checkpoints driver.TriggerEvent("showGarbageCheckPoint", currentGarbagePosition, nextGarbagePosition, CheckpointType.CylinderSingleArrow); player.TriggerEvent("showGarbageCheckPoint", currentGarbagePosition, nextGarbagePosition, CheckpointType.CylinderSingleArrow); } else { driver.SendChatMessage(Constants.COLOR_INFO + InfoRes.route_finished); driver.TriggerEvent("showGarbageCheckPoint", new Vector3(49.44239f, 6558.004f, 32.18963f), new Vector3(), CheckpointType.CylinderCheckerboard); player.TriggerEvent("deleteGarbageCheckPoint"); } player.SendChatMessage(Constants.COLOR_INFO + InfoRes.garbage_collected); }); }
public static void RemoveWeaponProps(Client player) { foreach (string key in WeaponKeys) { if (!NAPI.Data.HasEntityData(player.Handle, key)) { continue; } GTANetworkAPI.Object obj = NAPI.Data.GetEntityData(player.Handle, key); obj.Delete(); NAPI.Data.ResetEntityData(player.Handle, key); } }
void CancelScuba(Client player) { var character = player.GetCharacter(); //Cancel timer. Timer timer = NAPI.Data.GetEntityData(player, "SCUBA_TIMER"); if (timer != null) { timer.Dispose(); NAPI.Data.ResetEntityData(player, "SCUBA_TIMER"); } //Remove clothes GTANetworkAPI.Object head = NAPI.Data.GetEntityData(player, "SCUBA_HEAD"); GTANetworkAPI.Object tank = NAPI.Data.GetEntityData(player, "SCUBA_TANK"); if (head != null && API.DoesEntityExist(head)) { head.Detach(); head.Delete(); NAPI.Data.ResetEntityData(player, "SCUBA_HEAD"); } if (tank != null && API.DoesEntityExist(tank)) { tank.Detach(); tank.Delete(); NAPI.Data.ResetEntityData(player, "SCUBA_TANK"); } //Set scuba state API.SendNativeToPlayer(player, Hash.SET_ENABLE_SCUBA, player.Handle, false); //Remove exygen NAPI.ClientEvent.TriggerClientEvent(player, "UPDATE_SCUBA_PERCENTAGE", "none"); //Set the variable. character.IsScubaDiving = false; //Set normal clothes character.update_ped(); //Set normal underwater time. API.SendNativeToPlayer(player, Hash.SET_PED_MAX_TIME_UNDERWATER, player.Handle, 60.0f); }
public void RemovePlayerWeapon(Client player, WeaponHash weapon) { if (WeaponData.ContainsKey(weapon)) { string key = WeaponKeys[(int)WeaponData[weapon].Type]; if (NAPI.Data.HasEntityData(player.Handle, key)) { GTANetworkAPI.Object obj = NAPI.Data.GetEntityData(player.Handle, key); if (obj.Model == NAPI.Util.GetHashKey(WeaponData[weapon].Model)) { obj.Delete(); NAPI.Data.ResetEntityData(player.Handle, key); } } } NAPI.Player.RemovePlayerWeapon(player, weapon); }
public void GarbageCommand(Client player, string action) { if (player.GetData(EntityData.PLAYER_JOB) != Constants.JOB_GARBAGE) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_garbage); } else if (player.GetData(EntityData.PLAYER_ON_DUTY) == 0) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_on_duty); } else { switch (action.ToLower()) { case Commands.ARG_ROUTE: if (player.HasData(EntityData.PLAYER_JOB_ROUTE) == true) { player.SendChatMessage(ErrRes.already_in_route); } else { Random random = new Random(); int garbageRoute = random.Next(Constants.MAX_GARBAGE_ROUTES); player.SetData(EntityData.PLAYER_JOB_ROUTE, garbageRoute); switch (garbageRoute) { case 0: player.SendChatMessage(Constants.COLOR_INFO + GenRes.route_north); break; case 1: player.SendChatMessage(Constants.COLOR_INFO + GenRes.route_south); break; case 2: player.SendChatMessage(Constants.COLOR_INFO + GenRes.route_east); break; case 3: player.SendChatMessage(Constants.COLOR_INFO + GenRes.route_west); break; } } break; case Commands.ARG_PICKUP: if (player.IsInVehicle) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.garbage_in_vehicle); } else if (player.HasData(EntityData.PLAYER_JOB_COLSHAPE) == false) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_garbage_near); } else { Checkpoint garbageCheckpoint = player.GetData(EntityData.PLAYER_JOB_COLSHAPE); if (player.Position.DistanceTo(garbageCheckpoint.Position) < 3.5f) { if (garbageTimerList.TryGetValue(player.Value, out Timer garbageTimer) == false) { player.PlayAnimation("anim@move_m@trash", "pickup", (int)(Constants.AnimationFlags.Loop | Constants.AnimationFlags.AllowPlayerControl)); player.SetData(EntityData.PLAYER_ANIMATION, true); // Make the timer for garbage collection garbageTimer = new Timer(OnGarbageCollectedTimer, player, 15000, Timeout.Infinite); garbageTimerList.Add(player.Value, garbageTimer); } else { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.already_garbage); } } else { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_garbage_near); } } break; case Commands.ARG_CANCEL: if (player.HasData(EntityData.PLAYER_JOB_PARTNER) == true) { Client partner = player.GetData(EntityData.PLAYER_JOB_PARTNER); if (partner != player) { GTANetworkAPI.Object trashBag = null; Checkpoint garbageCheckpoint = null; if (player.VehicleSeat == (int)VehicleSeat.Driver) { // Driver canceled trashBag = player.GetData(EntityData.PLAYER_GARBAGE_BAG); garbageCheckpoint = player.GetData(EntityData.PLAYER_JOB_COLSHAPE); player.SendChatMessage(Constants.COLOR_INFO + InfoRes.route_finished); partner.TriggerEvent("deleteGarbageCheckPoint"); } else { // Passenger canceled trashBag = partner.GetData(EntityData.PLAYER_GARBAGE_BAG); garbageCheckpoint = partner.GetData(EntityData.PLAYER_JOB_COLSHAPE); trashBag = partner.GetData(EntityData.PLAYER_GARBAGE_BAG); player.TriggerEvent("deleteGarbageCheckPoint"); } trashBag.Delete(); // Create finish checkpoint NAPI.Entity.SetEntityModel(garbageCheckpoint, 4); garbageCheckpoint.Position = new Vector3(-339.0206f, -1560.117f, 25.23038f); } else { // Player doesn't have any partner player.SendChatMessage(Constants.COLOR_INFO + InfoRes.route_canceled); } // Remove player from partner search player.ResetData(EntityData.PLAYER_JOB_PARTNER); } else if (player.HasData(EntityData.PLAYER_JOB_ROUTE) == true) { // Cancel the route player.ResetData(EntityData.PLAYER_JOB_PARTNER); player.SendChatMessage(Constants.COLOR_INFO + InfoRes.garbage_route_canceled); } else { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_in_route); } break; default: player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_GARBAGE_JOB_COMMAND); break; } } }
public void HandcuffCommand(Client player, string targetString) { if (player.GetData(EntityData.PLAYER_KILLED) != 0) { player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_PLAYER_IS_DEAD); } else if (player.GetData(EntityData.PLAYER_ON_DUTY) == 0) { player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_PLAYER_NOT_ON_DUTY); } else if (player.GetData(EntityData.PLAYER_FACTION) != Constants.FACTION_POLICE) { player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_PLAYER_NOT_POLICE_FACTION); } else { Client target = int.TryParse(targetString, out int targetId) ? Globals.GetPlayerById(targetId) : NAPI.Player.GetPlayerFromName(targetString); if (target != null) { if (player.Position.DistanceTo(target.Position) > 1.5f) { player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_PLAYER_TOO_FAR); } else if (target == player) { player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_PLAYER_HANDCUFFED_HIMSELF); } else if (target.HasData(EntityData.PLAYER_HANDCUFFED) == false) { string playerMessage = string.Format(Messages.INF_CUFFED, target.Name); string targetMessage = string.Format(Messages.INF_CUFFED_BY, player.Name); GTANetworkAPI.Object cuff = NAPI.Object.CreateObject(-1281059971, new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 0.0f)); cuff.AttachTo(target, "IK_R_Hand", new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 0.0f)); target.PlayAnimation("mp_arresting", "idle", (int)(Constants.AnimationFlags.Loop | Constants.AnimationFlags.OnlyAnimateUpperBody | Constants.AnimationFlags.AllowPlayerControl)); player.SetData(EntityData.PLAYER_ANIMATION, true); target.SetData(EntityData.PLAYER_HANDCUFFED, cuff); player.SendChatMessage(Constants.COLOR_INFO + playerMessage); target.SendChatMessage(Constants.COLOR_INFO + targetMessage); // Disable some player movements player.TriggerEvent("toggleHandcuffed", true); } else { GTANetworkAPI.Object cuff = target.GetData(EntityData.PLAYER_HANDCUFFED); cuff.Detach(); cuff.Delete(); target.StopAnimation(); player.ResetData(EntityData.PLAYER_ANIMATION); target.ResetData(EntityData.PLAYER_HANDCUFFED); string playerMessage = string.Format(Messages.INF_UNCUFFED, target.Name); string targetMessage = string.Format(Messages.INF_UNCUFFED_BY, player.Name); player.SendChatMessage(Constants.COLOR_INFO + playerMessage); target.SendChatMessage(Constants.COLOR_INFO + targetMessage); // Enable previously disabled player movements player.TriggerEvent("toggleHandcuffed", false); } } else { player.SendChatMessage(Constants.COLOR_ERROR + Messages.ERR_PLAYER_NOT_FOUND); } } }
public void GarbageCommand(Client player, string action) { player.SendChatMessage(Constants.COLOR_ERROR + "Trabajo deshabilitado temporalmente."); return; if (player.GetData(EntityData.PLAYER_JOB) != Constants.JOB_GARBAGE) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_garbage); } else if (player.GetData(EntityData.PLAYER_ON_DUTY) == 0) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.player_not_on_duty); } else { switch (action.ToLower()) { case Commands.ARG_ROUTE: if (player.GetData(EntityData.PLAYER_JOB_ROUTE) != null) { player.SendChatMessage(ErrRes.already_in_route); } else { Random random = new Random(); int garbageRoute = random.Next(Constants.MAX_GARBAGE_ROUTES); player.SetData(EntityData.PLAYER_JOB_ROUTE, garbageRoute); switch (garbageRoute) { case 0: player.SendChatMessage(Constants.COLOR_INFO + GenRes.route_north); break; case 1: player.SendChatMessage(Constants.COLOR_INFO + GenRes.route_south); break; case 2: player.SendChatMessage(Constants.COLOR_INFO + GenRes.route_east); break; case 3: player.SendChatMessage(Constants.COLOR_INFO + GenRes.route_west); break; } } break; case Commands.ARG_PICKUP: if (player.IsInVehicle) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.garbage_in_vehicle); } else if (player.GetData(EntityData.PLAYER_GARBAGE_BAG) == null) { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_garbage_near); } else { // Get the closest garbage bag GTANetworkAPI.Object trashBag = player.GetData(EntityData.PLAYER_GARBAGE_BAG); if (player.Position.DistanceTo(trashBag.Position) < 3.5f) { if (garbageTimerList.TryGetValue(player.Value, out Timer garbageTimer) == false) { player.PlayAnimation("anim@move_m@trash", "pickup", (int)(Constants.AnimationFlags.Loop | Constants.AnimationFlags.AllowPlayerControl)); player.SetData(EntityData.PLAYER_ANIMATION, true); // Make the timer for garbage collection garbageTimer = new Timer(OnGarbageCollectedTimer, player, 15000, Timeout.Infinite); garbageTimerList.Add(player.Value, garbageTimer); } else { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.already_garbage); } } else { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_garbage_near); } } break; case Commands.ARG_CANCEL: if (player.GetData(EntityData.PLAYER_JOB_PARTNER) != null) { Client partner = player.GetData(EntityData.PLAYER_JOB_PARTNER); if (partner != player) { GTANetworkAPI.Object trashBag = null; if (player.VehicleSeat == (int)VehicleSeat.Driver) { // Driver canceled trashBag = player.GetData(EntityData.PLAYER_GARBAGE_BAG); player.SendChatMessage(Constants.COLOR_INFO + InfoRes.route_finished); partner.TriggerEvent("deleteGarbageCheckPoint"); // Create finish checkpoint player.TriggerEvent("showGarbageCheckPoint", new Vector3(49.44239f, 6558.004f, 32.18963f), new Vector3(), CheckpointType.CylinderCheckerboard); } else { // Passenger canceled trashBag = partner.GetData(EntityData.PLAYER_GARBAGE_BAG); player.TriggerEvent("deleteGarbageCheckPoint"); // Create finish checkpoint partner.TriggerEvent("showGarbageCheckPoint", new Vector3(49.44239f, 6558.004f, 32.18963f), new Vector3(), CheckpointType.CylinderCheckerboard); } // Delete the garbage bag trashBag.Delete(); } else { // Player doesn't have any partner player.SendChatMessage(Constants.COLOR_INFO + InfoRes.route_canceled); } // Remove player from partner search player.ResetData(EntityData.PLAYER_JOB_PARTNER); } else if (player.GetData(EntityData.PLAYER_JOB_ROUTE) != null) { // Cancel the route player.ResetData(EntityData.PLAYER_JOB_ROUTE); player.ResetData(EntityData.PLAYER_JOB_PARTNER); player.SendChatMessage(Constants.COLOR_INFO + InfoRes.garbage_route_canceled); } else { player.SendChatMessage(Constants.COLOR_ERROR + ErrRes.not_in_route); } break; default: player.SendChatMessage(Constants.COLOR_HELP + Commands.HLP_GARBAGE_JOB_COMMAND); break; } } }