Changed whole project structure (split client and server into separat projects)
This commit is contained in:
570
ReallifeGamemode.Client/Tuning/main.js
Normal file
570
ReallifeGamemode.Client/Tuning/main.js
Normal file
@@ -0,0 +1,570 @@
|
||||
/**
|
||||
* @overview Life of German Reallife - Tuning tuning.js
|
||||
* @author hydrant
|
||||
* @copyright (c) 2008 - 2018 Life of German
|
||||
*/
|
||||
|
||||
var keyBound = false;
|
||||
|
||||
var disableInput = [75, 278, 279, 280, 281, 23, 59, 60, 71, 72, 74];
|
||||
|
||||
var carModTypes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 22, 25, 27, 28, 33, 34, 35, 38, 39, 40, 41, 42, 43, 44, 46, 48, 69];
|
||||
|
||||
var carModSlotName = [
|
||||
{ Slot: 0, Name: "Spoiler" },
|
||||
{ Slot: 1, Name: "Frontstoßstange"},
|
||||
{ Slot: 2, Name: "Heckstoßstange"},
|
||||
{ Slot: 3, Name: "Seitenschweller"},
|
||||
{ Slot: 4, Name: "Auspuff"},
|
||||
{ Slot: 5, Name: "Rahmen"},
|
||||
{ Slot: 6, Name: "Kühlergrill"},
|
||||
{ Slot: 7, Name: "Motorhaube"},
|
||||
{ Slot: 8, Name: "Kotflügel"},
|
||||
{ Slot: 9, Name: "Rechter Kotflügel"},
|
||||
{ Slot: 10, Name: "Dach"},
|
||||
{ Slot: 11, Name: "Motor" },
|
||||
{ Slot: 12, Name: "Bremsen"},
|
||||
{ Slot: 13, Name: "Getriebe"},
|
||||
{ Slot: 14, Name: "Hupe"},
|
||||
{ Slot: 15, Name: "Federung"},
|
||||
{ Slot: 18, Name: "Turbo"},
|
||||
{ Slot: 22, Name: "Licht"},
|
||||
{ Slot: 23, Name: "Reifen" },
|
||||
{ Slot: 25, Name: "Nummernschildhalter" },
|
||||
{ Slot: 27, Name: "Innenausstatung" },
|
||||
{ Slot: 28, Name: "Wackelkopf" },
|
||||
{ Slot: 33, Name: "Lenkrad" },
|
||||
{ Slot: 34, Name: "Schalthebel" },
|
||||
{ Slot: 35, Name: "Schild" },
|
||||
{ Slot: 38, Name: "Hydraulik" },
|
||||
{ Slot: 39, Name: "Motorabdeckung" },
|
||||
{ Slot: 40, Name: "Luftfilter" },
|
||||
{ Slot: 46, Name: "Fenster" },
|
||||
{ Slot: 48, Name: "Design" }
|
||||
];
|
||||
|
||||
var customPartNames = [
|
||||
{
|
||||
Model: 1093792632,
|
||||
Names: [
|
||||
{
|
||||
Slot: 8,
|
||||
Name: "Lüftungsschlitze"
|
||||
},
|
||||
{
|
||||
Slot: 43,
|
||||
Name: "Motorhaubenstifte"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
Model: 223240013,
|
||||
Names: [
|
||||
{
|
||||
Slot: 9,
|
||||
Name: "Heckkotflügel"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
Model: 1031562256,
|
||||
Names: [
|
||||
{
|
||||
Slot: 5,
|
||||
Name: "Stoßdämpfer"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
Model: 3308022675,
|
||||
Names: [
|
||||
{
|
||||
Slot: 9,
|
||||
Name: "Kotflügel"
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
var doorOpeners = [
|
||||
{
|
||||
Model: 3308022675,
|
||||
Doors: [
|
||||
{
|
||||
Slot: 5,
|
||||
Door: 4
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
var bikeModTypes = [];
|
||||
|
||||
const NativeUI = require("nativeui");
|
||||
const Menu = NativeUI.Menu;
|
||||
const UIMenuItem = NativeUI.UIMenuItem;
|
||||
const BadgeStyle = NativeUI.BadgeStyle;
|
||||
const Point = NativeUI.Point;
|
||||
|
||||
var mainMenu;
|
||||
var modMenu;
|
||||
var closeMenu = false;
|
||||
|
||||
mp.events.add('showTuningInfo', () => {
|
||||
mp.game.ui.setTextComponentFormat('STRING');
|
||||
mp.game.ui.addTextComponentSubstringPlayerName('Drücke ~INPUT_CONTEXT~, um dein Fahrzeug zu modifizieren');
|
||||
mp.game.ui.displayHelpTextFromStringLabel(0, true, true, -1);
|
||||
|
||||
mp.keys.bind(0x45, false, keyPressHandler);
|
||||
keyBound = true;
|
||||
});
|
||||
|
||||
mp.events.add('hideTuningInfo', (unbind) => {
|
||||
mp.game.ui.clearHelp(true);
|
||||
mp.gui.chat.show(true);
|
||||
|
||||
if (mp.players.local.vehicle) {
|
||||
mp.players.local.vehicle.setLights(0);
|
||||
}
|
||||
|
||||
if (typeof mainMenu !== "undefined" && unbind) {
|
||||
mainMenu.Close();
|
||||
globalData.InTuning = false;
|
||||
}
|
||||
|
||||
if (typeof modMenu !== "undefined" && modMenu.Visible && unbind) {
|
||||
closeMenu = true;
|
||||
modMenu.Close();
|
||||
globalData.InTuning = false;
|
||||
}
|
||||
|
||||
if (keyBound && unbind) {
|
||||
mp.keys.unbind(0x45, false, keyPressHandler);
|
||||
keyBound = false;
|
||||
}
|
||||
});
|
||||
|
||||
function keyPressHandler() {
|
||||
mp.events.callRemote("startPlayerTuning");
|
||||
}
|
||||
|
||||
mp.events.add("render", () => {
|
||||
if (globalData.InTuning) {
|
||||
disableInput.forEach((input) => {
|
||||
mp.game.controls.disableControlAction(1, input, true);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
mp.events.add("showTuningMenu", () => {
|
||||
mp.events.call("hideTuningInfo" , false);
|
||||
mp.gui.chat.show(false);
|
||||
|
||||
var localPlayer = mp.players.local;
|
||||
var localVehicle = localPlayer.vehicle;
|
||||
|
||||
localVehicle.setHalt(1.0, 1, false);
|
||||
|
||||
if (typeof mainMenu !== "undefined" && mainMenu.Visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof modMenu !== "undefined" && modMenu.Visible) {
|
||||
return;
|
||||
}
|
||||
|
||||
globalData.InTuning = true;
|
||||
|
||||
localVehicle.setLights(1);
|
||||
|
||||
var carName = mp.game.ui.getLabelText(mp.game.vehicle.getDisplayNameFromVehicleModel(localVehicle.model));
|
||||
|
||||
mainMenu = new Menu("Fahrzeugwerkstatt", carName, new Point(50, 50));
|
||||
|
||||
if (localVehicle.getBodyHealth() !== 1000) {
|
||||
|
||||
var repairItem = new UIMenuItem("Fahrzeug reparieren");
|
||||
mainMenu.AddItem(repairItem);
|
||||
|
||||
mainMenu.ItemSelect.on((selectedItem, index) => {
|
||||
if (selectedItem === repairItem) {
|
||||
mp.events.callRemote("repairVehicle");
|
||||
mainMenu.Close();
|
||||
setTimeout(() => {
|
||||
mp.events.call("showTuningMenu");
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
|
||||
mainMenu.MenuClose.on(() => {
|
||||
globalData.InTuning = false;
|
||||
mp.events.call("hideTuningInfo", false);
|
||||
});
|
||||
|
||||
mainMenu.Open();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
carModTypes.forEach((modType) => {
|
||||
if (localVehicle.getModSlotName(modType) !== "undefined") {
|
||||
var slotName = mp.game.ui.getLabelText(localVehicle.getModSlotName(modType));
|
||||
|
||||
if (slotName === "NULL") {
|
||||
slotName = getCustomName(localVehicle.model, modType);
|
||||
if (slotName === undefined) slotName = getSlotName(modType);
|
||||
}
|
||||
|
||||
if (slotName === "undefined") slotName = "Slot " + modType;
|
||||
|
||||
var menuItem = new UIMenuItem(slotName);
|
||||
var num = localVehicle.getNumMods(modType);
|
||||
if (num === undefined && modType !== 18 && modType !== 22) return;
|
||||
if (num !== 0 || modType === 18 || modType === 22) mainMenu.AddItem(menuItem);
|
||||
}
|
||||
});
|
||||
|
||||
mainMenu.Open();
|
||||
|
||||
mainMenu.ItemSelect.on((item) => {
|
||||
var modSlot = getSlotId(item.Text);
|
||||
if (item.Text.startsWith("Slot")) {
|
||||
restStr = item.Text.substring(5);
|
||||
modSlot = parseInt(restStr);
|
||||
}
|
||||
if (modSlot === undefined) return;
|
||||
|
||||
if (modSlot === 38) {
|
||||
localVehicle.setDoorOpen(5, false, false);
|
||||
} else if (modSlot === 39 || modSlot === 40 || modSlot === 41) {
|
||||
localVehicle.setDoorOpen(4, false, false);
|
||||
}
|
||||
|
||||
var door = getDoor(localVehicle.model, modSlot);
|
||||
if (door !== undefined) {
|
||||
localVehicle.setDoorOpen(door, false, false);
|
||||
}
|
||||
|
||||
var currentMod = localVehicle.getMod(modSlot);
|
||||
var oldToggleValue;
|
||||
if (modSlot === 18) {
|
||||
oldToggleValue = localVehicle.isToggleModOn(modSlot);
|
||||
currentMod = oldToggleValue ? 0 : -1;
|
||||
}
|
||||
|
||||
if (modSlot === 22) {
|
||||
localVehicle.setLights(2);
|
||||
var hlColor = localVehicle.getVariable("headlightColor");
|
||||
if (typeof hlColor !== "number" || isNaN(hlColor) || hlColor < 0 || hlColor === 255) {
|
||||
currentMod = -1;
|
||||
} else if (hlColor === 13) currentMod = 0;
|
||||
else currentMod = hlColor + 2;
|
||||
}
|
||||
|
||||
var currentModItem;
|
||||
|
||||
var modNum = localVehicle.getNumMods(modSlot);
|
||||
if (modSlot === 18) modNum = 1;
|
||||
if (modSlot === 22) modNum = 14;
|
||||
|
||||
modMenu = new Menu(item.Text, "Änderung: " + item.Text, new Point(50, 50));
|
||||
|
||||
for (var i = -1; i < modNum; i++) {
|
||||
var modItem;
|
||||
|
||||
if (i === -1) {
|
||||
modItem = new UIMenuItem("Serie", "");
|
||||
} else {
|
||||
var modName = getModName(localVehicle, modSlot, i);
|
||||
|
||||
modItem = new UIMenuItem(modName, "");
|
||||
}
|
||||
|
||||
if (i === currentMod - (modSlot === 22 ? 1 : 0)) {
|
||||
modItem.SetRightBadge(BadgeStyle.Car);
|
||||
currentModItem = modItem;
|
||||
}
|
||||
|
||||
modMenu.AddItem(modItem);
|
||||
}
|
||||
|
||||
modMenu.ItemSelect.on((selectedItem, index) => {
|
||||
if (currentModItem !== undefined) {
|
||||
currentModItem.SetRightBadge(BadgeStyle.None);
|
||||
}
|
||||
if (selectedItem !== undefined) {
|
||||
selectedItem.SetRightBadge(BadgeStyle.Car);
|
||||
currentModItem = selectedItem;
|
||||
}
|
||||
mp.events.callRemote("setVehicleMod", modSlot, index);
|
||||
|
||||
if (modSlot === 18) {
|
||||
oldToggleValue = index;
|
||||
return;
|
||||
}
|
||||
|
||||
if (modSlot === 22) {
|
||||
currentMod = index;
|
||||
return;
|
||||
}
|
||||
|
||||
if (index === 0) index = -1;
|
||||
currentMod = index - 1;
|
||||
});
|
||||
|
||||
modMenu.IndexChange.on((index) => {
|
||||
if (modSlot === 18) return;
|
||||
if (modSlot === 22) {
|
||||
setHeadlightsColor(localVehicle, index);
|
||||
return;
|
||||
}
|
||||
if (index === 0) index = -1;
|
||||
localVehicle.setMod(modSlot, index - 1);
|
||||
});
|
||||
|
||||
modMenu.MenuClose.on(() => {
|
||||
if (modSlot === 38) {
|
||||
localVehicle.setDoorShut(5, false);
|
||||
} else if (modSlot === 39 || modSlot === 40 || modSlot === 41) {
|
||||
localVehicle.setDoorShut(4, false);
|
||||
}
|
||||
|
||||
if (door !== undefined) {
|
||||
localVehicle.setDoorShut(door, false);
|
||||
}
|
||||
|
||||
if (closeMenu) {
|
||||
closeMenu = false;
|
||||
return;
|
||||
}
|
||||
|
||||
mainMenu.Visible = true;
|
||||
modMenu.Visible = false;
|
||||
|
||||
if (modSlot === 18) return;
|
||||
else if (modSlot === 22) {
|
||||
localVehicle.setLights(1);
|
||||
setHeadlightsColor(localVehicle, currentMod);
|
||||
return;
|
||||
}
|
||||
localVehicle.setMod(modSlot, currentMod);
|
||||
});
|
||||
|
||||
mainMenu.Visible = false;
|
||||
modMenu.Visible = true;
|
||||
});
|
||||
|
||||
mainMenu.MenuClose.on(() => {
|
||||
localVehicle.setLights(0);
|
||||
globalData.InTuning = false;
|
||||
mp.events.call("hideTuningInfo", false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
mp.events.add("playerLeaveVehicle", () => {
|
||||
if (keyBound) {
|
||||
mp.events.call("hideTuningInfo", true);
|
||||
}
|
||||
});
|
||||
|
||||
function getSlotName(slot) {
|
||||
var toReturn = "undefined";
|
||||
|
||||
carModSlotName.forEach((name) => {
|
||||
if (name.Slot === slot) toReturn = name.Name;
|
||||
});
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
function getSlotId(slotName) {
|
||||
var toReturn = "undefined";
|
||||
|
||||
carModSlotName.forEach((name) => {
|
||||
if (name.Name === slotName) toReturn = name.Slot;
|
||||
});
|
||||
|
||||
if (toReturn === "undefined") {
|
||||
|
||||
toReturn = getCustomId(mp.players.local.vehicle.model, slotName);
|
||||
|
||||
if (toReturn === undefined) {
|
||||
carModTypes.forEach((modType) => {
|
||||
if (mp.game.ui.getLabelText(mp.players.local.vehicle.getModSlotName(modType)) === slotName) toReturn = getSlotId(getSlotName(modType));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
function getCustomName(model, slot) {
|
||||
var toReturn = undefined;
|
||||
|
||||
customPartNames.forEach((cpn) => {
|
||||
if (cpn.Model === model) {
|
||||
cpn.Names.forEach((names) => {
|
||||
if (names.Slot === slot) toReturn = names.Name;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
function getCustomId(model, name) {
|
||||
var toReturn = undefined;
|
||||
|
||||
customPartNames.forEach((cpn) => {
|
||||
if (cpn.Model === model) {
|
||||
cpn.Names.forEach((names) => {
|
||||
if (names.Name === name) toReturn = names.Slot;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
function getDoor(model, slot) {
|
||||
var toReturn = undefined;
|
||||
|
||||
doorOpeners.forEach((cpn) => {
|
||||
if (cpn.Model === model) {
|
||||
cpn.Doors.forEach((door) => {
|
||||
if (door.Slot === slot) toReturn = door.Door;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
function getModName(vehicle, slot, mod) {
|
||||
var modName = vehicle.getModTextLabel(slot, mod);
|
||||
var realModName = mp.game.ui.getLabelText(modName);
|
||||
|
||||
if (slot === 11) {
|
||||
switch (mod) {
|
||||
case 0:
|
||||
realModName = "EMS Verbesserung 1";
|
||||
break;
|
||||
case 1:
|
||||
realModName = "EMS Verbesserung 2";
|
||||
break;
|
||||
case 2:
|
||||
realModName = "EMS Verbesserung 3";
|
||||
break;
|
||||
case 3:
|
||||
realModName = "EMS Verbesserung 4";
|
||||
break;
|
||||
}
|
||||
} else if (slot === 12) {
|
||||
switch (mod) {
|
||||
case 0:
|
||||
realModName = "Straßenbremsen";
|
||||
break;
|
||||
case 1:
|
||||
realModName = "Sportbremsen";
|
||||
break;
|
||||
case 2:
|
||||
realModName = "Rennbremsen";
|
||||
break;
|
||||
}
|
||||
} else if (slot === 13) {
|
||||
switch (mod) {
|
||||
case 0:
|
||||
realModName = "Straßengetriebe";
|
||||
break;
|
||||
case 1:
|
||||
realModName = "Sportgetriebe";
|
||||
break;
|
||||
case 2:
|
||||
realModName = "Renngetriebe";
|
||||
break;
|
||||
}
|
||||
} else if (slot === 15) {
|
||||
switch (mod) {
|
||||
case 0:
|
||||
realModName = "Tiefere Federung";
|
||||
break;
|
||||
case 1:
|
||||
realModName = "Straßenfederung";
|
||||
break;
|
||||
case 2:
|
||||
realModName = "Sportfederung";
|
||||
break;
|
||||
case 3:
|
||||
realModName = "Rennfederung";
|
||||
break;
|
||||
case 4:
|
||||
realModName = "Wettkampffederung";
|
||||
break;
|
||||
}
|
||||
} else if (slot === 18) {
|
||||
realModName = "Turbotuning";
|
||||
} else if (slot === 22) {
|
||||
switch (mod) {
|
||||
case 0:
|
||||
realModName = "Xenon Licht";
|
||||
break;
|
||||
case 1:
|
||||
realModName = "Weißes Licht";
|
||||
break;
|
||||
case 2:
|
||||
realModName = "Blaues Licht";
|
||||
break;
|
||||
case 3:
|
||||
realModName = "Hell-blaues Licht";
|
||||
break;
|
||||
case 4:
|
||||
realModName = "Grünes Licht";
|
||||
break;
|
||||
case 5:
|
||||
realModName = "Hell-grünes Licht";
|
||||
break;
|
||||
case 6:
|
||||
realModName = "Hell-gelbes Licht";
|
||||
break;
|
||||
case 7:
|
||||
realModName = "Gelbes Licht";
|
||||
break;
|
||||
case 8:
|
||||
realModName = "Orangenes Licht";
|
||||
break;
|
||||
case 9:
|
||||
realModName = "Rotes Licht";
|
||||
break;
|
||||
case 10:
|
||||
realModName = "Hell-pinkes Licht";
|
||||
break;
|
||||
case 11:
|
||||
realModName = "Pinkes Licht";
|
||||
break;
|
||||
case 12:
|
||||
realModName = "Lila Licht";
|
||||
break;
|
||||
case 13:
|
||||
realModName = "Hell-lila Licht";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return realModName;
|
||||
}
|
||||
|
||||
function setHeadlightsColor(vehicle, index) {
|
||||
var color = index - 2;
|
||||
if (index === 0) color = -1;
|
||||
if (index === 1) color = 13;
|
||||
if (typeof color !== "number" || isNaN(color) || color < 0 || color === 255) {
|
||||
// Disable
|
||||
vehicle.toggleMod(22, false);
|
||||
mp.game.invoke("0xE41033B25D003A07", vehicle.handle, 255);
|
||||
} else {
|
||||
// Enable
|
||||
vehicle.toggleMod(22, true);
|
||||
mp.game.invoke("0xE41033B25D003A07", vehicle.handle, color);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user