This commit is contained in:
hydrant
2021-04-02 21:48:59 +02:00
parent b032934f0e
commit 8cbab7ef15
3 changed files with 84 additions and 45 deletions

View File

@@ -12,20 +12,18 @@ export default function playerBlips() {
var entityMp = <EntityMp>entity; var entityMp = <EntityMp>entity;
mp.gui.chat.push("Player recieved: Yes"); mp.gui.chat.push("Player recieved: Yes");
let color = parseInt(entity.getVariable("blipColor")); let color = parseInt(entity.getVariable("blipColor"));
mp.gui.chat.push("Color : " + color); mp.gui.chat.push("Color : " + color);
entity.createBlip(1); entity.createBlip(1);
mp.gui.chat.push(parseInt(entity.blip) == 0 ? "Blip was not created" : "Blip was created"); mp.gui.chat.push(parseInt(entity.blip) == 0 ? "Blip was not created" : "Blip was created");
mp.gui.chat.push("entity.blip is actually " + entity.blip); mp.gui.chat.push("entity.blip is actually " + entity.blip);
var blip = mp.blips.at(entity.blip); var blip = entity.blip;
blip.dimension = entityMp.dimension;
mp.gui.chat.push("1 -" + blip.getAlpha() + " 2- " + blip.doesExist() + " 3-" + blip.dimension + " 4-" + entityMp.dimension); mp.gui.chat.push("1 -" + blip.getAlpha() + " 2- " + blip.doesExist() + " 3-" + blip.dimension + " 4-" + entityMp.dimension);
@@ -34,8 +32,8 @@ export default function playerBlips() {
mp.game.invoke(Natives.SET_BLIP_CATEGORY, entity.blip, 7); mp.game.invoke(Natives.SET_BLIP_CATEGORY, entity.blip, 7);
mp.game.invoke(Natives.SHOW_HEADING_INDICATOR_ON_BLIP, entity.blip, true); mp.game.invoke(Natives.SHOW_HEADING_INDICATOR_ON_BLIP, entity.blip, true);
mp.game.invoke(Natives.SET_BLIP_AS_SHORT_RANGE, entity.blip, true); mp.game.invoke(Natives.SET_BLIP_AS_SHORT_RANGE, entity.blip, true);
//mp.game.invoke(Natives.SET_BLIP_DISPLAY, entity.blip, 8); mp.game.invoke(Natives.SET_BLIP_DISPLAY, entity.blip, 8);
} }
}); });
*/ */

View File

@@ -12,6 +12,7 @@ const Point = NativeUI.Point;
const Color = NativeUI.Color; const Color = NativeUI.Color;
let screenRes = mp.game.graphics.getScreenResolution(0, 0); let screenRes = mp.game.graphics.getScreenResolution(0, 0);
import vehicleColors from './colors'; import vehicleColors from './colors';
import moneyformat from '../moneyformat';
export default function tuning(globalData: IGlobalData) { export default function tuning(globalData: IGlobalData) {
var keyBound = false; var keyBound = false;
@@ -53,6 +54,10 @@ export default function tuning(globalData: IGlobalData) {
{ Slot: 38, Name: "Hydraulik", Price: 2000 }, { Slot: 38, Name: "Hydraulik", Price: 2000 },
{ Slot: 39, Name: "Motorabdeckung", Price: 2000 }, { Slot: 39, Name: "Motorabdeckung", Price: 2000 },
{ Slot: 40, Name: "Luftfilter", Price: 2000 }, { Slot: 40, Name: "Luftfilter", Price: 2000 },
{ Slot: 41, Name: "Domstrebe", Price: 2000 },
{ Slot: 42, Name: "Scheinwerferabdeckung", Price: 2000 },
{ Slot: 43, Name: "Nebelscheinwerfer", Price: 2000 },
{ Slot: 44, Name: "Dach-Extra", Price: 2000 },
{ Slot: 46, Name: "Fenster", Price: 2000 }, { Slot: 46, Name: "Fenster", Price: 2000 },
{ Slot: 48, Name: "Design", Price: 2000 } { Slot: 48, Name: "Design", Price: 2000 }
]; ];
@@ -156,6 +161,10 @@ export default function tuning(globalData: IGlobalData) {
} }
}); });
var currentMod = new Array<number>();
var currentActiveModItem = new Array<NativeUI.UIMenuItem>();
var currentSelectedItem: VehicleModMenuItem = null;
mp.events.add("showTuningMenu", () => { mp.events.add("showTuningMenu", () => {
mp.events.call("hideTuningInfo", false); mp.events.call("hideTuningInfo", false);
mp.gui.chat.show(false); mp.gui.chat.show(false);
@@ -178,12 +187,8 @@ export default function tuning(globalData: IGlobalData) {
repairItem.BackColor = new Color(94, 94, 94); repairItem.BackColor = new Color(94, 94, 94);
repairItem.HighlightedBackColor = new Color(105, 105, 105); repairItem.HighlightedBackColor = new Color(105, 105, 105);
var currentMod = new Array<number>();
var currentActiveModItem = new Array<NativeUI.UIMenuItem>();
carModTypes.forEach((modType) => { carModTypes.forEach((modType) => {
var mod: number = null;
var mod = null;
if (modType === 22) { // Lichter if (modType === 22) { // Lichter
var hlColor = localVehicle.getVariable("headlightColor"); var hlColor = localVehicle.getVariable("headlightColor");
@@ -221,6 +226,10 @@ export default function tuning(globalData: IGlobalData) {
} }
} }
mp.gui.chat.push("getting price for modtype = " + modType.toString() + ", modtypename = " + modName);
var price = getModSlotPrice(modType);
if (mod === null) { if (mod === null) {
mod = localVehicle.getMod(modType); mod = localVehicle.getMod(modType);
} }
@@ -247,7 +256,8 @@ export default function tuning(globalData: IGlobalData) {
modText = mp.game.ui.getLabelText(localVehicle.getModTextLabel(modType, x)); modText = mp.game.ui.getLabelText(localVehicle.getModTextLabel(modType, x));
if (modText === "NULL") modText = getModName(localVehicle, modType, x); if (modText === "NULL") modText = getModName(localVehicle, modType, x);
} }
var item = new UIMenuItem(modText); var item = new VehicleModMenuItem(modText);
item.price = price;
modMenu.AddItem(item); modMenu.AddItem(item);
if (x === mod) { if (x === mod) {
@@ -255,6 +265,9 @@ export default function tuning(globalData: IGlobalData) {
currentActiveModItem[modType] = item; currentActiveModItem[modType] = item;
modMenu.CurrentSelection = x; modMenu.CurrentSelection = x;
} }
else {
item.SetRightLabel("$"+ moneyformat(price));
}
} }
modMenu.IndexChange.on((index: number) => { modMenu.IndexChange.on((index: number) => {
@@ -272,13 +285,13 @@ export default function tuning(globalData: IGlobalData) {
} }
}); });
modMenu.ItemSelect.on((item: NativeUI.UIMenuItem, index: number) => { modMenu.ItemSelect.on((item: VehicleModMenuItem, index: number) => {
currentMod[modType] = index - 1; if (currentMod[modType] == index - 1) {
currentActiveModItem[modType].SetRightBadge(BadgeStyle.None); return;
item.SetRightBadge(BadgeStyle.Car); }
currentActiveModItem[modType] = item;
mp.events.callRemote("setVehicleMod", modType, index); currentSelectedItem = item;
mp.events.callRemote("setVehicleMod", modType, index, price);
}); });
modMenu.MenuClose.on(() => { modMenu.MenuClose.on(() => {
@@ -311,6 +324,13 @@ export default function tuning(globalData: IGlobalData) {
}); });
mp.events.add("SERVER:Tuning_ModSucessfull", (modType: number, index: number) => {
currentMod[modType] = index - 1;
currentActiveModItem[modType].SetRightLabel("$" + moneyformat(currentSelectedItem.price));
currentSelectedItem.SetRightBadge(BadgeStyle.Car);
currentActiveModItem[modType] = currentSelectedItem;
});
mp.events.add("playerLeaveVehicle", () => { mp.events.add("playerLeaveVehicle", () => {
if (keyBound) { if (keyBound) {
mp.events.call("hideTuningInfo", true); mp.events.call("hideTuningInfo", true);
@@ -435,6 +455,10 @@ export default function tuning(globalData: IGlobalData) {
return realModName; return realModName;
} }
function getModSlotPrice(modType: number): number {
return carModSlotName.filter(x => x.Slot == modType)[0].Price;
}
function setHeadlightsColor(vehicle, index) { function setHeadlightsColor(vehicle, index) {
if (!vehicle) { if (!vehicle) {
@@ -552,4 +576,8 @@ export default function tuning(globalData: IGlobalData) {
mp.events.callRemote("CLIENT:TuningManager_SetVehicleColor", false, color); mp.events.callRemote("CLIENT:TuningManager_SetVehicleColor", false, color);
} }
class VehicleModMenuItem extends UIMenuItem {
public price: number;
}
} }

View File

@@ -92,8 +92,22 @@ namespace ReallifeGamemode.Server.Managers
} }
[RemoteEvent("setVehicleMod")] [RemoteEvent("setVehicleMod")]
public void SetVehicleMod(Player player, int slot, int index) public void SetVehicleMod(Player player, int slot, int index, int price)
{ {
using var dbContext = new DatabaseContext();
User user = player.GetUser(dbContext);
if (user.BankAccount.Balance < price)
{
player.SendNotification("Du hast nicht genug Geld für dieses Tuningteil!");
return;
}
else
{
user.BankAccount.Balance -= price;
}
player.TriggerEvent("SERVER:Tuning_ModSucessfull", slot, index);
Vehicle pV = player.Vehicle; Vehicle pV = player.Vehicle;
if (index == 0) index--; if (index == 0) index--;
@@ -118,41 +132,40 @@ namespace ReallifeGamemode.Server.Managers
NAPI.ClientEvent.TriggerClientEventForAll("vehicleToggleMod", pV, slot, newVal); NAPI.ClientEvent.TriggerClientEventForAll("vehicleToggleMod", pV, slot, newVal);
} }
ServerVehicle sV = player.Vehicle.GetServerVehicle(); dbContext.SaveChanges();
ServerVehicle sV = player.Vehicle.GetServerVehicle(dbContext);
if (sV == null) return; if (sV == null) return;
using (var dbContext = new DatabaseContext()) VehicleMod vMod = dbContext.VehicleMods.FirstOrDefault(m => m.ServerVehicleId == sV.Id && m.Slot == slot);
if (vMod == null && index != -1)
{ {
VehicleMod vMod = dbContext.VehicleMods.FirstOrDefault(m => m.ServerVehicleId == sV.Id && m.Slot == slot); vMod = new VehicleMod
if (vMod == null && index != -1) {
ServerVehicleId = sV.Id,
Slot = slot,
ModId = index
};
dbContext.VehicleMods.Add(vMod);
}
else if (vMod != null && index == -1)
{
dbContext.VehicleMods.Remove(vMod);
}
else
{
if (vMod == null)
{ {
vMod = new VehicleMod vMod = new VehicleMod
{ {
ServerVehicleId = sV.Id, ServerVehicleId = sV.Id,
Slot = slot, Slot = slot
ModId = index
}; };
dbContext.VehicleMods.Add(vMod); dbContext.VehicleMods.Add(vMod);
} }
else if (vMod != null && index == -1) vMod.ModId = index;
{
dbContext.VehicleMods.Remove(vMod);
}
else
{
if (vMod == null)
{
vMod = new VehicleMod
{
ServerVehicleId = sV.Id,
Slot = slot
};
dbContext.VehicleMods.Add(vMod);
}
vMod.ModId = index;
}
dbContext.SaveChanges();
} }
dbContext.SaveChanges();
} }
[RemoteEvent("CLIENT:TuningManager_SetVehicleColor")] [RemoteEvent("CLIENT:TuningManager_SetVehicleColor")]