403 lines
15 KiB
C#
403 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using GrandTheftMultiplayer.Server;
|
|
using GrandTheftMultiplayer.Shared;
|
|
using GrandTheftMultiplayer.Server.API;
|
|
using GrandTheftMultiplayer.Shared.Math;
|
|
using GrandTheftMultiplayer.Server.Elements;
|
|
using GrandTheftMultiplayer.Server.Constant;
|
|
using GrandTheftMultiplayer.Server.Managers;
|
|
|
|
namespace Roleplay.Tuning
|
|
{
|
|
public class LosSantosCustoms : Script
|
|
{
|
|
|
|
public const int LSC_ROOT = 126;
|
|
public const int LSC_CHILD = 127;
|
|
|
|
public const int SPOILER = 0;
|
|
public const int FRONTBUMPER = 1;
|
|
public const int REARBUMPER = 2;
|
|
public const int SKIRT = 3;
|
|
public const int EXHAUST = 4;
|
|
public const int ROLLCAGE = 5;
|
|
public const int GRILLE = 6;
|
|
public const int HOOD = 7;
|
|
public const int FENDER = 8;
|
|
public const int RFENDER = 9;
|
|
public const int ROOF = 10;
|
|
public const int ENGINE = 11;
|
|
public const int BRAKES = 12;
|
|
public const int TRANSMISSION = 13;
|
|
public const int HORNS = 14;
|
|
public const int SUSPENSION = 15;
|
|
public const int ARMOR = 16;
|
|
public const int FWHEEL = 23;
|
|
public const int BWHEEL = 24;
|
|
|
|
|
|
private static readonly Dictionary<int, string> Mods = new Dictionary<int, string>()
|
|
{
|
|
{0, "Spoiler"},
|
|
{1, "Frontstoßstange"},
|
|
{2, "Hintere Stoßstange"},
|
|
{3, "Skirts"},
|
|
{4, "Auspuff"},
|
|
{5, "Ueberrollkaefig"},
|
|
{6, "Vergitterung"},
|
|
{7, "Motorhaube"},
|
|
{8, "Kotfluegel"},
|
|
{9, "Kotfluegel hinten"},
|
|
{10, "Dach"},
|
|
{11, "Motor"},
|
|
{12, "Bremsen"},
|
|
{13, "Getriebe"},
|
|
{14, "Hupen"},
|
|
{15, "Federung"},
|
|
{16, "Panzerung"},
|
|
{18, "Turbo" },
|
|
{22, "Xenon Lichter" },
|
|
{23, "Raeder"},
|
|
{24, "Hinter Raeder"},
|
|
{25, "Plattenhalter"},
|
|
{27, "Trim Design" },
|
|
{28, "Verzierung" },
|
|
{30, "Dials" },
|
|
{33, "Lenkrad" },
|
|
{34, "Gangschaltung" },
|
|
{35, "Plakette" },
|
|
{38, "Hydraulik" },
|
|
{48, "Aussehen" },
|
|
{62, "Schild" },
|
|
{66, "Farbe 1" },
|
|
{67, "Farbe 2" },
|
|
{69, "Fenstertoenung" },
|
|
};
|
|
|
|
private static readonly string[] Horns = new string[62]
|
|
{
|
|
"Truck",
|
|
"Cop",
|
|
"Clown",
|
|
"Musical 1",
|
|
"Musical 2",
|
|
"Musical 3",
|
|
"Musical 4",
|
|
"Musical 5",
|
|
"Sad Horn",
|
|
"Classical 1",
|
|
"Classical 2",
|
|
"Classical 3",
|
|
"Classical 4",
|
|
"Classical 5",
|
|
"Classical 6",
|
|
"Classical 7",
|
|
"Do",
|
|
"Re",
|
|
"Mi",
|
|
"Fa",
|
|
"Sol",
|
|
"La",
|
|
"Si",
|
|
"Do (High)",
|
|
"Jazz 1",
|
|
"Jazz 2",
|
|
"Jazz 3",
|
|
"Jazz Loop",
|
|
"Star Spangled Banner 1",
|
|
"Star Spangled Banner 2",
|
|
"Star Spangled Banner 3",
|
|
"Star Spangled Banner 4",
|
|
"Classical Horn Loop 1",
|
|
"Classical Horn Loop 2",
|
|
"Classical Horn Loop 3",
|
|
"Classical Horn 8",
|
|
"Classical Horn 9",
|
|
"Classical Horn 10",
|
|
"Funeral (Loop)",
|
|
"Funeral",
|
|
"Spooky (Loop)",
|
|
"Spooky",
|
|
"San Andreas (Loop)",
|
|
"San Andreas",
|
|
"Libery City (Loop)",
|
|
"Libery City",
|
|
"Christmas 1 (Loop)",
|
|
"Christmas 1",
|
|
"Christmas 2 (Loop)",
|
|
"Christmas 2",
|
|
"Christmas 3 (Loop)",
|
|
"Christmas 3",
|
|
"Unknown",
|
|
"Unknown",
|
|
"Unknown",
|
|
"Unknown",
|
|
"Unknown",
|
|
"Unknown",
|
|
"Unknown",
|
|
"Unknown",
|
|
"Unknown",
|
|
"Unknown"
|
|
};
|
|
|
|
private static readonly string[] Engines = new string[5]
|
|
{
|
|
"EMS Verbesserung, Level 1",
|
|
"EMS Verbesserung, Level 2",
|
|
"EMS Verbesserung, Level 3",
|
|
"EMS Verbesserung, Level 4",
|
|
"EMS Verbesserung, Level 5"
|
|
};
|
|
private static readonly string[] Brakes = new string[3]
|
|
{
|
|
"Strassen Bremsen",
|
|
"Sport Bremsen",
|
|
"Renn Bremsen"
|
|
};
|
|
private static readonly string[] Transmissions = new string[4]
|
|
{
|
|
"Strassen Uebertragung",
|
|
"Sport Uebertragung",
|
|
"Renn Uebertragung",
|
|
"Monster Uebertragung"
|
|
};
|
|
private static readonly string[] Suspensions = new string[4]
|
|
{
|
|
"Gesenkte Federung",
|
|
"Strassen Federung",
|
|
"Sport Federung",
|
|
"Wettbewerb Federung"
|
|
};
|
|
|
|
public LosSantosCustoms()
|
|
{
|
|
API.onClientEventTrigger += ClientEvent;
|
|
API.onEntityEnterColShape += EnterColshape;
|
|
Roleplay.RAPI.Marker.createMarker(21, new Vector3(-359, -134, 39), 2, 255, 0, 0, "LSC", 0, 80, "Tuning Shop",70);
|
|
Blip blip = API.createBlip(new Vector3(-338.24, -136.36, 38));
|
|
API.setBlipSprite(blip, 446);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void EnterColshape(ColShape colshape, NetHandle entity)
|
|
{
|
|
|
|
if (colshape.hasData("LSC"))
|
|
{
|
|
|
|
var player = API.getPlayerFromHandle(entity);
|
|
if (player == null) return;
|
|
if (!player.isInVehicle) return;
|
|
if (player.vehicleSeat != -1) return;
|
|
if (API.getEntityData(player.vehicle, "besitzer") != player.name) return;
|
|
else
|
|
{
|
|
|
|
API.sendNativeToPlayer(player, Hash.DO_SCREEN_FADE_OUT, 200);
|
|
if (API.getEntityData(entity, "Task") != true)
|
|
{
|
|
Task t = Task.Run(() => getVehicleModSlots(player, player.vehicle));
|
|
API.setEntityData(entity, "Task", true);
|
|
API.delay(10000*3, true, () =>
|
|
{
|
|
|
|
if (t.IsCompleted)
|
|
{
|
|
API.sendNativeToPlayer(player, Hash.DO_SCREEN_FADE_IN, 200);
|
|
//API.triggerClientEvent(player, "activate_camera", new Vector3(-335.06, -134.72, 39.67));
|
|
player.vehicle.position = new Vector3(-338.24, -136.36, 38.66);
|
|
player.vehicle.rotation = new Vector3(0, 0, -108);
|
|
player.vehicle.freezePosition = true;
|
|
player.dimension = API.getEntityData(player, "ID");
|
|
player.vehicle.dimension = API.getEntityData(player, "ID");
|
|
//Cams.interpolateCamera(player, 1, 1000, true, true);
|
|
menuRoot(player, player.vehicle);
|
|
API.sendNotificationToPlayer(player, "~g~TIPP: Du kannst die Maus zum umhersehen benutzen!", true);
|
|
API.setEntityData(entity, "Task", false);
|
|
} else
|
|
{
|
|
API.sendNativeToPlayer(player, Hash.DO_SCREEN_FADE_IN, 200);
|
|
API.sendChatMessageToPlayer(player,"Server konnte die liste der Modifikationen nicht erhalten! Bitte versuche es nochmal und melde dies einem Administrator!");
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void leaveLSC(Client player)
|
|
{
|
|
// API.sendNativeToPlayer(player, Hash.DO_SCREEN_FADE_OUT, 1);
|
|
// API.sendNativeToPlayer(player, Hash.DO_SCREEN_FADE_IN, 1000);
|
|
// API.triggerClientEvent(player, "kill_camera", new Vector3(-335.06, -134.72, 39.67));
|
|
player.vehicle.freezePosition = false;
|
|
player.dimension = 0;
|
|
player.vehicle.dimension = 0;
|
|
player.vehicle.position = new Vector3(-369.6,-113.65,38);
|
|
player.vehicle.rotation = new Vector3(0, 0, 70);
|
|
API.triggerClientEvent(player,"menu_handler_close_menu");
|
|
}
|
|
|
|
private void ClientEvent(Client sender, string eventName, object[] args)
|
|
{
|
|
if (eventName == "menu_handler_select_item")
|
|
{
|
|
var callbackId = (int)args[0];
|
|
var index = (int)args[1];
|
|
if (callbackId == LSC_ROOT)
|
|
{
|
|
if (index == 0) {
|
|
leaveLSC(sender);
|
|
Roleplay.Vehiclesystem.VehicleMain.remapTunings(sender, sender.vehicle, API);
|
|
return;
|
|
}
|
|
|
|
List<int> slots = sender.vehicle.getData("Slots");
|
|
var slot = slots[index - 1];
|
|
menuChild(sender, slot);
|
|
API.setEntityData(sender.vehicle, "OldTuning" + slot, API.getVehicleMod(sender.vehicle,slot));
|
|
sender.vehicle.setData("SelectedSlot", slot);
|
|
}
|
|
else if (callbackId == LSC_CHILD)
|
|
{
|
|
var slot = sender.vehicle.getData("SelectedSlot");
|
|
if (index == 0) {
|
|
menuRoot(sender, sender.vehicle);
|
|
API.setVehicleMod(sender.vehicle, slot, API.getEntityData(sender.vehicle,"OldTuning" + slot));
|
|
return;
|
|
}
|
|
if (index == 1) {
|
|
// DATENBANK & GELD ABZUG WIE GELD ABFRAGE!!!
|
|
int tuningpreis = 0;
|
|
int lastitem = API.getEntityData(sender.vehicle, "lastitem");
|
|
if(lastitem > 0){
|
|
tuningpreis = lastitem * 250;
|
|
}
|
|
|
|
|
|
if (Roleplay.Environment.MONEY.Money.hasBarMoney(sender, tuningpreis))
|
|
{
|
|
|
|
API.setEntityData(sender.vehicle, "OldTuning" + slot, lastitem);
|
|
Roleplay.Vehiclesystem.VehicleMain.setDatabaseTuning(sender, sender.vehicle, slot, lastitem);
|
|
Roleplay.Environment.MONEY.Money.giveBarMoney(sender, -tuningpreis, API);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
API.sendNotificationToPlayer(sender, "Du hast nicht genug Bargeld dabei!");
|
|
}
|
|
|
|
return;
|
|
}
|
|
else if(index == 2)
|
|
{
|
|
API.setVehicleMod(sender.vehicle, slot, -1);
|
|
API.setEntityData(sender.vehicle, "lastitem", -1);
|
|
}
|
|
else
|
|
{
|
|
API.setVehicleMod(sender.vehicle, slot, index - 3);
|
|
API.setEntityData(sender.vehicle, "lastitem", index - 3);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public int getNumVehicleMods(Client player, NetHandle vehicle, int slot)
|
|
{
|
|
int x = API.shared.fetchNativeFromPlayer<int>(player, 0xE38E9162A2500646, vehicle, slot);
|
|
return x;
|
|
}
|
|
|
|
public void getVehicleModSlots(Client player, NetHandle vehicle)
|
|
{
|
|
List<int> availableslots = new List<int>();
|
|
for (var i = 0; i < 62; i++)
|
|
{
|
|
int s = API.fetchNativeFromPlayer<int>(player, 0xE38E9162A2500646, vehicle, i); // ANZAHL DER MOD MÖGLICHKEITEN FÜR MOD INDEX i
|
|
if (s > 0 )
|
|
{
|
|
if (!(i == 21 || i == 17 || i == 19 || i == 20 || i == 26 || i == 29 || i == 31 || i == 32 || i == 36 || i == 37 || i == 39 || i == 40 || i == 41 || i == 42 || i == 43 || i == 44 || i == 45 || i == 46 || i == 47 || i == 49 || i == 50 || i == 51 || i == 52 || i == 53 || i == 54 || i == 55 || i == 56 || i == 57 || i == 58 || i == 59 || i == 60 || i == 61 || i == 63 || i == 64 || i == 65 || i == 68 || i == 70))
|
|
{
|
|
API.setEntityData(vehicle, "Slot" + i, getNumVehicleMods(player, vehicle, i));
|
|
availableslots.Add(i);
|
|
}
|
|
}
|
|
}
|
|
API.setEntityData(vehicle, "Slots", availableslots);
|
|
return;
|
|
}
|
|
|
|
|
|
public void menuChild(Client player, int slot)
|
|
{
|
|
var availablemods = API.getEntityData(player.vehicle, "Slot" + slot);
|
|
object[] argslist = new object[30 + availablemods * 2];
|
|
argslist[0] = LSC_CHILD;
|
|
argslist[1] = Mods[slot];
|
|
argslist[2] = "Tuning";
|
|
argslist[3] = true;
|
|
argslist[4] = availablemods + 3;
|
|
argslist[5] = "~r~Zurueck";
|
|
argslist[6] = "~g~Kaufen";
|
|
argslist[7] = "~r~Ausbauen";
|
|
for (var i = 0; i < availablemods; i++)
|
|
{
|
|
var x = "Tuning: ";
|
|
switch (slot)
|
|
{
|
|
default:
|
|
x = "Tuning: " + i;
|
|
break;
|
|
case ENGINE:
|
|
x = Engines[i];
|
|
break;
|
|
case BRAKES:
|
|
x = Brakes[i];
|
|
break;
|
|
case TRANSMISSION:
|
|
x = Transmissions[i];
|
|
break;
|
|
case SUSPENSION:
|
|
x = Suspensions[i];
|
|
break;
|
|
case HORNS:
|
|
x = Horns[i];
|
|
break;
|
|
}
|
|
|
|
argslist[8 + i] = x;
|
|
}
|
|
API.triggerClientEvent(player, "menu_handler_create_menu3", argslist);
|
|
}
|
|
|
|
public void menuRoot(Client player, NetHandle vehicle)
|
|
{
|
|
List<int> slots = API.getEntityData(vehicle, "Slots");
|
|
//if (slots == null) return;
|
|
object[] argslist = new object[7 + slots.Count * 2];
|
|
argslist[0] = LSC_ROOT;
|
|
argslist[1] = "Tuning Shop";
|
|
argslist[2] = "Optionen:";
|
|
argslist[3] = true;
|
|
argslist[4] = slots.Count + 1;
|
|
argslist[5] = "~r~Verlassen";
|
|
var i = 0;
|
|
foreach (var s in slots)
|
|
{
|
|
string x = "Unbekannt";
|
|
Mods.TryGetValue(s, out x);
|
|
argslist[6 + i] = x;
|
|
//argslist[6+ slots.Count + i] = "->";
|
|
i++;
|
|
}
|
|
API.triggerClientEvent(player, "menu_handler_create_menu", argslist);
|
|
}
|
|
}
|
|
}
|