SuperVisor Posted December 19, 2018 Posted December 19, 2018 updatesMemo = "" currentDate = "" local sx, sy = guiGetScreenSize ( ) local screenW, screenH = guiGetScreenSize ( ) local currentList = { } -- Tables local main = {} local read = { } local add = { button = {}, edit = {} } local remove = { button = {} } -- View Panel main.window = guiCreateWindow((screenW - 587) / 2, (screenH - 400) / 2, 587, 400, "Recent Updates", false) staticimage = guiCreateStaticImage(0.3104, 0.1000, 0.4200, 0.2800, "logo.png", true, main.window) guiWindowSetMovable ( main.window, false ) guiWindowSetSizable(main.window, false) guiSetVisible ( main.window, false ) main.grid = guiCreateMemo(0.0187, 0.501, 0.9659, 0.413, "", true, main.window) guiMemoSetReadOnly(main.grid,true) main.close = guiCreateButton(0.9000, 0.0900, 0.0587, 0.0587, "X", true, main.window) infogrids = guiCreateLabel(0.1554, 0.3851, 0.6884, 0.1174, "Recent Updates", true, main.window) guiLabelSetColor(infogrids, 0, 255, 0) guiLabelSetVerticalAlign(infogrids, "center") guiLabelSetHorizontalAlign(infogrids, "center", false) guiSetFont(infogrids, "default-bold-small") -- Adding Panel add.window = guiCreateWindow( ( sx / 2 - 482 / 2 ), ( sy / 2 - 571 / 2 ), 482, 571, "Add Updates Panel", false) guiWindowSetSizable(add.window, false) guiSetVisible ( add.window, false ) guiCreateLabel(10, 32, 145, 15, "Date (DD/MM/YYYY):", false, add.window) add.edit['date'] = guiCreateEdit(9, 53, 454, 28, "", false, add.window) guiCreateLabel(10, 103, 145, 15, "Update:", false, add.window) add.edit['update'] = guiCreateMemo(13, 125, 450, 294, "", false, add.window) guiCreateLabel(10, 449, 145, 15, "Author:", false, add.window) add.edit['author'] = guiCreateEdit(9, 468, 454, 28, "", false, add.window) add.button['add'] = guiCreateButton(12, 508, 143, 44, "Add Update", false, add.window) add.button['cancel'] = guiCreateButton(165, 508, 143, 44, "Cancel/close", false, add.window) add.button['remove'] = guiCreateButton(320, 508, 143, 44, "Remove a update", false, add.window) -- Remove Panel remove.window = guiCreateWindow( ( sx / 2 - 552 / 2 ), ( sy / 2 - 533 / 2 ), 552, 533, "Remove an Update Panel", false) guiWindowSetSizable(remove.window, false) guiSetVisible ( remove.window, false ) remove.grid = guiCreateGridList(10, 28, 532, 443, false, remove.window) guiGridListAddColumn(remove.grid, "Date", 0.18) guiGridListAddColumn(remove.grid, "Update", 0.58) guiGridListAddColumn(remove.grid, "Developer", 0.2) remove.button['remove'] = guiCreateButton(376, 481, 166, 36, "Remove", false, remove.window) guiSetProperty(remove.button['remove'], "NormalTextColour", "FFFF0000") remove.button['back'] = guiCreateButton(10, 481, 166, 36, "Add a update", false, remove.window) -- Read More read.window = guiCreateWindow( ( sx / 2 - 407 / 2 ), ( sy / 2 - 397 / 2 ), 407, 397, "Read More", false) guiWindowSetSizable(read.window, false) guiSetVisible ( read.window, false ) guiSetAlpha ( read.window, 1 ) guiWindowSetMovable ( read.window, false ) read.date = guiCreateLabel(9, 35, 275, 25, "Date: Loading..", false, read.window) read.author = guiCreateLabel(9, 70, 388, 25, "Developer: Loading...", false, read.window) guiCreateLabel(9, 105, 388, 25, "Update:", false, read.window) read.update = guiCreateMemo(9, 127, 388, 253, "Loading..", false, read.window) guiMemoSetReadOnly(read.update, true) read.close = guiCreateButton(294, 25, 103, 35, "Exit", false, read.window) days = {"1st","2nd","3rd","4th","5th","6th","7th","8th","9th","10th","11th","12th","13th","14th","15th","16th","17th","18th","19th","20th","21st","22nd","23rd","24th","25th","26th","27th","28th","29th","30th","31st"} months = {"January","February","March","April","May","June","July","August","September","October","November","December"} function accountsExport(ag1) updatesMemo = "" if (type(ag1) == 'table') then currentList = { } local updates = { } for index, variable in ipairs(ag1) do local lol = updates updates = { } table.insert(updates, {variable['Date_'], variable['Name'], variable['Developer']}) for i, v in ipairs(lol) do table.insert(updates, v) end end for i,v in ipairs(updates) do d, m, y = string.match(v[1], "(%d+)/(%d+)/(%d+)") performdate = getdayofweek(d,m,y).." "..days[tonumber(d)].." "..months[tonumber(m)].." "..y if currentDate ~= v[1] then currentDate = v[1] updatesMemo = updatesMemo.. "".. performdate.."\n" end three = string.gsub(v[3],"%[","") three = string.gsub(three,"%]","") three = string.gsub(three,"","") three = string.gsub(three,"","") str = "- "..v[2].." ("..three..")" updatesMemo = updatesMemo ..string.gsub(str,"\n","").."\n\n" triggerEvent("accounts.GetUpdates", source, updatesMemo) end currentList = updates end end addEvent("updates.acc", true) addEventHandler("Supdates.acc", root, accountsExport) addEvent ( "Updates:onPanelChangeState", true ) addEventHandler ( "Updates:onPanelChangeState", root, function ( window, ag1 ) guiSetText(main.grid,"") updatesMemo = "" if ( window == 'main' ) then if ( guiGetVisible ( add.window ) ) then guiSetVisible ( add.window, false ) showCursor ( false ) end if ( guiGetVisible ( remove.window ) ) then guiSetVisible ( remove.window, false ) showCursor ( false ) end guiSetVisible ( main.window, true ) showCursor ( true ) if ( type ( ag1 ) == 'table' ) then currentList = { } -- Reverse the loop -- local updates = { } for index, variable in ipairs ( ag1 ) do local lol = updates updates = { } table.insert ( updates, { variable['Date_'], variable['Name'], variable['Developer'] } ) for i, v in ipairs ( lol ) do table.insert ( updates, v ) end end for i,v in ipairs ( updates ) do d, m, y = string.match(v[1], "(%d+)/(%d+)/(%d+)") performdate = getdayofweek(d,m,y).." "..days[tonumber(d)].." "..months[tonumber(m)].." "..y if currentDate ~= v[1] then currentDate = v[1] updatesMemo = updatesMemo.. "".. performdate.."\n" end three = string.gsub(v[3],"%[","") three = string.gsub(three,"%]","") three = string.gsub(three,"","") three = string.gsub(three,"","") str = "- "..v[2].." ("..three..")" updatesMemo = updatesMemo ..string.gsub(str,"\n","").."\n\n" guiSetText(main.grid,updatesMemo) end currentList = updates else guiSetText ( main.grid, "Failed to load updates" ) end elseif ( window == 'manager' ) then if ( guiGetVisible ( remove.window ) ) then return end if ( guiGetVisible ( main.window ) ) then guiSetVisible ( main.window, false ) showCursor ( false ) end if ( guiGetVisible ( read.window ) ) then guiSetVisible ( read.window, false ) end guiSetVisible ( add.window, true ) showCursor ( true ) guiSetText ( add.edit['author'], getPlayerName ( localPlayer ) ) local time = getRealTime ( ) local day = time.monthday local month = time.month + 1 local year = time.year + 1900 if ( day < 10 ) then day = 0 .. day end if ( month < 10 ) then month = 0 .. month end guiSetText ( add.edit['date'], table.concat ( { day, month, year }, "/" ) ) guiSetInputMode ( "no_binds_when_editing" ) end end ) addEventHandler ( 'onClientGUIClick', root, function ( btn ) if ( btn == 'left' ) then -- Main Panel if ( source == main.readmore ) then local row, col = guiGridListGetSelectedItem ( main.grid ) if ( row ~= -1 and col ~= 0 ) then guiSetVisible ( read.window, true ) guiBringToFront ( read.window ) guiSetText ( read.date, "Date: "..guiGridListGetItemText ( main.grid, row, 1 ) ) guiSetText ( read.update, guiGridListGetItemText ( main.grid, row, 2 ) ) guiSetText ( read.author, "Developer: "..guiGridListGetItemText ( main.grid, row, 3 ) ) else outputChatBox ( "Select an update.", 255, 255, 0 ) end elseif ( source == read.close ) then guiSetVisible ( read.window, false ) elseif ( source == main.close ) then guiSetText(main.grid,"") guiSetVisible ( main.window, false ) showCursor ( false ) if ( guiGetVisible ( read.window ) ) then guiSetVisible ( read.window, false ) end -- Adding Panel elseif ( source == add.button['cancel'] ) then guiSetVisible ( add.window, false ) showCursor ( false ) elseif ( source == add.button['add'] ) then local date, update, author = guiGetText ( add.edit['date'] ), guiGetText ( add.edit['update'] ), guiGetText ( add.edit['author'] ) if ( date ~= '' and update ~= '' and author ~= '' ) then triggerServerEvent ( "Updates:onServerEvent", localPlayer, 'addUpdate', { date, update, author } ) else outputChatBox ( "You need to enter all of the information.", 255, 0, 0 ) end elseif ( source == add.button['remove'] ) then guiSetVisible ( add.window, false ) guiSetVisible ( remove.window, true ) guiGridListClear ( remove.grid ) if ( currentList and #currentList > 0 ) then for index, var in ipairs ( currentList ) do local row = guiGridListAddRow ( remove.grid ) guiGridListSetItemText ( remove.grid, row, 1, var[1], false, false ) guiGridListSetItemText ( remove.grid, row, 2, var[2], false, false ) guiGridListSetItemText ( remove.grid, row, 3, var[3], false, false ) end else guiGridListSetItemText ( remove.grid, guiGridListAddRow ( remove.grid ), 2, "Please use /updates, then come back to this panel.", true, true ) guiGridListSetItemColor ( remove.grid, 0, 2, 255, 0, 0 ) end -- remove panel elseif ( source == remove.button['back'] ) then guiSetVisible ( remove.window, false ) guiSetVisible ( add.window, true ) elseif ( source == remove.button['remove'] ) then local row, col = guiGridListGetSelectedItem ( remove.grid ) if ( row ~= -1 and col ~= 0 ) then local date = guiGridListGetItemText ( remove.grid, row, 1 ) local update = guiGridListGetItemText ( remove.grid, row, 2 ) local author = guiGridListGetItemText ( remove.grid, row, 3 ) for index, var in ipairs ( currentList ) do if ( var[1] == date and var[2] == update and var[3] == author ) then table.remove ( currentList, index ) break end end guiGridListClear ( remove.grid ) if ( #currentList > 0 ) then for index, var in ipairs ( currentList ) do local row = guiGridListAddRow ( remove.grid ) guiGridListSetItemText ( remove.grid, row, 1, var[1], false, false ) guiGridListSetItemText ( remove.grid, row, 2, var[2], false, false ) guiGridListSetItemText ( remove.grid, row, 3, var[3], false, false ) end else guiGridListSetItemText ( remove.grid, guiGridListAddRow ( remove.grid ), 2, "No updates found.", true, true ) end triggerServerEvent ( 'Updates:onServerEvent', localPlayer, 'removeUpdate', { date, update, author } ) end end end end ) function getdayofweek(dd, mm, yy) local days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" } local mmx = mm if (mm == 1) then mmx = 13; yy = yy-1 end if (mm == 2) then mmx = 14; yy = yy-1 end local val8 = dd + (mmx*2) + math.floor(((mmx+1)*3)/5) + yy + math.floor(yy/4) - math.floor(yy/100) + math.floor(yy/400) + 2 local val9 = math.floor(val8/7) local dw = val8-(val9*7) if (dw == 0) then dw = 7 end return days[dw] end fileDelete("client.lua") ---Command function updates () outputChatBox ( "#b23fff(SERVER):#ffffff A new update has been added, type /news to check it out.", 0, 255, 0, true ) end addCommandHandler("update", updates) How to make Gui show when player Login ! Script of Login Name ="LoginP"
DNL291 Posted December 20, 2018 Posted December 20, 2018 -- server-side "onPlayerLogin" triggerClientEvent -- client-side addEvent addEventHandler guiSetVisible showCursor Please do not PM me with scripting related question nor support, use the forums instead.
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