Drop WeaponDeal Items on Disconnect, And equip WeaponDeal Box on Login (in case of Server Crash).

This commit is contained in:
2021-04-14 03:38:00 +02:00
parent f006fdffe9
commit 590abf5165
2 changed files with 45 additions and 2 deletions

View File

@@ -15,6 +15,8 @@ using ReallifeGamemode.Server.Services;
using ReallifeGamemode.Server.Types; using ReallifeGamemode.Server.Types;
using ReallifeGamemode.Server.Report; using ReallifeGamemode.Server.Report;
using ReallifeGamemode.Server.Factions.Medic; using ReallifeGamemode.Server.Factions.Medic;
using ReallifeGamemode.Server.Inventory.Interfaces;
using ReallifeGamemode.Server.Inventory;
/** /**
* @overview Life of German Reallife - Event Login (Login.cs) * @overview Life of German Reallife - Event Login (Login.cs)
@@ -48,7 +50,7 @@ namespace ReallifeGamemode.Server.Events
} }
if (type == DisconnectionType.Timeout) if (type == DisconnectionType.Timeout)
{ {
NAPI.Util.ConsoleOutput(player.Name + " Timeoutet"); NAPI.Util.ConsoleOutput(player.Name + " timed out");
} }
/*if (GlobalHelper.DutyAdmins.Contains(player)) /*if (GlobalHelper.DutyAdmins.Contains(player))
@@ -131,6 +133,32 @@ namespace ReallifeGamemode.Server.Events
} }
} }
List<UserItem> fItem = saveUser.UserItems.Where(u => u.UserId == user.Id).ToList();
foreach (var item in fItem)
{
IItem iItem = InventoryManager.GetItemById(item.ItemId);
if (iItem is IWeaponDealItem obj)
{
int amount = item.Amount;
Vector3 dropPosition = PlayerExtension.GetPositionFromPlayer(player, 0.6f, 0);
//new Vector3(player.Position.X, player.Position.Y, player.Position.Z - 0.8f);
Random r = new Random();
GTANetworkAPI.Object grndObject;
Vector3 textPos = dropPosition;
dropPosition.Z -= 1.05f;
grndObject = NAPI.Object.CreateObject(3666746839, dropPosition, new Vector3(0, 0, r.Next(0, 360)), 255, 0);
GroundItem grndItem = new GroundItem { ItemId = iItem.Id, Amount = amount, Position = dropPosition };
TextLabel grndTxtLbl = NAPI.TextLabel.CreateTextLabel(iItem.Name + " ~s~(~y~" + amount + "~s~)", textPos, 5, 0.5f, 4, new Color(255, 255, 255), false, 0);
GroundItem.AddGroundItem(grndItem, grndObject, grndTxtLbl);
saveUser.Remove(item);
}
}
Vector3 pos = player.Position; Vector3 pos = player.Position;
user.PositionX = pos.X; user.PositionX = pos.X;

View File

@@ -11,6 +11,8 @@ using ReallifeGamemode.Server.Util;
using ReallifeGamemode.Server.Wanted; using ReallifeGamemode.Server.Wanted;
using ReallifeGamemode.Database.Entities; using ReallifeGamemode.Database.Entities;
using System; using System;
using System.Collections.Generic;
using ReallifeGamemode.Server.Inventory.Interfaces;
/** /**
* @overview Life of German Reallife - Event Login (Login.cs) * @overview Life of German Reallife - Event Login (Login.cs)
@@ -148,6 +150,19 @@ namespace ReallifeGamemode.Server.Events
player.Dimension = 0; player.Dimension = 0;
} }
List<UserItem> fItem = dbContext.UserItems.Where(u => u.UserId == user.Id).ToList();
foreach (var item in fItem)
{
IItem iItem = InventoryManager.GetItemById(item.ItemId);
if (iItem is IWeaponDealItem obj)
{
player.SyncAnimation("carryBox");
player.AddAttachment("ammobox", false);
NAPI.Player.SetPlayerCurrentWeapon(player, WeaponHash.Unarmed);
break;
}
}
player.TriggerEvent("draw", player.Name, player.Handle.Value); player.TriggerEvent("draw", player.Name, player.Handle.Value);
NAPI.Task.Run(() => NAPI.Task.Run(() =>
{ {