Ragemp-roleplay-skript/RAPI/Menu.js
2019-04-16 13:59:07 +02:00

143 lines
3.9 KiB
JavaScript

var menu = null;
var text = null;
var control = true;
API.onUpdate.connect(function () {
if (control == false) {
API.disableControlThisFrame(37);
API.disableControlThisFrame(81);
API.disableControlThisFrame(82);
API.disableControlThisFrame(83);
API.disableControlThisFrame(84);
API.disableControlThisFrame(100);
API.disableControlThisFrame(99);
API.disableControlThisFrame(6);
// API.disableControlThisFrame(1);
}
});
API.onServerEventTrigger.connect(function (name, args) {
if (name == "menu_handler_create_menu") {
if (menu != null) {
menu.Visible = false;
menu = null;
}
var callbackId = args[0];
var banner = args[1];
var subtitle = args[2];
var noExit = args[3];
if (banner == null){
menu = API.createMenu(subtitle, 0, 0, 6);
menu.Visible = true;
}else{
menu = API.createMenu(banner, subtitle, 0, 0, 6);
menu.Visible = true;
}
if (noExit) {
menu.ResetKey(menuControl.Back);
control = true;
}
var itemsLen = args[4];
for (var i = 0; i < itemsLen; i++) {
var item = API.createMenuItem(args[5 + i], "");
item.SetRightLabel(args[5 + i + itemsLen]);
menu.AddItem(item);
}
menu.OnItemSelect.connect(function (sender, item, index) {
API.triggerServerEvent("menu_handler_select_item", callbackId, index, item.Text);
menu.Visible = false;
control = true;
});
} else if (name == "menu_handler_create_menu3") {
if (menu != null) {
menu.Visible = false;
menu = null;
}
var callbackId = args[0];
var banner = args[1];
var subtitle = args[2];
var noExit = args[3];
control = false;
if (banner == null)
menu = API.createMenu(subtitle, 0, 0, 6);
else menu = API.createMenu(banner, subtitle, 0, 0, 6);
if (noExit) {
menu.ResetKey(menuControl.Back);
}
var itemsLen = args[4];
for (var i = 0; i < itemsLen; i++) {
var item = API.createMenuItem(args[5 + i], "");
item.SetRightLabel(args[5 + i + itemsLen]);
menu.AddItem(item);
}
menu.OnItemSelect.connect(function (sender, item, index) {
API.triggerServerEvent("menu_handler_select_item", callbackId, index, item.Text);
control = true;
});
menu.Visible = true;
}
else if (name == "menu_handler_create_menu2") {
if (menu != null) {
menu.Visible = false;
menu = null;
}
var callbackId = args[0];
var banner = args[1];
var subtitle = args[2];
var noExit = args[3];
if (banner == null)
menu = API.createMenu(subtitle, 0, 0, 6);
else menu = API.createMenu(banner, subtitle, 0, 0, 6);
if (noExit) {
menu.ResetKey(menuControl.Back);
}
var itemsLen = args[4];
for (var i = 0; i < itemsLen; i++) {
var item = API.createMenuItem(args[5 + i], "");
item.SetRightLabel(args[5 + i + itemsLen]);
menu.AddItem(item);
}
menu2.OnItemSelect.connect(function (sender, item, index) {
API.triggerServerEvent("menu_handler_select_item", callbackId, index);
});
menu.Visible = true;
}
else if (name === "menu_handler_close_menu") {
menu.Visible = false;
menu = null;
}
else if (name == "get_user_input") {
text = API.getUserInput(args[1], args[2]);
if (args[3] == null) {
API.triggerServerEvent("menu_handler_user_input", args[0], text);
}
else {
API.triggerServerEvent("menu_handler_user_input", args[0], text, args[3]);
}
}
});