From 590abf51651e78b610a39f15acdf92b2c80da1ab Mon Sep 17 00:00:00 2001 From: kookroach Date: Wed, 14 Apr 2021 03:38:00 +0200 Subject: [PATCH] Drop WeaponDeal Items on Disconnect, And equip WeaponDeal Box on Login (in case of Server Crash). --- ReallifeGamemode.Server/Events/Disconnect.cs | 32 ++++++++++++++++++-- ReallifeGamemode.Server/Events/Login.cs | 15 +++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/ReallifeGamemode.Server/Events/Disconnect.cs b/ReallifeGamemode.Server/Events/Disconnect.cs index ab181cb4..ef442350 100644 --- a/ReallifeGamemode.Server/Events/Disconnect.cs +++ b/ReallifeGamemode.Server/Events/Disconnect.cs @@ -15,6 +15,8 @@ using ReallifeGamemode.Server.Services; using ReallifeGamemode.Server.Types; using ReallifeGamemode.Server.Report; using ReallifeGamemode.Server.Factions.Medic; +using ReallifeGamemode.Server.Inventory.Interfaces; +using ReallifeGamemode.Server.Inventory; /** * @overview Life of German Reallife - Event Login (Login.cs) @@ -33,7 +35,7 @@ namespace ReallifeGamemode.Server.Events using var saveUser = new DatabaseContext(); User user = player.GetUser(saveUser); - if(user == null) + if (user == null) { return; } @@ -48,7 +50,7 @@ namespace ReallifeGamemode.Server.Events } if (type == DisconnectionType.Timeout) { - NAPI.Util.ConsoleOutput(player.Name + " Timeoutet"); + NAPI.Util.ConsoleOutput(player.Name + " timed out"); } /*if (GlobalHelper.DutyAdmins.Contains(player)) @@ -131,6 +133,32 @@ namespace ReallifeGamemode.Server.Events } } + List 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; user.PositionX = pos.X; diff --git a/ReallifeGamemode.Server/Events/Login.cs b/ReallifeGamemode.Server/Events/Login.cs index 3ce33dad..de2ba0cd 100644 --- a/ReallifeGamemode.Server/Events/Login.cs +++ b/ReallifeGamemode.Server/Events/Login.cs @@ -11,6 +11,8 @@ using ReallifeGamemode.Server.Util; using ReallifeGamemode.Server.Wanted; using ReallifeGamemode.Database.Entities; using System; +using System.Collections.Generic; +using ReallifeGamemode.Server.Inventory.Interfaces; /** * @overview Life of German Reallife - Event Login (Login.cs) @@ -148,6 +150,19 @@ namespace ReallifeGamemode.Server.Events player.Dimension = 0; } + List 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); NAPI.Task.Run(() => {