plmqq Posted January 7, 2023 Share Posted January 7, 2023 Hello! I need to display random messages in AdminForm while opening admin panel without restarting it But when i create table and set text to aMessages[math.random(#aMessages)], it changes only on restarting admin resource, but i need changing every time when you open it Code: aMessages = { [[Admin panel by Lil_toady]], [[TEST1]], [[TEST2]], [[TEST3]], [[TEST4]], [[TEST5]] } guiCreateLabel ( 0.75, 0.05, 0.45, 0.04, aMessages[math.random(#aMessages)], true, aAdminForm ) Link to comment
Spakye Posted January 7, 2023 Share Posted January 7, 2023 Hello, you have to pick a new message each time you open that gui. If you are using the basic admin resource that come with mta server ( which i think you do ) then you can edit the function aAdminMain.Open () inside c_gui.lua like so : local aMessages = { [[Admin panel by Lil_toady]], [[TEST1]], [[TEST2]], [[TEST3]], [[TEST4]], [[TEST5]] } local yourLabel -- creating both vars here so its accessible from anywhere in the file function aAdminMain.Open () if ( aAdminMain.Form == nil ) then local x, y = guiGetScreenSize() aAdminMain.Form = guiCreateWindow ( x / 2 - 310 - 20, y / 2 - 260 - 20, 620, 520, "Anti-Cheat Panel - v".._version, false ) aAdminMain.Panel = guiCreateTabPanel ( 0.01, 0.05, 0.98, 0.95, true, aAdminMain.Form ) aAdminMain.AddTab ( "Status", aAntiCheatTab, "anticheat" ) aAdminMain.AddTab ( "Status #2", aAntiCheatTab2, "anticheat" ) aAdminMain.AddTab ( "Block Img Mods", aBlockModsTab, "mods" ) aAdminMain.AddTab ( "Server Config", aServerConfigTab, "server" ) yourLabel = guiCreateLabel ( 0.75, 0.05, 0.45, 0.04, "", true, aAdminForm ) -- creating the label here with other gui elements addEventHandler ( "onClientGUITabSwitched", resourceRoot, aAdminMain.Switch ) addEventHandler ( "onAdminInitialize", aAdminMain.Form, aAdminMain.Initialize ) triggerEvent ( "onAdminInitialize", aAdminMain.Form ) end guiSetText ( yourLabel , aMessages[math.random(#aMessages)] ) -- updating the random message each time you open the window guiSetAlpha ( aAdminMain.Form, 1 ) guiSetVisible ( aAdminMain.Form, true ) showCursor ( true ) aAdminMain.Hidden = false end Please note that i didnt test it and didnt script in a long time so i maybe made a mistake. Link to comment
plmqq Posted January 7, 2023 Author Share Posted January 7, 2023 2 hours ago, Spakye said: Hello, you have to pick a new message each time you open that gui. If you are using the basic admin resource that come with mta server ( which i think you do ) then you can edit the function aAdminMain.Open () inside c_gui.lua like so : local aMessages = { [[Admin panel by Lil_toady]], [[TEST1]], [[TEST2]], [[TEST3]], [[TEST4]], [[TEST5]] } local yourLabel -- creating both vars here so its accessible from anywhere in the file function aAdminMain.Open () if ( aAdminMain.Form == nil ) then local x, y = guiGetScreenSize() aAdminMain.Form = guiCreateWindow ( x / 2 - 310 - 20, y / 2 - 260 - 20, 620, 520, "Anti-Cheat Panel - v".._version, false ) aAdminMain.Panel = guiCreateTabPanel ( 0.01, 0.05, 0.98, 0.95, true, aAdminMain.Form ) aAdminMain.AddTab ( "Status", aAntiCheatTab, "anticheat" ) aAdminMain.AddTab ( "Status #2", aAntiCheatTab2, "anticheat" ) aAdminMain.AddTab ( "Block Img Mods", aBlockModsTab, "mods" ) aAdminMain.AddTab ( "Server Config", aServerConfigTab, "server" ) yourLabel = guiCreateLabel ( 0.75, 0.05, 0.45, 0.04, "", true, aAdminForm ) -- creating the label here with other gui elements addEventHandler ( "onClientGUITabSwitched", resourceRoot, aAdminMain.Switch ) addEventHandler ( "onAdminInitialize", aAdminMain.Form, aAdminMain.Initialize ) triggerEvent ( "onAdminInitialize", aAdminMain.Form ) end guiSetText ( yourLabel , aMessages[math.random(#aMessages)] ) -- updating the random message each time you open the window guiSetAlpha ( aAdminMain.Form, 1 ) guiSetVisible ( aAdminMain.Form, true ) showCursor ( true ) aAdminMain.Hidden = false end Please note that i didnt test it and didnt script in a long time so i maybe made a mistake. No, there are mistakes Link to comment
Spakye Posted January 7, 2023 Share Posted January 7, 2023 What error msg do you get? Link to comment
plmqq Posted January 8, 2023 Author Share Posted January 8, 2023 13 hours ago, Spakye said: What error msg do you get? ERROR: admin\client\gui\admin_main.lua:52: attempt to index global 'aAdminMain' (a nil value) Admin main just not exist Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now