Clientside Ammunation
This commit is contained in:
@@ -15,16 +15,12 @@ export default function ammunation(globalData: IGlobalData) {
|
||||
var weapons: Weapon[];
|
||||
|
||||
mp.events.add("AmmunationShop:LoadNativeUI", (weaponList: string) => {
|
||||
mp.gui.chat.push("a "+ weaponList);
|
||||
//mp.gui.chat.activate(false);
|
||||
//globalData.InMenu = true;
|
||||
weapons = JSON.parse(weaponList);
|
||||
mp.gui.chat.push("b " +weapons.toString());
|
||||
|
||||
weapons = JSON.parse(weaponList);
|
||||
var menu = getAmmunationMenu();
|
||||
|
||||
//Schaut nach ob mindestens eine Waffe in weapons existiert welche die CategoryId beinhaltet
|
||||
for (var c = 1; c < 9; c++) {
|
||||
for (var c = 1; c < 10; c++) {
|
||||
switch (c) {
|
||||
case 1: { //Meelee
|
||||
|
||||
@@ -33,35 +29,62 @@ export default function ammunation(globalData: IGlobalData) {
|
||||
|
||||
case 2: { //Pistolen
|
||||
if (weapons.find(w => w.CategoryId == c)) {
|
||||
var pistolItem = new MenuItem("Pistolen", "",);
|
||||
var pistolItem = new MenuItem("Pistolen", "Das kleine Kaliber",);
|
||||
menu.AddItem(pistolItem);
|
||||
menu.BindMenuToItem(getWeaponsFromCategory(menu, c, "Pistolen"),pistolItem);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 9: { //Sonstiges (Armor / Fallschirm)
|
||||
var otherItem = new MenuItem("Sonstiges", "Schutzwesten, Fallschirme...",);
|
||||
menu.AddItem(otherItem);
|
||||
menu.BindMenuToItem(getWeaponsFromCategory(menu, c, "Sonstiges"), otherItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
menu.Open();
|
||||
mp.gui.chat.activate(false);
|
||||
globalData.InMenu = true;
|
||||
|
||||
|
||||
|
||||
menu.MenuClose.on(() => {
|
||||
globalData.InMenu = false;
|
||||
mp.gui.chat.show(true);
|
||||
})
|
||||
});
|
||||
|
||||
function getAmmunationMenu(): NativeUI.Menu {
|
||||
return new Menu("Ammunation", "", new Point(0, screenRes.y / 3), null, null);
|
||||
return new Menu("", "AMMU NATION - Waffenladen", new Point(0, screenRes.y / 3), "shopui_title_gunclub", "shopui_title_gunclub");
|
||||
}
|
||||
|
||||
function getWeaponsFromCategory(parentMenu: NativeUI.Menu, category: number, categoryName: string): NativeUI.Menu {
|
||||
var categoryMenu = new Menu(categoryName, "", new Point(0, screenRes.y / 3), null, null);
|
||||
var categoryMenu = new Menu("", categoryName, new Point(0, screenRes.y / 3), "shopui_title_gunclub", "shopui_title_gunclub");
|
||||
|
||||
categoryMenu.Visible = false;
|
||||
|
||||
var cWeapons: Weapon[] = weapons.filter(w => w.CategoryId == category);
|
||||
|
||||
if (category < 9) { //Weapons aus Datenbank
|
||||
cWeapons.forEach(weapon => {
|
||||
var menuItem = new MenuItem(weapon.WeaponModel, "Munition: " + weapon.Ammo);
|
||||
categoryMenu.AddItem(menuItem);
|
||||
menuItem.SetRightLabel("~g~$~w~" + weapon.Price.toString());
|
||||
var weaponItem: NativeUI.UIMenuItem = new MenuItem(weapon.WeaponModel, "Munition: " + weapon.Ammo, [weapon.WeaponModel, weapon.Ammo, weapon.Price]);
|
||||
categoryMenu.AddItem(weaponItem);
|
||||
weaponItem.SetRightLabel("~g~$" + weapon.Price.toString());
|
||||
})
|
||||
categoryMenu.ItemSelect.on((item: NativeUI.UIMenuItem, index: number) => {
|
||||
mp.events.callRemote("CLIENT:Ammunation_BuyWeapon", item.Data[0], item.Data[1], item.Data[2]); //weaponmodel / ammo / price
|
||||
});
|
||||
} else { //Sonstiges = Schutzwesten / Fallschirme
|
||||
var armorItem = new MenuItem("Schutzweste", "Sch\u00fctzt dich");
|
||||
categoryMenu.AddItem(armorItem);
|
||||
armorItem.SetRightLabel("~g~$3000");
|
||||
|
||||
var parachuteItem = new MenuItem("Fallschirm", "Flieg damit wohin du willst");
|
||||
categoryMenu.AddItem(parachuteItem);
|
||||
parachuteItem.SetRightLabel("~g~$500");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return categoryMenu;
|
||||
|
||||
};
|
||||
};
|
||||
@@ -19,5 +19,8 @@ namespace ReallifeGamemode.Database.Entities
|
||||
public int SlotID { get; set; }
|
||||
public int Ammo { get; set; }
|
||||
public float Price { get; set; }
|
||||
|
||||
public bool Legal { get; set; }
|
||||
public bool AmmunationActive { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
1981
ReallifeGamemode.Database/Migrations/20210416175726_Ammunations2.Designer.cs
generated
Normal file
1981
ReallifeGamemode.Database/Migrations/20210416175726_Ammunations2.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace ReallifeGamemode.Database.Migrations
|
||||
{
|
||||
public partial class Ammunations2 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "AmmunationActive",
|
||||
table: "Weapons",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "Legal",
|
||||
table: "Weapons",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "AmmunationActive",
|
||||
table: "Weapons");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Legal",
|
||||
table: "Weapons");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1600,9 +1600,15 @@ namespace ReallifeGamemode.Database.Migrations
|
||||
b.Property<int>("Ammo")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("AmmunationActive")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<int>("CategoryId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<bool>("Legal")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<float>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ using Newtonsoft.Json;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using ReallifeGamemode.Server.Managers;
|
||||
using ReallifeGamemode.Server.Services;
|
||||
|
||||
namespace ReallifeGamemode.Server.Shop.Ammunation
|
||||
{
|
||||
@@ -25,7 +27,7 @@ namespace ReallifeGamemode.Server.Shop.Ammunation
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
weaponList = dbContext.Weapons.ToList();
|
||||
weaponList = dbContext.Weapons.ToList().FindAll(w => w.AmmunationActive == true);
|
||||
}
|
||||
}
|
||||
public void LoadShopNUI(Player client)
|
||||
@@ -34,5 +36,25 @@ namespace ReallifeGamemode.Server.Shop.Ammunation
|
||||
List<Weapon> shopWeapons = weaponList.ToList();
|
||||
client.TriggerEvent("AmmunationShop:LoadNativeUI", JsonConvert.SerializeObject(shopWeapons));
|
||||
}
|
||||
|
||||
[RemoteEvent("CLIENT:Ammunation_BuyWeapon")]
|
||||
public void AmmunationBuyWeapoon(Player player, WeaponHash weaponmodel, int ammo , int price)
|
||||
{
|
||||
player.SendChatMessage("JO IS ANGEKOMMEN" + weaponmodel + " " + ammo + " " + price);
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User user = player.GetUser(dbContext);
|
||||
|
||||
if (user.Handmoney < price)
|
||||
{
|
||||
player.SendNotification("Du hast nicht genügend Geld bei dir");
|
||||
return;
|
||||
}
|
||||
user.Handmoney -= price;
|
||||
dbContext.SaveChanges();
|
||||
player.GiveWeapon((WeaponHash)weaponmodel, ammo);
|
||||
//client.TriggerEvent("SERVER:SET_HANDMONEY", user.Handmoney);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user