private void API_onClientEventTrigger(Client sender, string eventName, params object[] arguments) { Character character = sender.GetCharacter(); switch (eventName) { case "myvehicles_locatecar": vehicle_manager.Vehicle lcVeh = VehicleManager.Vehicles.Single( x => x.NetHandle.Value == Convert.ToInt32(arguments[0]) && x.OwnerId == character.Id); Vector3 loc = API.GetEntityPosition(lcVeh.NetHandle); API.TriggerClientEvent(sender, "myvehicles_setCheckpointToCar", loc.X, loc.Y, loc.Z); API.SendChatMessageToPlayer(sender, "A checkpoint has been set to the vehicle."); break; case "myvehicles_abandoncar": vehicle_manager.Vehicle acVeh = VehicleManager.Vehicles.Single( x => x.Id == Convert.ToInt32(arguments[0]) && x.OwnerId == character.Id); VehicleManager.despawn_vehicle(acVeh); VehicleManager.delete_vehicle(acVeh); acVeh.Delete(); API.SendChatMessageToPlayer(sender, $"You have sucessfully abandoned your ~r~{VehicleOwnership.returnCorrDisplayName(acVeh.VehModel)}~w~"); break; case "myvehicles_sellcar": vehicle_manager.Vehicle scVeh = VehicleManager.Vehicles.Single( x => x.Id == Convert.ToInt32(arguments[0]) && x.OwnerId == character.Id); var tid = (string)arguments[1]; var target = PlayerManager.ParseClient(tid); if (target == null) { API.SendChatMessageToPlayer(sender, "That player isn't online or doesn't exist."); return; } var targetChar = target.GetCharacter(); var targetAccount = target.GetAccount(); var price = 0; if (!int.TryParse((string)arguments[2], out price)) { API.SendChatMessageToPlayer(sender, "Invalid price entered."); return; } if (price < 0) { API.SendChatMessageToPlayer(sender, "Price cannot be negative."); return; } if (targetChar.OwnedVehicles.Count >= VehicleManager.GetMaxOwnedVehicles(targetChar.Client)) { API.SendChatMessageToPlayer(sender, "This player cannot own any more vehicles."); return; } API.SendChatMessageToPlayer(sender, $"Are you sure you would like to sell the ~r~{VehicleOwnership.returnCorrDisplayName(scVeh.VehModel)}~w~ for ~r~${price}~w~ to the player ~r~{targetChar.rp_name()}~w~?"); API.SendChatMessageToPlayer(sender, "Use /confirmsellvehicle to sell."); API.SetEntityData(sender, "sellcar_selling", new dynamic[] { scVeh, targetChar, price }); break; case "groupvehicles_locatecar": vehicle_manager.Vehicle gVeh = VehicleManager.Vehicles.Single( x => x.NetHandle.Value == Convert.ToInt32(arguments[0]) && x.GroupId == character.GroupId); Vector3 location = API.GetEntityPosition(gVeh.NetHandle); API.TriggerClientEvent(sender, "myvehicles_setCheckpointToCar", location.X, location.Y, location.Z); API.SendChatMessageToPlayer(sender, "A checkpoint has been set to the vehicle."); break; } }
public void OnVehicleMenuTrigger(Client player, params object[] arguments) { var vehicleHandle = (NetHandle)arguments[0]; var option = (string)arguments[1]; Character character = player.GetCharacter(); GameVehicle vehicle = API.Shared.GetEntityData(vehicleHandle, "Vehicle"); var playerSeat = API.Shared.GetPlayerVehicleSeat(player); //Check that player vehicle is the same as the menu vehicle... if (API.Shared.GetPlayerVehicle(player) != vehicleHandle) { DebugManager.DebugMessage("[VehicleMenu] " + character.CharacterName + "(" + player.SocialClubName + ", " + player.Handle + ") used VehicleMenu option in a different vehicle handle."); return; } var vehAccess = VehicleManager.DoesPlayerHaveVehicleAccess(player, vehicle); var parkAccess = VehicleManager.DoesPlayerHaveVehicleParkLockAccess(player, vehicle); if ((option.Equals("park") || option.Equals("lock")) && !parkAccess) { API.Shared.SendChatMessageToPlayer(player, "~r~ You do not have access to this vehicle."); return; } if ((option.Equals("engine") || option.Equals("park")) && playerSeat != -1) { API.Shared.SendChatMessageToPlayer(player, "~r~ You can only access these options in the driver seat."); return; } switch (option) { case "engine": if (vehAccess) { VehicleManager.engine_cmd(player); } else { VehicleManager.hotwire_cmd(player); } break; case "lock": var lockState = API.Shared.GetVehicleLocked(vehicleHandle); if (lockState) { API.Shared.SetVehicleLocked(vehicleHandle, false); ChatManager.RoleplayMessage(character, "unlocks the doors of the vehicle.", ChatManager.RoleplayMe); } else { API.Shared.SetVehicleLocked(vehicleHandle, true); ChatManager.RoleplayMessage(character, "locks the doors of the vehicle.", ChatManager.RoleplayMe); } break; case "park": var pos = NAPI.Entity.GetEntityPosition(vehicleHandle); var rot = API.GetEntityRotation(vehicleHandle); var dimension = API.GetEntityDimension(vehicleHandle); vehicle.SpawnPos = pos; vehicle.SpawnRot = rot; vehicle.SpawnDimension = (int)dimension; vehicle.Save(); API.Shared.SendChatMessageToPlayer(player, "Car spawn location saved to current location."); break; case "door": var doorIndex = (int)arguments[2]; var doorName = ""; switch (doorIndex) { case 0: doorName = "front left door"; break; case 1: doorName = "front right door"; break; case 2: doorName = "back left door"; break; case 3: doorName = "back right door"; break; case 4: doorName = "hood"; break; case 5: doorName = "trunk"; break; } var doorState = API.GetVehicleDoorState(vehicleHandle, doorIndex); if (doorState) { API.SetVehicleDoorState(vehicleHandle, doorIndex, false); ChatManager.RoleplayMessage(character, "closed the " + doorName + " of the vehicle.", ChatManager.RoleplayMe); } else { API.SetVehicleDoorState(vehicleHandle, doorIndex, true); ChatManager.RoleplayMessage(character, "opened the " + doorName + " of the vehicle.", ChatManager.RoleplayMe); } break; } }
public void confirmbuyvehicle_cmd(Client player) { Character character = player.GetCharacter(); Account account = player.GetAccount(); var data = API.GetEntityData(player, "sellcar_buying"); if (data != null) { Character buyingFrom = data[0]; Vehicle veh = data[1]; int price = data[2]; //Make sure near him. var buyingPos = buyingFrom.Client.position; if (player.position.DistanceTo(buyingPos) <= 5f) { //make sure still have slots. if (character.OwnedVehicles.Count < VehicleManager.GetMaxOwnedVehicles(character.Client)) { //make sure have money. if (Money.GetCharacterMoney(character) >= price) { //Do actual process. InventoryManager.GiveInventoryItem(buyingFrom, new Money(), price); InventoryManager.DeleteInventoryItem(character, typeof(Money), price); veh.OwnerId = character.Id; veh.OwnerName = character.CharacterName; veh.Save(); //DONE, now spawn if hes vip. if (!veh.IsSpawned) { //He won't be able to buy it anyways if he wasn't VIP... so I THINK he can now have it spawned, right ? :/ if (VehicleManager.spawn_vehicle(veh) != 1) { API.ConsoleOutput( $"There was an error spawning vehicle #{veh.Id} of {character.CharacterName}."); } } //Tell. API.SendChatMessageToPlayer(player, "You have sucessfully bought the car."); API.SendChatMessageToPlayer(buyingFrom.Client, "You have successfully sold the car."); API.SetEntityData(player, "sellcar_buying", null); } else { API.SendChatMessageToPlayer(player, "You don't have enough money."); API.SendChatMessageToPlayer(buyingFrom.Client, "The buyer doesn't have enough money."); API.SetEntityData(player, "sellcar_buying", null); } } else { API.SendChatMessageToPlayer(player, "You can't own anymore vehicles."); API.SendChatMessageToPlayer(buyingFrom.Client, "The buyer can't own anymore vehicles."); API.SetEntityData(player, "sellcar_buying", null); } } else { API.SendChatMessageToPlayer(player, "You must be near the buyer."); API.SendChatMessageToPlayer(buyingFrom.Client, "The buyer must be near you."); API.SetEntityData(player, "sellcar_buying", null); } } else { API.SendChatMessageToPlayer(player, "You aren't buying any car."); } }