2019-10-20 11:48:14 +02:00
--antigrief things made by mewmew
2020-07-01 19:35:38 +02:00
local Event = require ' utils.event '
2020-08-14 22:07:54 +02:00
local Jailed = require ' utils.datastore.jail_data '
2022-04-05 19:28:08 +02:00
local Gui = require ' utils.gui '
2021-12-05 22:15:49 +01:00
local AntiGrief = require ' utils.antigrief '
2020-12-14 19:36:37 +01:00
local SpamProtection = require ' utils.spam_protection '
2023-11-12 22:39:24 +01:00
local Color = require ' utils.color_presets '
local Server = require ' utils.server '
local Task = require ' utils.task '
2021-03-25 23:49:57 +01:00
local Token = require ' utils.token '
2024-01-28 23:13:32 +01:00
local Global = require ' utils.global '
2023-11-24 19:38:17 +01:00
local Public = { }
2019-10-20 11:48:14 +02:00
2023-11-24 19:38:17 +01:00
local insert = table.insert
2020-07-01 19:35:38 +02:00
local lower = string.lower
2024-01-28 23:13:32 +01:00
local ceil = math.ceil
local max = math.max
local min = math.min
2022-04-05 19:28:08 +02:00
local module_name = Gui.uid_name ( )
2024-01-28 23:13:32 +01:00
local next_button_name = Gui.uid_name ( )
local prev_button_name = Gui.uid_name ( )
2024-01-29 08:06:24 +01:00
local listable_players_name = Gui.uid_name ( )
2024-01-28 23:13:32 +01:00
local rows_per_page = 100
local this = {
admin_panel_selected_history_index = { } ,
admin_panel_selected_player_index = { } ,
admin_panel_listable_players_index = { } ,
admin_panel_paginator_selected_page = { }
}
Global.register (
this ,
function ( tbl )
this = tbl
end
)
2019-10-20 11:48:14 +02:00
2023-11-12 22:39:24 +01:00
local function clear_validation_action ( player_name , action )
local admin_button_validation = AntiGrief.get ( ' admin_button_validation ' )
if admin_button_validation and admin_button_validation [ action ] then
admin_button_validation [ action ] [ player_name ] = nil
end
end
local clear_validation_token =
Token.register (
function ( event )
local action = event.action
if not action then
return
end
local player_name = event.player_name
if not player_name then
return
end
local admin_button_validation = AntiGrief.get ( ' admin_button_validation ' )
if admin_button_validation and admin_button_validation [ action ] then
admin_button_validation [ action ] [ player_name ] = nil
end
end
)
local function validate_action ( player , action )
local admin_button_validation = AntiGrief.get ( ' admin_button_validation ' )
if not admin_button_validation [ action ] then
admin_button_validation [ action ] = { }
end
if not admin_button_validation [ action ] [ player.name ] then
admin_button_validation [ action ] [ player.name ] = true
Task.set_timeout_in_ticks ( 100 , clear_validation_token , { player_name = player.name , action = action } )
player.print ( ' Please run this again if you are certain that you want to run this action[ ' .. action .. ' ]. ' , Color.warning )
return true
end
return false
end
2020-07-10 13:52:55 +02:00
local function admin_only_message ( str )
for _ , player in pairs ( game.connected_players ) do
if player.admin == true then
player.print ( ' Admins-only-message: ' .. str , { r = 0.88 , g = 0.88 , b = 0.88 } )
end
end
end
2019-10-20 11:48:14 +02:00
local function jail ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' jail ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2023-11-12 22:39:24 +01:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' jail ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2023-11-12 22:39:24 +01:00
Jailed.try_ul_data ( player.name , true , source_player.name , ' Jailed by ' .. source_player.name .. ' ! ' )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' jail ' )
2023-11-12 22:39:24 +01:00
end
local function mute ( player , source_player )
if validate_action ( source_player , ' mute ' ) then
return
end
if player.name == source_player.name then
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' mute ' )
2023-11-12 22:39:24 +01:00
return
end
Jailed.try_ul_data ( player.name , true , source_player.name , ' Jailed and muted by ' .. source_player.name .. ' ! ' , true )
local muted = Jailed.mute_player ( player )
local muted_str = muted and ' muted ' or ' unmuted '
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' jail ' )
2023-11-12 22:39:24 +01:00
game.print ( player.name .. ' was ' .. muted_str .. ' by player ' .. source_player.name .. ' ! ' , { r = 1 , g = 0.5 , b = 0.1 } )
2019-10-20 11:48:14 +02:00
end
local function free ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' free ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2023-11-12 22:39:24 +01:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' free ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-07-07 23:42:44 +02:00
Jailed.try_ul_data ( player.name , false , source_player.name )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' free ' )
2019-10-20 11:48:14 +02:00
end
local bring_player_messages = {
2020-06-28 14:40:39 +02:00
' Come here my friend! ' ,
' Papers, please. ' ,
' What are you up to? '
2019-10-20 11:48:14 +02:00
}
2020-06-28 14:40:39 +02:00
2019-10-20 11:48:14 +02:00
local function bring_player ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' bring_player ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2023-11-12 22:39:24 +01:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' bring_player ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
if player.driving == true then
source_player.print ( ' Target player is in a vehicle, teleport not available. ' , { r = 0.88 , g = 0.88 , b = 0.88 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' bring_player ' )
2020-06-28 14:40:39 +02:00
return
end
local pos = source_player.surface . find_non_colliding_position ( ' character ' , source_player.position , 50 , 1 )
if pos then
player.teleport ( pos , source_player.surface )
2022-04-05 19:28:08 +02:00
game.print ( player.name .. ' has been teleported to ' .. source_player.name .. ' . ' .. bring_player_messages [ math.random ( 1 , # bring_player_messages ) ] , { r = 0.98 , g = 0.66 , b = 0.22 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' bring_player ' )
2020-06-28 14:40:39 +02:00
end
2019-10-20 11:48:14 +02:00
end
local go_to_player_messages = {
2020-06-28 14:40:39 +02:00
' Papers, please. ' ,
' What are you up to? '
2019-10-20 11:48:14 +02:00
}
local function go_to_player ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' go_to_player ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2023-11-12 22:39:24 +01:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' go_to_player ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
local pos = player.surface . find_non_colliding_position ( ' character ' , player.position , 50 , 1 )
if pos then
source_player.teleport ( pos , player.surface )
2022-04-05 19:28:08 +02:00
game.print ( source_player.name .. ' is visiting ' .. player.name .. ' . ' .. go_to_player_messages [ math.random ( 1 , # go_to_player_messages ) ] , { r = 0.98 , g = 0.66 , b = 0.22 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' go_to_player ' )
2020-06-28 14:40:39 +02:00
end
2019-10-20 11:48:14 +02:00
end
local function spank ( player , source_player )
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
return player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
end
2020-06-28 14:40:39 +02:00
if player.character then
if player.character . health > 1 then
player.character . damage ( 1 , ' player ' )
end
player.character . health = player.character . health - 5
player.surface . create_entity ( { name = ' water-splash ' , position = player.position } )
game.print ( source_player.name .. ' spanked ' .. player.name , { r = 0.98 , g = 0.66 , b = 0.22 } )
end
2019-10-20 11:48:14 +02:00
end
local damage_messages = {
2020-06-28 14:40:39 +02:00
' recieved a love letter from ' ,
' recieved a strange package from '
2019-10-20 11:48:14 +02:00
}
local function damage ( player , source_player )
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
return player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
end
2020-06-28 14:40:39 +02:00
if player.character then
if player.character . health > 1 then
player.character . damage ( 1 , ' player ' )
end
player.character . health = player.character . health - 125
player.surface . create_entity ( { name = ' big-explosion ' , position = player.position } )
2020-12-14 19:36:37 +01:00
game.print ( player.name .. damage_messages [ math.random ( 1 , # damage_messages ) ] .. source_player.name , { r = 0.98 , g = 0.66 , b = 0.22 } )
2020-06-28 14:40:39 +02:00
end
2019-10-20 11:48:14 +02:00
end
local kill_messages = {
2020-06-28 14:40:39 +02:00
' did not obey the law. ' ,
' should not have triggered the admins. ' ,
' did not respect authority. ' ,
' had a strange accident. ' ,
' was struck by lightning. '
2019-10-20 11:48:14 +02:00
}
local function kill ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' kill ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2023-11-12 22:39:24 +01:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' kill ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
if player.character then
player.character . die ( ' player ' )
game.print ( player.name .. kill_messages [ math.random ( 1 , # kill_messages ) ] , { r = 0.98 , g = 0.66 , b = 0.22 } )
admin_only_message ( source_player.name .. ' killed ' .. player.name )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' kill ' )
2020-06-28 14:40:39 +02:00
end
2019-10-20 11:48:14 +02:00
end
local enemy_messages = {
2020-06-28 14:40:39 +02:00
' Shoot on sight! ' ,
' Wanted dead or alive! '
2019-10-20 11:48:14 +02:00
}
local function enemy ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' enemy ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2023-11-12 22:39:24 +01:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' enemy ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
if not game.forces . enemy_players then
game.create_force ( ' enemy_players ' )
end
player.force = game.forces . enemy_players
2020-12-14 19:36:37 +01:00
game.print ( player.name .. ' is now an enemy! ' .. enemy_messages [ math.random ( 1 , # enemy_messages ) ] , { r = 0.95 , g = 0.15 , b = 0.15 } )
2020-06-28 14:40:39 +02:00
admin_only_message ( source_player.name .. ' has turned ' .. player.name .. ' into an enemy ' )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' enemy ' )
2019-10-20 11:48:14 +02:00
end
local function ally ( player , source_player )
2023-11-12 22:39:24 +01:00
if validate_action ( source_player , ' ally ' ) then
return
end
2020-07-06 23:22:03 +02:00
if player.name == source_player.name then
2023-11-12 22:39:24 +01:00
player.print ( " You can't select yourself! " , { r = 1 , g = 0.5 , b = 0.1 } )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' ally ' )
2023-11-12 22:39:24 +01:00
return
2020-07-06 23:22:03 +02:00
end
2020-06-28 14:40:39 +02:00
player.force = game.forces . player
game.print ( player.name .. ' is our ally again! ' , { r = 0.98 , g = 0.66 , b = 0.22 } )
admin_only_message ( source_player.name .. ' made ' .. player.name .. ' our ally ' )
2023-11-24 19:38:17 +01:00
clear_validation_action ( source_player.name , ' ally ' )
2019-10-20 11:48:14 +02:00
end
2019-10-20 12:52:19 +02:00
local function turn_off_global_speakers ( player )
2023-11-12 22:39:24 +01:00
if validate_action ( player , ' turn_off_global_speakers ' ) then
return
end
2020-06-28 14:40:39 +02:00
local counter = 0
for _ , surface in pairs ( game.surfaces ) do
local speakers = surface.find_entities_filtered ( { name = ' programmable-speaker ' } )
2023-11-12 22:39:24 +01:00
for _ , speaker in pairs ( speakers ) do
2020-06-28 14:40:39 +02:00
if speaker.parameters . playback_globally == true then
speaker.surface . create_entity ( { name = ' massive-explosion ' , position = speaker.position } )
2023-08-10 14:29:05 +02:00
speaker.destroy ( )
2020-06-28 14:40:39 +02:00
counter = counter + 1
end
end
end
if counter == 0 then
return
end
if counter == 1 then
game.print ( player.name .. ' has nuked ' .. counter .. ' global speaker. ' , { r = 0.98 , g = 0.66 , b = 0.22 } )
else
game.print ( player.name .. ' has nuked ' .. counter .. ' global speakers. ' , { r = 0.98 , g = 0.66 , b = 0.22 } )
end
2023-11-12 22:39:24 +01:00
clear_validation_action ( player.name , ' turn_off_global_speakers ' )
2019-10-20 11:48:14 +02:00
end
2019-10-20 12:52:19 +02:00
local function delete_all_blueprints ( player )
2023-11-12 22:39:24 +01:00
if validate_action ( player , ' delete_all_blueprints ' ) then
return
end
2020-06-28 14:40:39 +02:00
local counter = 0
for _ , surface in pairs ( game.surfaces ) do
for _ , ghost in pairs ( surface.find_entities_filtered ( { type = { ' entity-ghost ' , ' tile-ghost ' } } ) ) do
ghost.destroy ( )
counter = counter + 1
end
end
if counter == 0 then
2023-11-12 22:39:24 +01:00
clear_validation_action ( player.name , ' delete_all_blueprints ' )
2020-06-28 14:40:39 +02:00
return
end
if counter == 1 then
game.print ( counter .. ' blueprint has been cleared! ' , { r = 0.98 , g = 0.66 , b = 0.22 } )
else
game.print ( counter .. ' blueprints have been cleared! ' , { r = 0.98 , g = 0.66 , b = 0.22 } )
end
admin_only_message ( player.name .. ' has cleared all blueprints. ' )
2023-11-12 22:39:24 +01:00
clear_validation_action ( player.name , ' delete_all_blueprints ' )
end
local function pause_game_tick ( player )
if validate_action ( player , ' pause_game_tick ' ) then
return
end
local paused = game.tick_paused
local paused_str = paused and ' unpaused ' or ' paused '
game.tick_paused = not paused
game.print ( ' Game has been ' .. paused_str .. ' by ' .. player.name , { r = 0.98 , g = 0.66 , b = 0.22 } )
clear_validation_action ( player.name , ' pause_game_tick ' )
end
local function save_game ( player )
if validate_action ( player , ' save_game ' ) then
return
end
local date = Server.get_start_time ( ) or game.tick
game.server_save ( ' _currently_running ' .. tostring ( date ) .. ' _ ' .. player.name )
clear_validation_action ( player.name , ' save_game ' )
2019-10-20 11:48:14 +02:00
end
2023-11-24 19:38:17 +01:00
local function clear_items_on_ground ( player )
if validate_action ( player , ' clear_items_on_ground ' ) then
return
end
local i = 0
for _ , entity in pairs ( player.surface . find_entities_filtered { type = ' item-entity ' , name = ' item-on-ground ' } ) do
if entity and entity.valid then
entity.destroy ( )
i = i + 1
end
end
if i == 0 then
return player.print ( ' No items to clear! ' , Color.warning )
end
player.print ( ' Cleared: ' .. i .. ' items. ' , Color.success )
clear_validation_action ( player.name , ' clear_items_on_ground ' )
end
2020-06-29 15:50:01 +02:00
local function create_mini_camera_gui ( player , caption , position , surface )
2020-06-28 14:40:39 +02:00
if player.gui . center [ ' mini_camera ' ] then
player.gui . center [ ' mini_camera ' ] . destroy ( )
end
local frame = player.gui . center.add ( { type = ' frame ' , name = ' mini_camera ' , caption = caption } )
2020-06-29 15:50:01 +02:00
surface = tonumber ( surface )
2021-06-06 20:14:26 +02:00
surface = game.surfaces [ surface ]
if not surface or not surface.valid then
return
end
2020-06-28 14:40:39 +02:00
local camera =
frame.add (
{
type = ' camera ' ,
name = ' mini_cam_element ' ,
position = position ,
zoom = 0.6 ,
2021-06-13 13:54:19 +02:00
surface_index = surface.index
2020-06-28 14:40:39 +02:00
}
)
camera.style . minimal_width = 640
camera.style . minimal_height = 480
2019-10-20 11:48:14 +02:00
end
2020-07-01 19:35:38 +02:00
local function filter_brackets ( str )
return ( string.find ( str , ' %[ ' ) ~= nil )
end
local function match_test ( value , pattern )
return lower ( value : gsub ( ' - ' , ' ' ) ) : find ( pattern )
end
2020-07-07 23:42:44 +02:00
local function contains_text ( key , value , search_text )
if filter_brackets ( search_text ) then
return false
end
if value then
if not match_test ( key [ value ] , search_text ) then
return false
end
else
if not match_test ( key , search_text ) then
return false
end
end
return true
end
2020-07-01 19:35:38 +02:00
local function draw_events ( data )
local frame = data.frame
2024-01-28 23:13:32 +01:00
local player_name = data.player_name
2020-07-01 19:35:38 +02:00
local search_text = data.search_text or nil
2024-01-28 23:13:32 +01:00
local history = frame.pagination_table . admin_history_select.items [ frame.pagination_table . admin_history_select.selected_index ]
if not this.admin_panel_paginator_selected_page [ player_name ] then
this.admin_panel_paginator_selected_page [ player_name ] = 1
end
local current_page = this.admin_panel_paginator_selected_page [ player_name ]
local start_index = ( current_page - 1 ) * rows_per_page + 1
local end_index = start_index + rows_per_page - 1
2020-07-01 19:35:38 +02:00
local scroll_pane
if frame.datalog then
frame.datalog . clear ( )
else
scroll_pane =
frame.add (
{
type = ' scroll-pane ' ,
name = ' datalog ' ,
direction = ' vertical ' ,
horizontal_scroll_policy = ' never ' ,
vertical_scroll_policy = ' auto '
}
)
scroll_pane.style . maximal_height = 200
2020-07-30 19:09:18 +02:00
scroll_pane.style . minimal_width = 790
2020-07-01 19:35:38 +02:00
end
local target_player_name = frame [ ' admin_player_select ' ] . items [ frame [ ' admin_player_select ' ] . selected_index ]
2020-07-30 19:09:18 +02:00
2023-11-24 19:38:17 +01:00
Public.contains_text (
history ,
search_text ,
target_player_name ,
function ( history_label , tooltip )
2024-01-28 23:13:32 +01:00
if not history_label then
return
end
2020-07-30 19:09:18 +02:00
frame.datalog . add (
{
type = ' label ' ,
2023-11-24 19:38:17 +01:00
caption = history_label ,
tooltip = tooltip
2020-07-30 19:09:18 +02:00
}
)
2024-01-28 23:13:32 +01:00
end ,
start_index ,
end_index
2023-11-24 19:38:17 +01:00
)
2020-07-01 19:35:38 +02:00
end
local function text_changed ( event )
local element = event.element
if not element then
return
end
if not element.valid then
return
end
2021-12-05 22:26:18 +01:00
local player = game.get_player ( event.player_index )
2020-07-01 19:35:38 +02:00
2022-04-05 19:28:08 +02:00
local frame = Gui.get_player_active_frame ( player )
2020-07-01 19:35:38 +02:00
if not frame then
return
end
2022-04-05 19:28:08 +02:00
if frame.name ~= ' Admin ' then
2020-07-01 19:35:38 +02:00
return
end
2021-01-12 21:52:45 +01:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Text Changed ' )
2020-12-14 19:36:37 +01:00
if is_spamming then
return
end
2024-01-09 21:57:10 +01:00
if element.text ~= nil then
local data = {
frame = frame ,
2024-01-28 23:13:32 +01:00
search_text = element.text : lower ( ) ,
player_name = player.name
2024-01-09 21:57:10 +01:00
}
2020-07-01 19:35:38 +02:00
2024-01-09 21:57:10 +01:00
draw_events ( data )
end
2020-07-01 19:35:38 +02:00
end
2024-01-28 23:13:32 +01:00
local function create_pagination_buttons ( player , frame , table_count )
if table_count == 0 then
return
end
local last_page = ceil ( table_count / rows_per_page )
if not this.admin_panel_paginator_selected_page [ player.name ] then
this.admin_panel_paginator_selected_page [ player.name ] = 1
end
local current_page = this.admin_panel_paginator_selected_page [ player.name ]
if current_page == 1 and current_page == last_page then
return
end
local button_flow =
frame.add {
type = ' flow ' ,
direction = ' horizontal '
}
local prev_button =
button_flow.add {
type = ' button ' ,
name = prev_button_name ,
caption = ' ◀️ ' ,
style = ' back_button '
}
prev_button.style . font = ' default-bold '
prev_button.style . minimal_width = 32
prev_button.tooltip = ' Previous page \n Holding [color=yellow]shift[/color] while pressing LMB/RMB will jump to the first page. '
local count_label =
button_flow.add {
type = ' label ' ,
caption = current_page .. ' / ' .. last_page
}
count_label.style . font = ' default-bold '
local next_button =
button_flow.add {
type = ' button ' ,
name = next_button_name ,
caption = ' ▶️ ' ,
style = ' forward_button '
}
next_button.style . font = ' default-bold '
next_button.style . minimal_width = 32
next_button.tooltip = ' Next page \n Holding [color=yellow]shift[/color] while pressing LMB/RMB will jump to the last page. '
Gui.set_data ( next_button , table_count )
end
2021-03-25 23:49:57 +01:00
local function create_admin_panel ( data )
local player = data.player
local frame = data.frame
2020-06-29 15:50:01 +02:00
local antigrief = AntiGrief.get ( )
2022-07-04 00:27:35 +02:00
if not antigrief then
return
end
2024-01-28 23:13:32 +01:00
local checkbox_state = this.admin_panel_listable_players_index [ player.name ]
2020-06-28 14:40:39 +02:00
frame.clear ( )
2024-01-28 23:13:32 +01:00
local players = game.connected_players
if checkbox_state then
players = game.players
end
2020-06-28 14:40:39 +02:00
local player_names = { }
2024-01-28 23:13:32 +01:00
for _ , p in pairs ( players ) do
2023-11-24 19:38:17 +01:00
insert ( player_names , tostring ( p.name ) )
2020-06-28 14:40:39 +02:00
end
2023-11-24 19:38:17 +01:00
insert ( player_names , ' Select Player ' )
2020-06-28 14:40:39 +02:00
local selected_index = # player_names
2024-01-28 23:13:32 +01:00
local selected = this.admin_panel_selected_player_index
if selected then
if selected [ player.name ] then
if player_names [ selected [ player.name ] ] then
selected_index = selected [ player.name ]
2020-06-28 14:40:39 +02:00
end
end
end
2024-01-28 23:13:32 +01:00
local checkbox_caption = ' Currently showing: connected players only. '
if checkbox_state then
checkbox_caption = ' Currently showing: all players that have played on this server. '
end
2024-01-29 08:06:24 +01:00
frame.add ( { type = ' checkbox ' , name = listable_players_name , caption = checkbox_caption , state = checkbox_state or false } )
2024-01-28 23:13:32 +01:00
2020-12-14 19:36:37 +01:00
local drop_down = frame.add ( { type = ' drop-down ' , name = ' admin_player_select ' , items = player_names , selected_index = selected_index } )
2020-06-28 14:40:39 +02:00
drop_down.style . minimal_width = 326
drop_down.style . right_padding = 12
drop_down.style . left_padding = 12
2023-11-12 22:39:24 +01:00
local t = frame.add ( { type = ' table ' , column_count = 4 } )
2020-06-28 14:40:39 +02:00
local buttons = {
t.add (
{
type = ' button ' ,
caption = ' Jail ' ,
name = ' jail ' ,
tooltip = ' Jails the player, they will no longer be able to perform any actions except writing in chat. '
}
) ,
2023-11-12 22:39:24 +01:00
t.add (
{
type = ' button ' ,
caption = ' Mute ' ,
name = ' mute ' ,
tooltip = ' Jails and mutes the player, they will no longer be able to chat. '
}
) ,
2020-06-28 14:40:39 +02:00
t.add ( { type = ' button ' , caption = ' Free ' , name = ' free ' , tooltip = ' Frees the player from jail. ' } ) ,
t.add (
{
type = ' button ' ,
caption = ' Bring Player ' ,
name = ' bring_player ' ,
tooltip = ' Teleports the selected player to your position. '
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Make Enemy ' ,
name = ' enemy ' ,
2023-11-12 22:39:24 +01:00
tooltip = ' Sets the selected players force to enemy_players. \n DO NOT USE IN PVP MAPS!! '
2020-06-28 14:40:39 +02:00
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Make Ally ' ,
name = ' ally ' ,
2023-11-12 22:39:24 +01:00
tooltip = ' Sets the selected players force back to the default player force. \n DO NOT USE IN PVP MAPS!! '
2020-06-28 14:40:39 +02:00
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Go to Player ' ,
name = ' go_to_player ' ,
tooltip = ' Teleport yourself to the selected player. '
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Spank ' ,
name = ' spank ' ,
2023-11-12 22:39:24 +01:00
tooltip = ' Hurts the selected player with minor damage. \n Can not kill the player. '
2020-06-28 14:40:39 +02:00
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Damage ' ,
name = ' damage ' ,
2023-11-12 22:39:24 +01:00
tooltip = ' Damages the selected player with greater damage. \n Can not kill the player. '
2020-06-28 14:40:39 +02:00
}
) ,
t.add ( { type = ' button ' , caption = ' Kill ' , name = ' kill ' , tooltip = ' Kills the selected player instantly. ' } )
}
for _ , button in pairs ( buttons ) do
button.style . font = ' default-bold '
--button.style.font_color = { r=0.99, g=0.11, b=0.11}
button.style . minimal_width = 106
end
local line = frame.add { type = ' line ' }
line.style . top_margin = 8
line.style . bottom_margin = 8
2021-03-24 16:46:00 +01:00
frame.add ( { type = ' label ' , caption = ' Global Actions: ' } )
2023-11-12 22:39:24 +01:00
local actionTable = frame.add ( { type = ' table ' , column_count = 4 } )
2021-03-24 17:36:07 +01:00
local bottomButtons = {
actionTable.add (
2020-06-28 14:40:39 +02:00
{
type = ' button ' ,
caption = ' Destroy global speakers ' ,
name = ' turn_off_global_speakers ' ,
tooltip = ' Destroys all speakers that are set to play sounds globally. '
}
) ,
2021-03-24 17:36:07 +01:00
actionTable.add (
2020-06-28 14:40:39 +02:00
{
type = ' button ' ,
caption = ' Delete blueprints ' ,
name = ' delete_all_blueprints ' ,
tooltip = ' Deletes all placed blueprints on the map. '
}
2023-11-12 22:39:24 +01:00
) ,
actionTable.add (
{
type = ' button ' ,
caption = ' Pause game tick ' ,
name = ' pause_game_tick ' ,
tooltip = ' Pauses the game tick. '
}
) ,
actionTable.add (
{
type = ' button ' ,
caption = ' Save game ' ,
name = ' save_game ' ,
tooltip = ' Saves the game. '
}
2023-11-24 19:38:17 +01:00
) ,
actionTable.add (
{
type = ' button ' ,
caption = ' Clear items on ground ' ,
name = ' clear_items_on_ground ' ,
tooltip = ' Clears all items on the ground. \n This might lag the game! '
}
2020-06-28 14:40:39 +02:00
)
--- t.add({type = "button", caption = "Cancel all deconstruction orders", name = "remove_all_deconstruction_orders"})
}
2021-03-24 17:36:07 +01:00
for _ , button in pairs ( bottomButtons ) do
2020-06-28 14:40:39 +02:00
button.style . font = ' default-bold '
button.style . minimal_width = 80
end
2021-03-24 17:36:07 +01:00
local bottomLine = frame.add { type = ' line ' }
bottomLine.style . top_margin = 8
bottomLine.style . bottom_margin = 8
2020-06-28 14:40:39 +02:00
local histories = { }
2020-06-29 15:50:01 +02:00
if antigrief.capsule_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Capsule History ' )
2020-06-28 14:40:39 +02:00
end
2021-05-07 01:19:38 +02:00
if antigrief.message_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Message History ' )
2021-05-07 01:19:38 +02:00
end
2020-06-29 15:50:01 +02:00
if antigrief.friendly_fire_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Friendly Fire History ' )
2020-06-28 14:40:39 +02:00
end
2020-06-29 15:50:01 +02:00
if antigrief.mining_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Mining History ' )
2020-06-28 14:40:39 +02:00
end
2021-05-09 17:11:18 +02:00
if antigrief.whitelist_mining_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Mining Override History ' )
2021-05-09 17:11:18 +02:00
end
2020-06-29 15:50:01 +02:00
if antigrief.landfill_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Landfill History ' )
2020-06-28 14:40:39 +02:00
end
2020-06-29 15:50:01 +02:00
if antigrief.corpse_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Corpse Looting History ' )
2020-06-28 14:40:39 +02:00
end
2020-07-06 23:22:03 +02:00
if antigrief.cancel_crafting_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Cancel Crafting History ' )
2020-07-06 23:22:03 +02:00
end
2022-07-04 00:27:35 +02:00
if antigrief.deconstruct_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Deconstruct History ' )
2022-07-04 00:27:35 +02:00
end
2023-09-17 16:28:11 +02:00
if antigrief.scenario_history then
2023-11-24 19:38:17 +01:00
insert ( histories , ' Scenario History ' )
2023-09-17 16:28:11 +02:00
end
2020-06-28 14:40:39 +02:00
if # histories == 0 then
return
end
2020-07-01 19:35:38 +02:00
local search_table = frame.add ( { type = ' table ' , column_count = 2 } )
search_table.add ( { type = ' label ' , caption = ' Search: ' } )
local search_text = search_table.add ( { type = ' textfield ' } )
search_text.style . width = 140
2021-03-24 17:36:07 +01:00
local bottomLine2 = frame.add ( { type = ' label ' , caption = ' ---------------------------------------------- ' } )
bottomLine2.style . font = ' default-listbox '
bottomLine2.style . font_color = { r = 0.98 , g = 0.66 , b = 0.22 }
2020-06-28 14:40:39 +02:00
2020-06-29 15:50:01 +02:00
local selected_index_2 = 1
2024-01-28 23:13:32 +01:00
local selected_history = this.admin_panel_selected_history_index
if selected_history then
if selected_history [ player.name ] then
selected_index_2 = selected_history [ player.name ]
2020-06-28 14:40:39 +02:00
end
end
2024-01-28 23:13:32 +01:00
local pagination_table = frame.add ( { type = ' table ' , column_count = 2 , name = ' pagination_table ' } )
local drop_down_2 = pagination_table.add ( { type = ' drop-down ' , name = ' admin_history_select ' , items = histories , selected_index = selected_index_2 } )
2020-06-29 15:50:01 +02:00
drop_down_2.style . right_padding = 12
drop_down_2.style . left_padding = 12
2020-06-28 14:40:39 +02:00
2024-01-28 23:13:32 +01:00
local history_index = {
[ ' Capsule History ' ] = antigrief.capsule_history ,
[ ' Message History ' ] = antigrief.message_history ,
[ ' Friendly Fire History ' ] = antigrief.friendly_fire_history ,
[ ' Mining History ' ] = antigrief.mining_history ,
[ ' Mining Override History ' ] = antigrief.whitelist_mining_history ,
[ ' Landfill History ' ] = antigrief.landfill_history ,
[ ' Corpse Looting History ' ] = antigrief.corpse_history ,
[ ' Cancel Crafting History ' ] = antigrief.cancel_crafting_history ,
[ ' Deconstruct History ' ] = antigrief.deconstruct_history ,
[ ' Scenario History ' ] = antigrief.scenario_history
}
local history = frame.pagination_table . admin_history_select.items [ frame.pagination_table . admin_history_select.selected_index ]
create_pagination_buttons ( player , pagination_table , # history_index [ history ] )
2021-03-25 23:49:57 +01:00
local datas = {
2020-07-01 19:35:38 +02:00
frame = frame ,
2024-01-28 23:13:32 +01:00
antigrief = antigrief ,
player_name = player.name
2020-06-28 14:40:39 +02:00
}
2019-10-20 11:48:14 +02:00
2021-03-25 23:49:57 +01:00
draw_events ( datas )
end
local create_admin_panel_token = Token.register ( create_admin_panel )
2019-10-20 11:48:14 +02:00
local admin_functions = {
2020-06-28 14:40:39 +02:00
[ ' jail ' ] = jail ,
2023-11-12 22:39:24 +01:00
[ ' mute ' ] = mute ,
2020-06-28 14:40:39 +02:00
[ ' free ' ] = free ,
[ ' bring_player ' ] = bring_player ,
[ ' spank ' ] = spank ,
[ ' damage ' ] = damage ,
[ ' kill ' ] = kill ,
[ ' enemy ' ] = enemy ,
[ ' ally ' ] = ally ,
[ ' go_to_player ' ] = go_to_player
}
2019-10-20 11:48:14 +02:00
2019-10-20 12:52:19 +02:00
local admin_global_functions = {
2020-06-28 14:40:39 +02:00
[ ' turn_off_global_speakers ' ] = turn_off_global_speakers ,
2023-11-12 22:39:24 +01:00
[ ' delete_all_blueprints ' ] = delete_all_blueprints ,
[ ' pause_game_tick ' ] = pause_game_tick ,
2023-11-24 19:38:17 +01:00
[ ' save_game ' ] = save_game ,
[ ' clear_items_on_ground ' ] = clear_items_on_ground
2020-06-28 14:40:39 +02:00
}
2019-10-20 12:52:19 +02:00
2020-06-29 15:50:01 +02:00
local function get_surface_from_string ( str )
if not str then
return
end
if str == ' ' then
return
end
str = string.lower ( str )
local start = string.find ( str , ' surface: ' )
local sname = string.len ( str )
local surface = string.sub ( str , start + 8 , sname )
if not surface then
return false
end
return surface
end
2019-10-20 11:48:14 +02:00
local function get_position_from_string ( str )
2020-06-28 14:40:39 +02:00
if not str then
return
end
if str == ' ' then
return
end
str = string.lower ( str )
local x_pos = string.find ( str , ' x: ' )
local y_pos = string.find ( str , ' y: ' )
if not x_pos then
return false
end
if not y_pos then
return false
end
x_pos = x_pos + 2
y_pos = y_pos + 2
local a = 1
for i = 1 , string.len ( str ) , 1 do
local s = string.sub ( str , x_pos + i , x_pos + i )
if not s then
break
end
if string.byte ( s ) == 32 then
break
end
a = a + 1
end
local x = string.sub ( str , x_pos , x_pos + a )
2021-03-24 16:46:00 +01:00
local a1 = 1
2020-06-28 14:40:39 +02:00
for i = 1 , string.len ( str ) , 1 do
local s = string.sub ( str , y_pos + i , y_pos + i )
if not s then
break
end
if string.byte ( s ) == 32 then
break
end
2021-03-24 16:46:00 +01:00
a1 = a1 + 1
2020-06-28 14:40:39 +02:00
end
2021-03-24 16:46:00 +01:00
local y = string.sub ( str , y_pos , y_pos + a1 )
2020-06-28 14:40:39 +02:00
x = tonumber ( x )
y = tonumber ( y )
local position = { x = x , y = y }
return position
end
2019-10-20 11:48:14 +02:00
local function on_gui_click ( event )
2021-03-25 23:49:57 +01:00
local element = event.element
if not element or not element.valid then
2020-06-28 14:40:39 +02:00
return
end
2021-03-25 23:49:57 +01:00
local player = game.get_player ( event.player_index )
2020-06-29 15:50:01 +02:00
2021-03-25 23:49:57 +01:00
local name = event.element . name
2022-04-05 19:28:08 +02:00
local frame = Gui.get_player_active_frame ( player )
2021-03-25 23:49:57 +01:00
if not frame then
return
end
2020-06-28 14:40:39 +02:00
2022-04-05 19:28:08 +02:00
if frame.name ~= ' Admin ' then
2020-06-29 15:50:01 +02:00
return
end
2022-04-05 19:28:08 +02:00
if name == ' mini_camera ' or name == ' mini_cam_element ' then
player.gui . center [ ' mini_camera ' ] . destroy ( )
2020-06-29 15:50:01 +02:00
return
end
2021-01-12 21:52:45 +01:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Gui Click ' )
2020-12-14 19:36:37 +01:00
if is_spamming then
return
end
2020-06-28 14:40:39 +02:00
if admin_functions [ name ] then
local target_player_name = frame [ ' admin_player_select ' ] . items [ frame [ ' admin_player_select ' ] . selected_index ]
if not target_player_name then
return
end
if target_player_name == ' Select Player ' then
2022-04-18 01:18:06 +02:00
player.print ( ' [AdminGui] No target player selected. ' , { r = 0.88 , g = 0.88 , b = 0.88 } )
2020-06-28 14:40:39 +02:00
return
end
local target_player = game.players [ target_player_name ]
if target_player.connected == true then
admin_functions [ name ] ( target_player , player )
end
return
end
if admin_global_functions [ name ] then
admin_global_functions [ name ] ( player )
return
end
if not frame then
return
end
2021-03-25 23:49:57 +01:00
if not element.caption then
2020-06-28 14:40:39 +02:00
return
end
2021-03-25 23:49:57 +01:00
local position = get_position_from_string ( element.caption )
2020-06-28 14:40:39 +02:00
if not position then
return
end
2021-03-25 23:49:57 +01:00
local surface = get_surface_from_string ( element.caption )
2020-06-29 15:50:01 +02:00
if not surface then
return
end
2020-06-28 14:40:39 +02:00
if player.gui . center [ ' mini_camera ' ] then
2021-03-25 23:49:57 +01:00
if player.gui . center [ ' mini_camera ' ] . caption == element.caption then
2020-06-28 14:40:39 +02:00
player.gui . center [ ' mini_camera ' ] . destroy ( )
return
end
end
2021-03-25 23:49:57 +01:00
create_mini_camera_gui ( player , element.caption , position , surface )
2019-10-20 11:48:14 +02:00
end
local function on_gui_selection_state_changed ( event )
2021-12-05 22:26:18 +01:00
local player = game.get_player ( event.player_index )
2020-06-28 14:40:39 +02:00
local name = event.element . name
2019-10-20 11:48:14 +02:00
2020-06-28 14:40:39 +02:00
if name == ' admin_history_select ' then
2024-01-28 23:13:32 +01:00
this.admin_panel_selected_history_index [ player.name ] = event.element . selected_index
2019-10-20 11:48:14 +02:00
2022-04-05 19:28:08 +02:00
local frame = Gui.get_player_active_frame ( player )
2020-06-28 14:40:39 +02:00
if not frame then
return
end
2022-04-05 19:28:08 +02:00
if frame.name ~= ' Admin ' then
2020-06-28 14:40:39 +02:00
return
end
2024-01-28 23:13:32 +01:00
this.admin_panel_paginator_selected_page [ player.name ] = 1
2021-01-12 21:52:45 +01:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Selection Changed ' )
2020-12-14 19:36:37 +01:00
if is_spamming then
return
end
2021-03-25 23:49:57 +01:00
local data = { player = player , frame = frame }
create_admin_panel ( data )
2020-06-29 15:50:01 +02:00
end
if name == ' admin_player_select ' then
2024-01-28 23:13:32 +01:00
this.admin_panel_selected_player_index [ player.name ] = event.element . selected_index
2020-06-29 15:50:01 +02:00
2022-04-05 19:28:08 +02:00
local frame = Gui.get_player_active_frame ( player )
2020-06-29 15:50:01 +02:00
if not frame then
return
end
2022-04-05 19:28:08 +02:00
if frame.name ~= ' Admin ' then
2020-06-29 15:50:01 +02:00
return
end
2021-01-12 21:52:45 +01:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Player Select ' )
2020-12-14 19:36:37 +01:00
if is_spamming then
return
end
2021-03-25 23:49:57 +01:00
local data = { player = player , frame = frame }
create_admin_panel ( data )
2020-06-28 14:40:39 +02:00
end
end
2019-10-28 17:38:36 +01:00
2022-04-05 19:28:08 +02:00
Gui.add_tab_to_gui ( { name = module_name , caption = ' Admin ' , id = create_admin_panel_token , admin = true } )
Gui.on_click (
module_name ,
function ( event )
local player = event.player
Gui.reload_active_tab ( player )
end
)
2019-10-28 17:38:36 +01:00
2024-01-28 23:13:32 +01:00
function Public . contains_text ( history , search_text , target_player_name , callback , start_index , end_index )
2023-11-24 19:38:17 +01:00
local antigrief = AntiGrief.get ( )
local history_index = {
[ ' Capsule History ' ] = antigrief.capsule_history ,
[ ' Message History ' ] = antigrief.message_history ,
[ ' Friendly Fire History ' ] = antigrief.friendly_fire_history ,
[ ' Mining History ' ] = antigrief.mining_history ,
[ ' Mining Override History ' ] = antigrief.whitelist_mining_history ,
[ ' Landfill History ' ] = antigrief.landfill_history ,
[ ' Corpse Looting History ' ] = antigrief.corpse_history ,
[ ' Cancel Crafting History ' ] = antigrief.cancel_crafting_history ,
[ ' Deconstruct History ' ] = antigrief.deconstruct_history ,
[ ' Scenario History ' ] = antigrief.scenario_history
}
local tooltip = ' Click to open mini camera. '
local remote_tbl = { }
2024-01-09 21:57:10 +01:00
if game.get_player ( target_player_name ) ~= nil then
2023-11-24 19:38:17 +01:00
if not history_index or not history_index [ history ] or # history_index [ history ] <= 0 then
return
end
2024-01-28 23:13:32 +01:00
if start_index then
for i = start_index , end_index do
if history_index [ history ] [ i ] and history_index [ history ] [ i ] : find ( target_player_name ) then
if search_text then
local success = contains_text ( history_index [ history ] [ i ] , nil , search_text )
if not success then
goto continue
end
end
if callback then
if history == ' Message History ' then
tooltip = ' '
end
callback ( history_index [ history ] [ i ] , tooltip )
else
remote_tbl [ # remote_tbl + 1 ] = history_index [ history ] [ i ]
end
:: continue ::
end
end
else
for i = # history_index [ history ] , 1 , - 1 do
if history_index [ history ] [ i ] : find ( target_player_name ) then
if search_text then
local success = contains_text ( history_index [ history ] [ i ] , nil , search_text )
if not success then
goto continue
end
end
if callback then
if history == ' Message History ' then
tooltip = ' '
end
callback ( history_index [ history ] [ i ] , tooltip )
else
remote_tbl [ # remote_tbl + 1 ] = history_index [ history ] [ i ]
end
:: continue ::
end
end
end
else
if start_index then
for i = start_index , end_index do
2023-11-24 19:38:17 +01:00
if search_text then
local success = contains_text ( history_index [ history ] [ i ] , nil , search_text )
if not success then
goto continue
end
end
if callback then
callback ( history_index [ history ] [ i ] , tooltip )
else
2024-01-28 23:13:32 +01:00
remote_tbl [ # remote_tbl + 1 ] = history_index [ history ] [ i ]
2023-11-24 19:38:17 +01:00
end
:: continue ::
end
2024-01-28 23:13:32 +01:00
else
for i = # history_index [ history ] , 1 , - 1 do
if search_text then
local success = contains_text ( history_index [ history ] [ i ] , nil , search_text )
if not success then
goto continue
end
2023-11-24 19:38:17 +01:00
end
2024-01-28 23:13:32 +01:00
if callback then
callback ( history_index [ history ] [ i ] , tooltip )
else
remote_tbl [ # remote_tbl + 1 ] = history_index [ history ] [ i ]
end
2023-11-24 19:38:17 +01:00
2024-01-28 23:13:32 +01:00
:: continue ::
end
2023-11-24 19:38:17 +01:00
end
end
if not callback then
return remote_tbl
end
end
2024-01-28 23:13:32 +01:00
Gui.on_click (
prev_button_name ,
function ( event )
local is_spamming = SpamProtection.is_spamming ( event.player , nil , ' Prev button click ' )
if is_spamming then
return
end
local player = event.player
if not player or not player.valid or not player.character then
return
end
local element = event.element
if not element or not element.valid then
return
end
if not this.admin_panel_paginator_selected_page [ player.name ] then
this.admin_panel_paginator_selected_page [ player.name ] = 1
end
local current_page = this.admin_panel_paginator_selected_page [ player.name ]
if current_page == 1 then
current_page = 1
this.admin_panel_paginator_selected_page [ player.name ] = current_page
player.print ( ' [Admin] There are no more pages beyond this point. ' , Color.warning )
return
end
local shift = event.shift
if shift then
current_page = 1
else
current_page = max ( 1 , current_page - 1 )
end
this.admin_panel_paginator_selected_page [ player.name ] = current_page
local data = { player = player , frame = element.parent . parent.parent }
create_admin_panel ( data )
end
)
Gui.on_click (
next_button_name ,
function ( event )
local is_spamming = SpamProtection.is_spamming ( event.player , nil , ' Next button click ' )
if is_spamming then
return
end
local element = event.element
if not element or not element.valid then
return
end
local player = event.player
if not player or not player.valid then
Gui.remove_data_recursively ( element )
return
end
local element_indices = Gui.get_data ( element )
if not element_indices then
Gui.remove_data_recursively ( element )
return
end
if not this.admin_panel_paginator_selected_page [ player.name ] then
this.admin_panel_paginator_selected_page [ player.name ] = 1
end
local current_page = this.admin_panel_paginator_selected_page [ player.name ]
local last_page = ceil ( element_indices / rows_per_page )
if current_page == last_page then
current_page = last_page
this.admin_panel_paginator_selected_page [ player.name ] = current_page
Gui.remove_data_recursively ( element )
player.print ( ' [Admin] There are no more pages beyond this point. ' , Color.warning )
return
end
local shift = event.shift
if shift then
current_page = last_page
else
current_page = min ( last_page , current_page + 1 )
end
this.admin_panel_paginator_selected_page [ player.name ] = current_page
Gui.remove_data_recursively ( element )
local data = { player = player , frame = element.parent . parent.parent }
create_admin_panel ( data )
end
)
2024-01-29 08:06:24 +01:00
Gui.on_checked_state_changed (
listable_players_name ,
function ( event )
local is_spamming = SpamProtection.is_spamming ( event.player , nil , ' Listable players click ' )
if is_spamming then
return
end
local player = event.player
if not player or not player.valid then
return
end
local element = event.element
if not element or not element.valid then
return
end
this.admin_panel_listable_players_index [ player.name ] = element.state
local data = { player = player , frame = element.parent }
create_admin_panel ( data )
end
)
2020-07-01 19:35:38 +02:00
Event.add ( defines.events . on_gui_text_changed , text_changed )
Event.add ( defines.events . on_gui_click , on_gui_click )
Event.add ( defines.events . on_gui_selection_state_changed , on_gui_selection_state_changed )
2023-11-24 19:38:17 +01:00
return Public