236 lines
9.4 KiB
TypeScript
236 lines
9.4 KiB
TypeScript
/// <reference path="../types-gt-mp/index.d.ts" />
|
|
function getLocalPlayer(){
|
|
return API.getLocalPlayer();
|
|
}
|
|
|
|
function getEntityData(ent, data){
|
|
if (API.hasEntitySyncedData(ent, data))
|
|
return API.getEntitySyncedData(ent, data);
|
|
else
|
|
return false;
|
|
}
|
|
|
|
API.onKeyDown.connect(function (sender, key) {
|
|
if (key.KeyCode === Keys.X) {
|
|
if (API.getEntitySyncedData(API.getLocalPlayer(), "loggedin") == true) {
|
|
// if (!getEntityData(getLocalPlayer(), "spawned")) return;
|
|
API.showCursor(!API.isCursorShown());
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
function getClickedEntity(cursorPos, sensitivity = 0.1) {
|
|
var clickedEntity = null;
|
|
var cursorCoords = API.screenToWorld(cursorPos);
|
|
var vecLineXStart = new Vector3(cursorCoords.X+sensitivity, cursorCoords.Y, cursorCoords.Z);
|
|
var vecLineXEnd = new Vector3(cursorCoords.X-sensitivity, cursorCoords.Y, cursorCoords.Z);
|
|
var vecLineYStart = new Vector3(cursorCoords.X, cursorCoords.Y+sensitivity, cursorCoords.Z);
|
|
var vecLineYEnd = new Vector3(cursorCoords.X, cursorCoords.Y-sensitivity, cursorCoords.Z);
|
|
var vecLineZStart = new Vector3(cursorCoords.X, cursorCoords.Y, cursorCoords.Z+sensitivity);
|
|
var vecLineZEnd = new Vector3(cursorCoords.X, cursorCoords.Y, cursorCoords.Z-sensitivity);
|
|
var vecLineXYZStart = new Vector3(cursorCoords.X+sensitivity, cursorCoords.Y+sensitivity, cursorCoords.Z+sensitivity);
|
|
var vecLineXYZEnd = new Vector3(cursorCoords.X-sensitivity, cursorCoords.Y-sensitivity, cursorCoords.Z-sensitivity);
|
|
var vecLineXYStart = new Vector3(cursorCoords.X+sensitivity, cursorCoords.Y+sensitivity, cursorCoords.Z-sensitivity);
|
|
var vecLineXYEnd = new Vector3(cursorCoords.X-sensitivity, cursorCoords.Y-sensitivity, cursorCoords.Z+sensitivity);
|
|
var vecLineYZStart = new Vector3(cursorCoords.X-sensitivity, cursorCoords.Y+sensitivity, cursorCoords.Z+sensitivity);
|
|
var vecLineYZEnd = new Vector3(cursorCoords.X+sensitivity, cursorCoords.Y-sensitivity, cursorCoords.Z-sensitivity);
|
|
var vecLineXZStart = new Vector3(cursorCoords.X+sensitivity, cursorCoords.Y-sensitivity, cursorCoords.Z+sensitivity);
|
|
var vecLineXZEnd = new Vector3(cursorCoords.X-sensitivity, cursorCoords.Y+sensitivity, cursorCoords.Z-sensitivity);
|
|
[
|
|
API.createRaycast(vecLineXStart, vecLineXEnd, -1, null),
|
|
API.createRaycast(vecLineYStart, vecLineYEnd, -1, null),
|
|
API.createRaycast(vecLineZStart, vecLineZEnd, -1, null),
|
|
API.createRaycast(vecLineXYZStart, vecLineXYZEnd, -1, null),
|
|
API.createRaycast(vecLineXYStart, vecLineXYEnd, -1, null),
|
|
API.createRaycast(vecLineYZStart, vecLineYZEnd, -1, null),
|
|
API.createRaycast(vecLineXZStart, vecLineXZEnd, -1, null)
|
|
].every(function(ray, index) {
|
|
if(ray.didHitEntity) {
|
|
clickedEntity = ray.hitEntity;
|
|
return false;
|
|
}
|
|
return true;
|
|
});
|
|
return clickedEntity;
|
|
}
|
|
|
|
API.onEntityStreamIn.connect(function (entity, entityType) {
|
|
if (entityType == 1) {
|
|
if (API.getEntitySyncedData(entity, "locked") == true) {
|
|
API.callNative("0xB664292EAECF7FA6", entity, 2);
|
|
// DOORS CLOSED
|
|
} else {
|
|
API.callNative("0xB664292EAECF7FA6", entity, 1);
|
|
// DOORS OPEN
|
|
}
|
|
}
|
|
});
|
|
|
|
API.onUpdate.connect(function () {
|
|
API.drawMenu(menu);
|
|
API.drawMenu(tuerenmenu);
|
|
if (API.isCursorShown()) {
|
|
if (API.isControlJustPressed(25)) {
|
|
var cursorPos = API.getCursorPosition();
|
|
onClientClick("right", getClickedEntity(cursorPos));
|
|
} else if (API.isControlJustPressed(24)) {
|
|
var cursorPos = API.getCursorPosition();
|
|
onClientClick("left", getClickedEntity(cursorPos));
|
|
}
|
|
}
|
|
});
|
|
|
|
var menu = API.createMenu("Fahrzeug Menu", "Optionen", 0, 0, 6);
|
|
menu.AddItem(API.createMenuItem("Auf/Abschliessen", "Schliesst das Fahrzeug auf/ab."));
|
|
menu.AddItem(API.createMenuItem("Fahrzeug Parken", "Parkt das Auto an der aktuellen Position."));
|
|
menu.AddItem(API.createMenuItem("Fahrzeug Respawnen", "Respawnt das Auto an der letzten Parkposition."));
|
|
menu.AddItem(API.createMenuItem("Tueren Oeffnen", "Hiermit kannst du Tueren Oeffnen."));
|
|
menu.AddItem(API.createMenuItem("Schliessen", "Menu Schliessen."));
|
|
var entity = null;
|
|
|
|
var kaufmenu = API.createMenu("Fahrzeug Kaufen", "Optionen", 0, 0, 6);
|
|
|
|
|
|
function showCarMenu(ent) {
|
|
var name = API.getPlayerName(API.getLocalPlayer());
|
|
var owner = API.getEntitySyncedData(ent, "besitzer");
|
|
if (name == owner) {
|
|
menu.Visible = true;
|
|
entity = ent;
|
|
} else if (owner == "System") {
|
|
API.sendNotification("~r~ Error: Das Fahrzeug hat keinen Besitzer!");
|
|
} else if (owner == "kauf") {
|
|
API.triggerServerEvent("triggerKaufBack", ent);
|
|
} else {
|
|
API.sendNotification("~r~Dieses Fahrzeug gehört: " + owner + ".");
|
|
}
|
|
}
|
|
|
|
function showCarMenu2(ent) {
|
|
var name = API.getPlayerName(API.getLocalPlayer());
|
|
var owner = API.getEntitySyncedData(ent, "besitzer");
|
|
API.triggerServerEvent("vehiclelock", ent);
|
|
}
|
|
|
|
|
|
API.onKeyDown.connect(function (sender, e) {
|
|
if (e.KeyCode === Keys.L) {
|
|
if (API.getEntitySyncedData(API.getLocalPlayer(), "loggedin") == true) {
|
|
//API.triggerServerEvent("vehiclelock");
|
|
}
|
|
}
|
|
});
|
|
|
|
function playerinteraction(ent) {
|
|
API.triggerServerEvent("playerinteraction",ent);
|
|
}
|
|
|
|
function playerinteraction2(ent) {
|
|
API.triggerServerEvent("playerinteraction2",ent);
|
|
}
|
|
|
|
var controlsdisabled = false;
|
|
|
|
API.onUpdate.connect(function () {
|
|
if (controlsdisabled == true) {
|
|
API.disableAllControlsThisFrame();
|
|
}
|
|
});
|
|
|
|
API.onServerEventTrigger.connect(function (eventName, args) {
|
|
if (eventName == "fesseln") {
|
|
controlsdisabled = true;
|
|
|
|
} else if (eventName == "unfesseln") {
|
|
controlsdisabled = false;
|
|
for (var i = 0; i < 45; i++) {
|
|
API.enableControlThisFrame(i);
|
|
}
|
|
}
|
|
});
|
|
|
|
var tuerenmenu = API.createMenu("Fahrzeug Turen", "Tueren:", 0, 0, 6);
|
|
tuerenmenu.AddItem(API.createMenuItem("Zurueck", "Kehre zum Fahrzeugmenu zurueck!"));
|
|
tuerenmenu.AddItem(API.createMenuItem("Fahrer Vordertuer", ""));
|
|
tuerenmenu.AddItem(API.createMenuItem("Beifahrer Vordertuer", ""));
|
|
tuerenmenu.AddItem(API.createMenuItem("Fahrer Hintertuer", ""));
|
|
tuerenmenu.AddItem(API.createMenuItem("Beifahrer Hintertuer", ""));
|
|
tuerenmenu.AddItem(API.createMenuItem("Motorhaube", ""));
|
|
tuerenmenu.AddItem(API.createMenuItem("Kofferraum", ""));
|
|
tuerenmenu.AddItem(API.createMenuItem("Spezial", ""));
|
|
|
|
menu.OnItemSelect.connect(function(sender, item, index){
|
|
if (item.Text == "Schliessen") {
|
|
menu.Visible = false;
|
|
API.showCursor(false);
|
|
entity = null;
|
|
} else if (item.Text == "Auf/Abschliessen") {
|
|
API.triggerServerEvent("aufabschliessen", entity)
|
|
menu.Visible = false;
|
|
API.showCursor(false);
|
|
entity = null;
|
|
} else if (item.Text == "Fahrzeug Parken") {
|
|
API.triggerServerEvent("parken", entity)
|
|
menu.Visible = false;
|
|
API.showCursor(false);
|
|
entity = null;
|
|
} else if (item.Text == "Fahrzeug Respawnen") {
|
|
API.triggerServerEvent("respawnen", entity)
|
|
menu.Visible = false;
|
|
API.showCursor(false);
|
|
entity = null;
|
|
} else if (item.Text == "Tueren Oeffnen") {
|
|
menu.Visible = false;
|
|
tuerenmenu.Visible = true;
|
|
}
|
|
});
|
|
|
|
tuerenmenu.OnItemSelect.connect(function (sender, item, index) {
|
|
if (item.Text == "Zurueck") {
|
|
menu.Visible = true;
|
|
tuerenmenu.Visible = false;
|
|
} else if(index == 1){
|
|
API.triggerServerEvent("openDoor", entity, 0);
|
|
} else if (index == 2) {
|
|
API.triggerServerEvent("openDoor", entity, 1);
|
|
} else if (index == 3) {
|
|
API.triggerServerEvent("openDoor", entity, 2);
|
|
} else if (index == 4) {
|
|
API.triggerServerEvent("openDoor", entity, 3);
|
|
} else if (index == 5) {
|
|
API.triggerServerEvent("openDoor", entity, 4);
|
|
} else if (index == 6) {
|
|
API.triggerServerEvent("openDoor", entity, 5);
|
|
} else if (index == 7) {
|
|
API.triggerServerEvent("openDoor", entity, 6);
|
|
}
|
|
|
|
});
|
|
|
|
function onClientClick(btn, ent){
|
|
if (btn == "right") {
|
|
if (ent && API.doesEntityExist(ent)){
|
|
var entType = API.getEntityType(ent);
|
|
if (entType == 1) {
|
|
showCarMenu2(ent);
|
|
} else if (entType == 6) {
|
|
playerinteraction2(ent);
|
|
}
|
|
//API.sendNotification("Entitytype:" + entType);
|
|
}
|
|
} else if (btn == "left") {
|
|
if (ent && API.doesEntityExist(ent)){
|
|
var entType = API.getEntityType(ent);
|
|
if (entType == 1) {
|
|
showCarMenu(ent);
|
|
} else if (entType == 6) {
|
|
playerinteraction(ent);
|
|
API.showCursor(false);
|
|
}
|
|
//API.sendNotification("Entitytype:" + entType);
|
|
}
|
|
}
|
|
}
|
|
|