gui.openurl not working (no error) - lua

The following code is for an escape menu in a garrys mod server. It's written in lua. I have no idea what the problem could be and I've been working at it for a very long time. There is absolutely no error returned. Here's the full thing:
local buttonList = {
{
name = "Continue",
callback = function(panel)
panel:Remove();
Atomic.pauseUI = nil;
end
},
{
name = "Menu",
callback = function(panel)
panel:Remove();
gui.ActivateGameUI();
Atomic.showDefaultMenu = true;
Atomic.delayCheck = true;
end
},
--[[
{
name = "Settings",
callback = function(panel)
// panel:Remove();
end
},
--]]
{
name = "Rules",
callback = function(panel)
gui.OpenURL("https://steamcommunity.com/linkfilter/?url=https://facepunch.com")
end;
},
{
name = "Disconnect",
callback = function(panel)
RunConsoleCommand("disconnect");
end
}
};

Related

How to Sort a Multi-dimensional Array by Value in Lua

Unfortunately, sorting tables in lua still remains difficult for me. Who can help me with the following question:
I would like to sort the table below by pluNumber:
Original tabel:
[3] = {
[1] = {
['article'] = {
['pluNumber'] = '204',
['name'] = 'Cola Zero'
}
},
[2] = {
['article'] = {
['pluNumber'] = '202',
['name'] = 'Sinas'
}
},
[3] = {
['article'] = {
['pluNumber'] = '203',
['name'] = '7-up'
}
},
[4] = {
['article'] = {
['pluNumber'] = '201',
['name'] = 'Cola'
}
}
}
New table:
[3] = {
[1] = {
['article'] = {
['pluNumber'] = '201',
['name'] = 'Cola'
}
},
[2] = {
['article'] = {
['pluNumber'] = '202',
['name'] = 'Sinas'
}
},
[3] = {
['article'] = {
['pluNumber'] = '203',
['name'] = '7-up'
}
},
[4] = {
['article'] = {
['pluNumber'] = '204',
['name'] = 'Cola Zero'
}
}
}
Where do I begin? I didn't succeed with a normal table.sort
Please help
You need to provide a function that tells Lua which of two table elements comes first.
table.sort(yourTable, function (a, b)
return a.article.pluNumber < b.article.pluNumber end
Or
table.sort(yourTable, function (a, b)
return a.article.pluNumber > b.article.pluNumber end
for decending order. This is explained in the Lua reference manual.
https://www.lua.org/manual/5.4/manual.html#pdf-table.sort

Lua: Add a table inside a table

local test = {
{
Resource = "test",
},
},
How can I add a table inside another table? so it will look like this
local test = {
{
Resource = "test",
{
File = "this is a test",
Code = "this is a test",
},
{
File = "this is a test",
Code = "this is a test",
},
},
}
Umm im only writing this because this post is mostly code and therefore have to put more text.
so please ignore this part :) and good new year
local test = {
{
Resource = "test",
},
}
for i = 1,2 do
test[1][i] = {
File = "this is a test",
Code = "this is a test",
}
end
or
for _ = 1,2 do
table.insert(test[1], {
File = "this is a test",
Code = "this is a test",
}
end

How to add table to table?

I want to add table 'mm' to table 'fmenu.pages' but it doesnt work at all. Error: attempt to index a nil value (field 'main2'). Its about last line. Code:
local fmenu = {
selected_button = 0,
menu = {
font = 1,
},
pages = {
["main"] = {
name = "name",
id = 1,
btns = {
{name = "name I", id = 1}
}
}
}
}
local mm = {
["main2"] = {
name = "name2",
id = 2,
btns = {
{name = "name I", id = 1},
{name = "name II", id = 2}
}
}
}
table.insert(fmenu.pages, mm)
print(fmenu.pages["main2"].name)
How about using table.merge from lua-stdlib?
local table = require"std.table"
local fmenu = {
selected_button = 0,
menu = {
font = 1,
},
pages = {
["main"] = {
name = "name",
id = 1,
btns = {
{name = "name I", id = 1}
}
}
}
}
local mm = {
["main2"] = {
name = "name2",
id = 2,
btns = {
{name = "name I", id = 1},
{name = "name II", id = 2}
}
}
}
table.merge(fmenu.pages, mm)
print(fmenu.pages["main2"].name)

payday2 demo menu script syntax error in Lua

I get an error when I run ingame it says
also posted source on pastebin SOURCE
The place where the error happens:
menu1 = menu1 or {
{ text = "Cancel", is_cancel_button = true }
{},
{ text = "+G0DM0DE~", callback = godmode }
{ text = "+Stamina Hack~", callback = staminahx }
{ text = "+Equipment/Tie Hack~", callback = sawsandties }
{ text = "No Recoil Or Spread!", callback = norclorsprd }
{ text = "< - Back", callback = callmenu0 },
}
You need to add comma between each elements of the table:
menu1 = menu1 or {
{ text = "Cancel", is_cancel_button = true }, --here
{},
{ text = "+G0DM0DE~", callback = godmode }, --here
{ text = "+Stamina Hack~", callback = staminahx }, --here
{ text = "+Equipment/Tie Hack~", callback = sawsandties }, --here
{ text = "No Recoil Or Spread!", callback = norclorsprd }, --here
{ text = "< - Back", callback = callmenu0 },
}

get clicked element id with javascript not jquery

I have 2 buttons that are in a popup.when each button clicked, popup perform callback .
my problem is when popup make callback i want to know which button clicked and Causes callback
i wrote this code but it don't work , Because in BeginCallback property S.name is the name of popup also e.buttonID is null Because Html.DevExpress().Button dont render input with button type ,it render td and div tag
please help me.
#Html.DevExpress().PopupControl(
settings =>
{
settings.Name = "GetDatepopUp";
settings.PopupElementID = "GetDate";
settings.PopupAction = PopupAction.LeftMouseClick;
settings.CloseAction = CloseAction.CloseButton;
settings.Modal = true;
settings.ShowOnPageLoad = false;
settings.LoadContentViaCallback = LoadContentViaCallback.OnPageLoad;
settings.SetContent(() =>
{
#Html.RenderPartial("CalenderContainerPartialView", "Message");
});
settings.CallbackRouteValues =
new { Controller = "Message", Action = "Calender" };
settings.ClientSideEvents.BeginCallback =
"function(s,e) { e.customArgs['btnName'] = s.name; }";
settings.SetFooterTemplateContent(c =>
{
ViewContext.Writer.Write("<Table style='width:100%'><tr><td>");
Html.DevExpress().Button(buttonsettings =>
{
buttonsettings.Name = "btnNext";
buttonsettings.Text = "<<";
buttonsettings.ClientSideEvents.Click =
"function(s, e) { GetDatepopUp.PerformCallback(); }";
}).Render();
ViewContext.Writer.Write("</td><td>");
Html.DevExpress().Button(buttonsettings =>
{
buttonsettings.Name = "btnPrevious";
buttonsettings.Text = ">>";
buttonsettings.ClientSideEvents.Click =
"function(s, e) { GetDatepopUp.PerformCallback(); }";
}).Render();
ViewContext.Writer.Write("</td></tr></table>");
});
}).GetHtml()
try changing:
GetDatepopUp.PerformCallback();
to this:
GetDatepopUp.PerformCallback('btnPrevious');

Resources