Added tuning support for colored lights

This commit is contained in:
hydrant
2018-12-15 14:00:01 +01:00
parent 7a5f820068
commit 2818fd3513
5 changed files with 139 additions and 26 deletions

View File

@@ -6,7 +6,7 @@
var keyBound = false;
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];
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" },
@@ -46,6 +46,10 @@ var customPartNames = [
{
Slot: 8,
Name: "Lüftungsschlitze"
},
{
Slot: 43,
Name: "Motorhaubenstifte"
}
]
},
@@ -194,8 +198,9 @@ mp.events.add("showTuningMenu", () => {
if (slotName === "undefined") slotName = "Slot " + modType;
var menuItem = new UIMenuItem(slotName);
if(localVehicle.getNumMods(modType) !== 0 || modType === 18 || modType === 22) mainMenu.AddItem(menuItem);
var num = localVehicle.getNumMods(modType);
if (num === undefined && modType !== 18 && modType !== 22) return;
if (num !== 0 || modType === 18 || modType === 22) mainMenu.AddItem(menuItem);
}
});
@@ -207,6 +212,7 @@ mp.events.add("showTuningMenu", () => {
restStr = item.Text.substring(5);
modSlot = parseInt(restStr);
}
if (modSlot === undefined) return;
if (modSlot === 38) {
localVehicle.setDoorOpen(5, false, false);
@@ -219,15 +225,24 @@ mp.events.add("showTuningMenu", () => {
var currentMod = localVehicle.getMod(modSlot);
var oldToggleValue;
if (modSlot === 18 || modSlot === 22) {
if (modSlot === 18) {
oldToggleValue = localVehicle.isToggleModOn(modSlot);
mp.gui.chat.push("oldToggleValue = " + oldToggleValue.toString());
currentMod = oldToggleValue ? 0 : -1;
}
if (modSlot === 22) {
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 || modSlot === 22) modNum = 1;
if (modSlot === 18) modNum = 1;
if (modSlot === 22) modNum = 14;
modMenu = new Menu(item.Text, "Änderung: " + item.Text, new Point(50, 50));
@@ -239,16 +254,12 @@ mp.events.add("showTuningMenu", () => {
} else {
var modName = getModName(localVehicle, modSlot, i);
if (modSlot === 18) modName = "Turbolader";
if (modSlot === 22) modName = "Xenon-Licht";
modItem = new UIMenuItem(modName, "");
}
if (i === currentMod) {
if (i === currentMod - (modSlot === 22 ? 1 : 0)) {
modItem.SetRightBadge(BadgeStyle.Car);
currentModItem = modItem;
modFound = true;
}
modMenu.AddItem(modItem);
@@ -264,18 +275,24 @@ mp.events.add("showTuningMenu", () => {
}
mp.events.callRemote("setVehicleMod", modSlot, index);
if (modSlot === 18 || modSlot === 22) {
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 || modSlot === 22) {
localVehicle.toggleMod(modSlot, index === 0 ? false : true);
if (modSlot === 18) return;
if (modSlot === 22) {
setHeadlightsColor(localVehicle, index);
return;
}
if (index === 0) index = -1;
@@ -299,8 +316,9 @@ mp.events.add("showTuningMenu", () => {
mainMenu.Visible = true;
modMenu.Visible = false;
if (modSlot === 18 || modSlot === 22) {
localVehicle.toggleMod(modSlot, !!oldToggleValue);
if (modSlot === 18) return;
else if (modSlot === 22) {
setHeadlightsColor(localVehicle, currentMod);
return;
}
localVehicle.setMod(modSlot, currentMod);
@@ -457,7 +475,69 @@ function getModName(vehicle, slot, mod) {
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);
}
}