Add ItemShop, fix ClotheShop Payment, fix Vehicle Respawn, Add Vehicle Lock from outside
This commit is contained in:
@@ -863,5 +863,42 @@ namespace ReallifeGamemode.Server.Managers
|
||||
ChatService.SendMessage(target, $"{client.Name} hat deine Anfrage angenommen.");
|
||||
|
||||
}
|
||||
|
||||
[RemoteEvent("SERVER:BuyItems")]
|
||||
public void SrvEvent_BuyItem(Client client, string itemName)
|
||||
{
|
||||
IItem shopItem = GetItemByName(itemName);
|
||||
|
||||
using(var dbContext = new DatabaseContext()){
|
||||
User user = client.GetUser(dbContext);
|
||||
|
||||
if (user.Handmoney < shopItem.Price)
|
||||
{
|
||||
client.TriggerEvent("itemMenu:Error");
|
||||
return;
|
||||
}
|
||||
|
||||
UserItem item = dbContext.UserItems.Where(i => i.ItemId == shopItem.Id && i.UserId == user.Id).FirstOrDefault();
|
||||
if(item == null)
|
||||
{
|
||||
var newItem = new UserItem
|
||||
{
|
||||
ItemId = shopItem.Id,
|
||||
UserId = user.Id,
|
||||
Amount = 1,
|
||||
Slot = -1
|
||||
};
|
||||
dbContext.UserItems.Add(newItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Amount += 1;
|
||||
}
|
||||
user.Handmoney -= shopItem.Price;
|
||||
dbContext.SaveChanges();
|
||||
client.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user