private void API_onClientEventTrigger(Client sender, string eventName, params object[] arguments) { if (eventName == "fuel_getvehiclefuel" && API.IsPlayerInAnyVehicle(sender) && API.GetPlayerVehicleSeat(sender) == -1) { Vehicle veh = API.GetEntityData(API.GetPlayerVehicle(sender), "Vehicle"); API.TriggerClientEvent(sender, "fuel_updatevalue", veh.Fuel); } }
private void API_onPlayerExitVehicle(Client player, NetHandle vehicle, int seat) { if (API.HasEntityData(player, "FUELING_VEHICLE")) { var vehEntity = API.GetEntityData(player, "FUELING_VEHICLE"); API.SendChatMessageToPlayer(player, "Refuel ended."); Vehicle veh = API.GetEntityData(vehEntity, "Vehicle"); veh.FuelingTimer?.Dispose(); API.FreezePlayer(player, false); veh.Save(); } }
public void PickupWood(Client player) { var character = player.GetCharacter(); if (character.JobOne.Type != JobManager.JobTypes.Lumberjack) { API.SendNotificationToPlayer(player, "You must be a lumberjack."); return; } if (API.IsPlayerInAnyVehicle(player) && API.GetEntityModel(API.GetPlayerVehicle(player)) == (int)VehicleHash.Flatbed) { Vehicle vehicle = API.GetEntityData(API.GetPlayerVehicle(player), "Vehicle"); if (vehicle.Job.Type != JobManager.JobTypes.Lumberjack) { API.SendChatMessageToPlayer(player, "This is not a Lumberjack vehicle."); return; } if (API.HasEntityData(vehicle.NetHandle, "TREE_OBJ")) { API.SendChatMessageToPlayer(player, "This vehicle is already holding some logs."); return; } var tree = Tree.Trees.FirstOrDefault(x => x.TreeObj?.position?.DistanceTo(player.position) <= 10.0f && x.Stage == Tree.Stages.Waiting); if (tree == null || tree?.Stage != Tree.Stages.Waiting) { API.SendChatMessageToPlayer(player, "You aren't near a tree."); return; } tree.Stage = Tree.Stages.Moving; tree.UpdateTreeText(); API.AttachEntityToEntity(tree.TreeObj, API.GetPlayerVehicle(player), "bodyshell", new Vector3(0, -1.5, 0.3), new Vector3(0, 0, 0)); ChatManager.RoleplayMessage(player, "picks up the woods into the truck.", ChatManager.RoleplayMe); API.TriggerClientEvent(player, "update_beacon", character.JobOne.MiscOne.Location); API.SetEntityData(vehicle.NetHandle, "TREE_OBJ", tree); API.SetEntityData(vehicle.NetHandle, "TREE_DRIVER", character.Id); API.SendChatMessageToPlayer(player, "Go to the HQ to sell your wood."); } else { API.SendChatMessageToPlayer(player, "You have to be in a truck to pickup the wood."); } }
public void SellWoodCmd(Client player) { var character = player.GetCharacter(); if (character.JobOne.Type != JobManager.JobTypes.Lumberjack) { API.SendNotificationToPlayer(player, "You must be a lumberjack."); return; } if (character.JobZoneType != 2 || JobManager.GetJobById(character.JobZone).Type != JobManager.JobTypes.Lumberjack) { API.SendChatMessageToPlayer(player, Color.White, "You are not near the sell wood point!"); return; } if (API.IsPlayerInAnyVehicle(player) && API.GetEntityModel(API.GetPlayerVehicle(player)) == (int)VehicleHash.Flatbed) { Tree tree = API.GetEntityData(API.GetPlayerVehicle(player), "TREE_OBJ"); if (tree == null) { API.SendChatMessageToPlayer(player, "You dont have any wood on your vehicle."); return; } tree.Stage = Tree.Stages.Hidden; tree.UpdateAllTree(); tree.RespawnTimer = new Timer(1.8e+6); tree.RespawnTimer.Elapsed += tree.RespawnTimer_Elapsed; tree.RespawnTimer.Start(); Vehicle vehicle = API.GetEntityData(API.GetPlayerVehicle(player), "Vehicle"); API.ResetEntityData(API.GetPlayerVehicle(player), "TREE_OBJ"); API.Delay(1000, true, () => API.WarpPlayerOutOfVehicle(player));; VehicleManager.respawn_vehicle(vehicle); API.ResetEntityData(API.GetPlayerVehicle(player), "TREE_DRIVER"); API.TriggerClientEvent(player, "update_beacon", new Vector3()); InventoryManager.GiveInventoryItem(player.GetCharacter(), new Money(), 350, true); API.SendChatMessageToPlayer(player, "* You have sucessfully sold your wood for ~g~$350"); LogManager.Log(LogManager.LogTypes.Stats, $"[Job] {character.CharacterName}[{player.GetAccount().AccountName}] has earned $200 from selling wood."); SettingsManager.Settings.WoodSupplies += 50; } }
public void RespawnTaxi(Character character, Vehicle veh) { if (API.IsPlayerConnected(character.Client)) { API.SendChatMessageToPlayer(character.Client, Color.Yellow, "[TAXI] You were out of your taxi for too long and have taken off-duty. The taxi has been respawned."); if (OnDutyDrivers.Contains(character)) { character.TaxiDuty = false; } SendMessageToOnDutyDrivers(character.rp_name() + " has gone off of taxi duty."); } API.SetVehicleEngineStatus(veh.NetHandle, false); veh.CustomRespawnTimer.Stop(); VehicleManager.respawn_vehicle(veh); }
private void API_onPlayerEnterVehicle(Client player, NetHandle vehicle, int seat) { if (vehicle.GetVehicle() == null) { return; } if (API.GetEntityModel(vehicle) == (int)VehicleHash.Flatbed && player.GetCharacter().JobOne.Type == JobManager.JobTypes.Lumberjack) { Vehicle veh = API.GetEntityData(vehicle, "Vehicle"); if (veh.Job?.Type != JobManager.JobTypes.Lumberjack) { return; } Tree tree = API.GetEntityData(vehicle, "TREE_OBJ"); if (tree == null) { return; } if (API.HasEntityData(vehicle, "TREE_DRIVER")) { int id = API.GetEntityData(vehicle, "TREE_DRIVER"); if (id != player.GetCharacter().Id) { API.Delay(1000, true, () => API.WarpPlayerOutOfVehicle(player));; API.SendChatMessageToPlayer(player, "This is not yours."); return; } } if (API.HasEntityData(vehicle, "Tree_Cancel_Timer")) { System.Threading.Timer timer = API.GetEntityData(vehicle, "Tree_Cancel_Timer"); timer.Dispose(); API.ResetEntityData(vehicle, "Tree_Cancel_Timer"); API.SendChatMessageToPlayer(player, "You've got back into your vehicle."); } } }
private void API_onPlayerExitVehicle(Client player, NetHandle vehicle, int seat) { if (API.GetEntityModel(vehicle) == (int)VehicleHash.Flatbed && player.GetCharacter().JobOne.Type == JobManager.JobTypes.Lumberjack) { Vehicle veh = API.GetEntityData(vehicle, "Vehicle"); if (veh.Job.Type != JobManager.JobTypes.Lumberjack) { return; } Tree tree = API.GetEntityData(vehicle, "TREE_OBJ"); if (tree == null) { return; } API.SetEntityData(vehicle, "Tree_Cancel_Timer", new System.Threading.Timer(state => { Vehicle vehN = API.GetEntityData(vehicle, "Vehicle"); Tree ttree = API.GetEntityData(vehicle, "TREE_OBJ"); if (ttree == null) { return; } ttree.Stage = Tree.Stages.Cutting; ttree.UpdateAllTree(); API.ResetEntityData(vehicle, "TREE_OBJ"); vehN.Respawn(); API.ResetEntityData(vehicle, "Tree_Cancel_Timer"); API.ResetEntityData(vehicle, "TREE_DRIVER"); API.SendChatMessageToPlayer(player, "Wood run cancelled."); API.TriggerClientEvent(player, "update_beacon", new Vector3()); }, null, 60000, Timeout.Infinite)); API.SendChatMessageToPlayer(player, "You've got 1 minute to get back to your vehicle or the wood will be reset."); } }
public void Refuel(Client player, int fuel = 0) { var prop = PropertyManager.IsAtPropertyInteraction(player); if (prop?.Type == PropertyManager.PropertyTypes.GasStation) { if (API.IsPlayerInAnyVehicle(player) && API.GetPlayerVehicleSeat(player) == -1) { var vehEntity = API.GetPlayerVehicle(player); Vehicle veh = API.GetEntityData(vehEntity, "Vehicle"); if (API.GetVehicleEngineStatus(vehEntity)) { API.SendChatMessageToPlayer(player, "Vehicle engine must be off."); return; } if (player.hasData("FUELING_VEHICLE")) { API.SendChatMessageToPlayer(player, "You're already refueling a vehicle."); return; } if (fuel == 0) { fuel = 100 - veh.Fuel; } var pendingFuel = fuel; if (pendingFuel > 100 || pendingFuel + veh.Fuel > 100 || pendingFuel < 0) { API.SendChatMessageToPlayer(player, "Vehicle fuel can't be above 100 or negative."); return; } if (Money.GetCharacterMoney(player.GetCharacter()) < pendingFuel * prop.ItemPrices["gas"] && player.GetCharacter().Group.CommandType != group_manager.Group.CommandTypeLspd) { API.SendChatMessageToPlayer(player, $"You don't have enough money to get ~r~{pendingFuel}~w~ units of fuel.~n~It's worth ~g~${pendingFuel * prop.ItemPrices["gas"]}~w~."); return; } API.SendChatMessageToPlayer(player, $"You will be charged ~g~${pendingFuel * prop.ItemPrices["gas"]}~w~ for ~r~{pendingFuel}~w~ units of fuel."); API.FreezePlayer(player, true); API.SetEntityData(vehEntity, "PENDING_FUEL", pendingFuel); veh.RefuelProp = prop; FuelVeh(new[] { player, vehEntity }); if (API.HasEntityData(vehEntity, "PENDING_FUEL")) { API.SetEntityData(player, "FUELING_VEHICLE", vehEntity); veh.FuelingTimer = new System.Threading.Timer(FuelVeh, new[] { player, vehEntity }, 3000, 3000); return; } } else { API.SendChatMessageToPlayer(player, "You must be driving a vehicle."); } } else { API.SendChatMessageToPlayer(player, "You must be at a gas station."); } }
private void FuelVeh(System.Object vars) { var handles = (NetHandle[])vars; Client playerEntity = API.GetPlayerFromHandle(handles[0]); NetHandle vehEntity = handles[1]; if (vehEntity.IsNull) { return; } Vehicle veh = API.GetEntityData(vehEntity, "Vehicle"); if (veh == null) { return; } if (playerEntity == null) { veh.FuelingTimer?.Dispose(); API.ResetEntityData(vehEntity, "PENDING_FUEL"); return; } Character c = playerEntity.GetCharacter(); if (c == null) { veh.FuelingTimer?.Dispose(); API.ResetEntityData(vehEntity, "PENDING_FUEL"); return; } if (API.GetVehicleEngineStatus(vehEntity)) { veh.FuelingTimer?.Dispose(); API.ResetEntityData(vehEntity, "PENDING_FUEL"); API.ResetEntityData(playerEntity, "FUELING_VEHICLE"); API.FreezePlayer(playerEntity, false); API.SendChatMessageToPlayer(playerEntity, "Refuel has been cancelled cause the engine has turned on."); veh.Save(); return; } int pendingFuel = API.GetEntityData(vehEntity, "PENDING_FUEL") ?? 0; if (pendingFuel <= 0 || veh.RefuelProp.Supplies <= 0) { API.TriggerClientEvent(playerEntity, "fuel_updatevalue", veh.Fuel); veh.FuelingTimer?.Dispose(); API.ResetEntityData(vehEntity, "PENDING_FUEL"); API.ResetEntityData(playerEntity, "FUELING_VEHICLE"); API.FreezePlayer(playerEntity, false); if (veh.RefuelProp.Supplies <= 0) { API.SendChatMessageToPlayer(playerEntity, "The gas station ran out of gas."); } else if (pendingFuel <= 0) { API.SendChatMessageToPlayer(playerEntity, "Refueling finished."); } veh.Save(); return; } if (pendingFuel < 10) { veh.Fuel += pendingFuel; pendingFuel -= pendingFuel; if (c.Group.CommandType != group_manager.Group.CommandTypeLspd) { InventoryManager.DeleteInventoryItem <Money>(c, pendingFuel * veh.RefuelProp.ItemPrices["gas"]); } veh.RefuelProp.Supplies--; } else { veh.Fuel += 10; pendingFuel -= 10; if (c.Group.CommandType != group_manager.Group.CommandTypeLspd) { InventoryManager.DeleteInventoryItem <Money>(c, 10 * veh.RefuelProp.ItemPrices["gas"]); } veh.RefuelProp.Supplies--; } API.TriggerClientEvent(playerEntity, "fuel_updatevalue", veh.Fuel); API.SetEntityData(vehEntity, "PENDING_FUEL", pendingFuel); }