diff --git a/ReallifeGamemode.Server/Events/UpdateCharacterCloth.cs b/ReallifeGamemode.Server/Events/UpdateCharacterCloth.cs index 876e1013..72c1351d 100644 --- a/ReallifeGamemode.Server/Events/UpdateCharacterCloth.cs +++ b/ReallifeGamemode.Server/Events/UpdateCharacterCloth.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using GTANetworkAPI; using Newtonsoft.Json; @@ -111,7 +111,18 @@ namespace ReallifeGamemode.Server.Events { for (var x = 0; x < slotType.Length; x++) { - var loopCloth = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == slotType[x] && u.SlotId == slotId[x]); + var loopCloth = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == (byte)slotType[x] && u.SlotId == slotId[x]); + + if (loopCloth == null) + { + loopCloth = new CharacterCloth() + { + UserId = user.Id, + SlotType = (byte)slotType[x], + SlotId = slotId[x] + }; + } + loopCloth.ClothId = clothId[x]; } CharacterCloth torso = context.CharacterClothes.FirstOrDefault(u => u.UserId == user.Id && u.SlotType == 0 && u.SlotId == 3); @@ -164,7 +175,7 @@ namespace ReallifeGamemode.Server.Events * [5] UndershirtTextureID * [6] Price */ - + int[] data = JsonConvert.DeserializeObject(jsonData); User user = client.GetUser(); if (user.Handmoney < data[6]) @@ -172,7 +183,7 @@ namespace ReallifeGamemode.Server.Events client.TriggerEvent("clothesMenu:Error"); return; } - + if (type == "clothe") { if (data[0] == 11)//for tops @@ -187,10 +198,10 @@ namespace ReallifeGamemode.Server.Events } using (var dbContext = new DatabaseContext()) { - + var clothes = dbContext.CharacterClothes.FirstOrDefault(c => c.UserId == user.Id && c.SlotId == data[0] && c.Duty == false); - if(clothes == null) + if (clothes == null) { CharacterCloth newCloth = new CharacterCloth { @@ -210,11 +221,11 @@ namespace ReallifeGamemode.Server.Events clothes.ClothId = data[2]; clothes.Texture = data[1]; } - if(data[0] == 11) + if (data[0] == 11) { var torso = dbContext.CharacterClothes.FirstOrDefault(c => c.UserId == user.Id && c.SlotId == 3 && c.Duty == false); var undershirt = dbContext.CharacterClothes.FirstOrDefault(c => c.UserId == user.Id && c.SlotId == 8 && c.Duty == false); - if(torso == null) + if (torso == null) { CharacterCloth newTorso = new CharacterCloth { @@ -232,7 +243,7 @@ namespace ReallifeGamemode.Server.Events { torso.ClothId = data[3]; } - if(undershirt == null) + if (undershirt == null) { CharacterCloth newUndershirt = new CharacterCloth { @@ -240,7 +251,7 @@ namespace ReallifeGamemode.Server.Events Duty = false, SlotType = 0, SlotId = 8, - ClothId = data[4], + ClothId = data[4], Texture = data[5] }; dbContext.CharacterClothes.Add(newUndershirt);