[+] Start WeaponDeal-System
This commit is contained in:
@@ -190,7 +190,7 @@ namespace ReallifeGamemode.Server.Managers
|
||||
{
|
||||
foreach (Vehicle veh in NAPI.Pools.GetAllVehicles())
|
||||
{
|
||||
if (veh.Position.DistanceTo(client.Position) < 2.5f)
|
||||
if (veh.Position.DistanceTo(client.Position) < 5f)
|
||||
{
|
||||
if (VehicleStreaming.GetDoorState(veh, DoorID.DoorTrunk) == DoorState.DoorOpen)
|
||||
{
|
||||
@@ -253,6 +253,13 @@ namespace ReallifeGamemode.Server.Managers
|
||||
};
|
||||
|
||||
UserItem uItem = context.UserItems.Where(u => u.UserId == user.Id && u.ItemId == cItem.ItemId).FirstOrDefault();
|
||||
IItem iItem = GetItemById(cItem.ItemId);
|
||||
|
||||
if(iItem is IWeaponDealItem weaponDealItem)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (uItem != null)
|
||||
{
|
||||
if (vehAmount < uItem.Amount)
|
||||
@@ -407,6 +414,53 @@ namespace ReallifeGamemode.Server.Managers
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddItemToVehicleInventory(Client player, VehicleItem item, Vehicle veh)
|
||||
{
|
||||
var user = player.GetUser();
|
||||
using (var context = new DatabaseContext())
|
||||
{
|
||||
ServerVehicle sVeh = VehicleManager.GetServerVehicleFromVehicle(veh);
|
||||
VehicleItem existingItem = context.VehicleItems.FirstOrDefault(i => i.ItemId == item.ItemId && i.VehicleId == sVeh.Id);
|
||||
if (existingItem != null)
|
||||
{
|
||||
existingItem.Amount += item.Amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
List<VehicleItem> allItemsByVehicle = context.VehicleItems.ToList().FindAll(i => i.VehicleId == sVeh.Id);
|
||||
var slotArr = Enumerable.Range(1, 20).ToList();
|
||||
allItemsByVehicle.ForEach(allItem =>
|
||||
{
|
||||
if (slotArr.Contains(allItem.Slot)) slotArr.Remove(allItem.Slot);
|
||||
});
|
||||
|
||||
int newSlot = slotArr.Min();
|
||||
|
||||
item.Slot = newSlot;
|
||||
context.VehicleItems.Add(item);
|
||||
|
||||
IItem iItem = GetItemById(item.ItemId);
|
||||
|
||||
string[] newItem = new string[] { iItem.Name, iItem.Description, iItem.Gewicht.ToString(), item.Amount.ToString(), newSlot.ToString(), item.Id.ToString() };
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveAllItemsfromVehicleInventory(Vehicle veh)
|
||||
{
|
||||
using(var context = new DatabaseContext())
|
||||
{
|
||||
ServerVehicle sVeh = VehicleManager.GetServerVehicleFromVehicle(veh);
|
||||
List<VehicleItem> allItemsByVehicle = context.VehicleItems.ToList().FindAll(i => i.VehicleId == sVeh.Id);
|
||||
allItemsByVehicle.ForEach(allItem =>
|
||||
{
|
||||
context.Remove(allItem);
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
[RemoteEvent("removeItemAsAdmin")]
|
||||
public void RemoveAsAdminInventory(Client player, string amount, string userItemId, string targetPlayerName)
|
||||
{
|
||||
@@ -486,10 +540,19 @@ namespace ReallifeGamemode.Server.Managers
|
||||
if (iItem is IDroppableItem usableItemObj2)
|
||||
{
|
||||
Vector3 dropPosition = ClientExtension.GetPositionFromPlayer(player, 0.6f, 0);
|
||||
dropPosition.Z -= 0.8f;
|
||||
//new Vector3(player.Position.X, player.Position.Y, player.Position.Z - 0.8f);
|
||||
Random r = new Random();
|
||||
GTANetworkAPI.Object grndObject = NAPI.Object.CreateObject(3777723516, dropPosition, new Vector3(0, 0, r.Next(0, 360)), 0);
|
||||
GTANetworkAPI.Object grndObject;
|
||||
if (iItem is IWeaponDealItem obj)
|
||||
{
|
||||
dropPosition.Z -= 1.05f;
|
||||
grndObject = NAPI.Object.CreateObject(3666746839, dropPosition, new Vector3(0, 0, r.Next(0, 360)), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
dropPosition.Z -= 0.8f;
|
||||
grndObject = NAPI.Object.CreateObject(3777723516, dropPosition, new Vector3(0, 0, r.Next(0, 360)), 0);
|
||||
}
|
||||
GroundItem grndItem = new GroundItem { ItemId = iItem.Id, Amount = amount, Position = dropPosition };
|
||||
TextLabel grndTxtLbl = NAPI.TextLabel.CreateTextLabel(iItem.Name + " ~s~(~y~" + amount + "~s~)", dropPosition, 5, 0.5f, 4, new Color(255, 255, 255), false, 0);
|
||||
GroundItem.AddGroundItem(grndItem, grndObject, grndTxtLbl);
|
||||
|
||||
Reference in New Issue
Block a user