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 '
2019-10-28 18:38:36 +02:00
local Tabs = require ' comfy_panel.main '
2020-06-29 15:50:01 +02:00
local AntiGrief = require ' antigrief '
2020-12-14 20:36:37 +02:00
local SpamProtection = require ' utils.spam_protection '
2019-10-20 11:48:14 +02:00
2020-07-01 19:35:38 +02:00
local lower = string.lower
2019-10-20 11:48:14 +02:00
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 )
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-07-07 23:42:44 +02:00
Jailed.try_ul_data ( player.name , true , source_player.name )
2019-10-20 11:48:14 +02:00
end
local function free ( 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-07-07 23:42:44 +02:00
Jailed.try_ul_data ( player.name , false , source_player.name )
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 )
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.driving == true then
source_player.print ( ' Target player is in a vehicle, teleport not available. ' , { r = 0.88 , g = 0.88 , b = 0.88 } )
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 )
game.print (
2020-12-14 20:36:37 +02:00
player.name .. ' has been teleported to ' .. source_player.name .. ' . ' .. bring_player_messages [ math.random ( 1 , # bring_player_messages ) ] ,
2020-06-28 14:40:39 +02:00
{ r = 0.98 , g = 0.66 , b = 0.22 }
)
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 )
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
local pos = player.surface . find_non_colliding_position ( ' character ' , player.position , 50 , 1 )
if pos then
source_player.teleport ( pos , player.surface )
2020-12-14 20:36:37 +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 } )
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 20:36:37 +02: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 )
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
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 )
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 )
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 not game.forces . enemy_players then
game.create_force ( ' enemy_players ' )
end
player.force = game.forces . enemy_players
2020-12-14 20:36:37 +02: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 ' )
2019-10-20 11:48:14 +02:00
end
local function ally ( 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
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 ' )
2019-10-20 11:48:14 +02:00
end
2019-10-20 12:52:19 +02:00
local function turn_off_global_speakers ( player )
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 ' } )
for i , speaker in pairs ( speakers ) do
if speaker.parameters . playback_globally == true then
speaker.surface . create_entity ( { name = ' massive-explosion ' , position = speaker.position } )
speaker.die ( ' player ' )
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
2019-10-20 11:48:14 +02:00
end
2019-10-20 12:52:19 +02:00
local function delete_all_blueprints ( player )
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
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. ' )
2019-10-20 11:48:14 +02:00
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 )
2020-06-28 14:40:39 +02:00
local camera =
frame.add (
{
type = ' camera ' ,
name = ' mini_cam_element ' ,
position = position ,
zoom = 0.6 ,
2020-06-29 15:50:01 +02:00
surface_index = game.surfaces [ 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
local antigrief = data.antigrief
local search_text = data.search_text or nil
local history = frame [ ' admin_history_select ' ] . items [ frame [ ' admin_history_select ' ] . selected_index ]
local history_index = {
[ ' Capsule History ' ] = antigrief.capsule_history ,
[ ' Friendly Fire History ' ] = antigrief.friendly_fire_history ,
[ ' Mining History ' ] = antigrief.mining_history ,
[ ' Landfill History ' ] = antigrief.landfill_history ,
2020-07-06 23:22:03 +02:00
[ ' Corpse Looting History ' ] = antigrief.corpse_history ,
[ ' Cancel Crafting History ' ] = antigrief.cancel_crafting_history
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 ]
if game.players [ target_player_name ] then
2020-07-28 16:48:55 +02:00
if not history_index or not history_index [ history ] or # history_index [ history ] <= 0 then
2020-07-10 16:08:50 +02:00
return
end
2020-07-30 19:09:18 +02:00
for i = # history_index [ history ] , 1 , - 1 do
if history_index [ history ] [ i ] : find ( target_player_name ) then
2020-07-30 17:47:50 +02:00
if search_text then
2020-07-30 19:09:18 +02:00
local success = contains_text ( history_index [ history ] [ i ] , nil , search_text )
2020-07-30 17:47:50 +02:00
if not success then
goto continue
end
2020-07-07 23:42:44 +02:00
end
2020-07-07 16:30:32 +02:00
2020-07-30 17:47:50 +02:00
frame.datalog . add (
{
type = ' label ' ,
2020-07-30 19:09:18 +02:00
caption = history_index [ history ] [ i ] ,
2020-07-30 17:47:50 +02:00
tooltip = ' Click to open mini camera. '
}
)
:: continue ::
end
2020-07-07 23:42:44 +02:00
end
else
2020-07-30 19:09:18 +02:00
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
2020-07-01 19:35:38 +02:00
end
end
2020-07-30 19:09:18 +02:00
frame.datalog . add (
{
type = ' label ' ,
caption = history_index [ history ] [ i ] ,
tooltip = ' Click to open mini camera. '
}
)
:: continue ::
2020-07-01 19:35:38 +02:00
end
end
end
local function text_changed ( event )
local element = event.element
if not element then
return
end
if not element.valid then
return
end
local antigrief = AntiGrief.get ( )
local player = game.players [ event.player_index ]
local frame = Tabs.comfy_panel_get_active_frame ( player )
if not frame then
return
end
if frame.name ~= ' Admin ' then
return
end
2021-01-12 22:52:45 +02:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Text Changed ' )
2020-12-14 20:36:37 +02:00
if is_spamming then
return
end
2020-07-01 19:35:38 +02:00
local data = {
frame = frame ,
antigrief = antigrief ,
search_text = element.text
}
draw_events ( data )
end
2020-06-28 14:40:39 +02:00
local create_admin_panel = ( function ( player , frame )
2020-06-29 15:50:01 +02:00
local antigrief = AntiGrief.get ( )
2020-06-28 14:40:39 +02:00
frame.clear ( )
local player_names = { }
for _ , p in pairs ( game.connected_players ) do
table.insert ( player_names , tostring ( p.name ) )
end
table.insert ( player_names , ' Select Player ' )
local selected_index = # player_names
if global.admin_panel_selected_player_index then
if global.admin_panel_selected_player_index [ player.name ] then
if player_names [ global.admin_panel_selected_player_index [ player.name ] ] then
selected_index = global.admin_panel_selected_player_index [ player.name ]
end
end
end
2020-12-14 20:36:37 +02: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
local t = frame.add ( { type = ' table ' , column_count = 3 } )
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. '
}
) ,
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 ' ,
tooltip = ' Sets the selected players force to enemy_players. DO NOT USE IN PVP MAPS!! '
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Make Ally ' ,
name = ' ally ' ,
tooltip = ' Sets the selected players force back to the default player force. DO NOT USE IN PVP MAPS!! '
}
) ,
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 ' ,
tooltip = ' Hurts the selected player with minor damage. Can not kill the player. '
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Damage ' ,
name = ' damage ' ,
tooltip = ' Damages the selected player with greater damage. Can not kill the player. '
}
) ,
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 . font_color = { r = 0.99 , g = 0.99 , b = 0.99 }
button.style . minimal_width = 106
end
local line = frame.add { type = ' line ' }
line.style . top_margin = 8
line.style . bottom_margin = 8
local l = frame.add ( { type = ' label ' , caption = ' Global Actions: ' } )
local t = frame.add ( { type = ' table ' , column_count = 2 } )
local buttons = {
t.add (
{
type = ' button ' ,
caption = ' Destroy global speakers ' ,
name = ' turn_off_global_speakers ' ,
tooltip = ' Destroys all speakers that are set to play sounds globally. '
}
) ,
t.add (
{
type = ' button ' ,
caption = ' Delete blueprints ' ,
name = ' delete_all_blueprints ' ,
tooltip = ' Deletes all placed blueprints on the map. '
}
)
--- t.add({type = "button", caption = "Cancel all deconstruction orders", name = "remove_all_deconstruction_orders"})
}
for _ , button in pairs ( buttons ) do
button.style . font = ' default-bold '
button.style . font_color = { r = 0.98 , g = 0.66 , b = 0.22 }
button.style . minimal_width = 80
end
local line = frame.add { type = ' line ' }
line.style . top_margin = 8
line.style . bottom_margin = 8
local histories = { }
2020-06-29 15:50:01 +02:00
if antigrief.capsule_history then
table.insert ( histories , ' Capsule History ' )
2020-06-28 14:40:39 +02:00
end
2020-06-29 15:50:01 +02:00
if antigrief.friendly_fire_history then
2020-06-28 14:40:39 +02:00
table.insert ( histories , ' Friendly Fire History ' )
end
2020-06-29 15:50:01 +02:00
if antigrief.mining_history then
2020-06-28 14:40:39 +02:00
table.insert ( histories , ' Mining History ' )
end
2020-06-29 15:50:01 +02:00
if antigrief.landfill_history then
2020-06-28 14:40:39 +02:00
table.insert ( histories , ' Landfill History ' )
end
2020-06-29 15:50:01 +02:00
if antigrief.corpse_history then
table.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
table.insert ( histories , ' Cancel Crafting History ' )
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
2020-06-28 14:40:39 +02:00
local l = frame.add ( { type = ' label ' , caption = ' ---------------------------------------------- ' } )
2020-07-01 19:35:38 +02:00
l.style . font = ' default-listbox '
l.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
2020-06-28 14:40:39 +02:00
if global.admin_panel_selected_history_index then
if global.admin_panel_selected_history_index [ player.name ] then
2020-06-29 15:50:01 +02:00
selected_index_2 = global.admin_panel_selected_history_index [ player.name ]
2020-06-28 14:40:39 +02:00
end
end
2020-12-14 20:36:37 +02:00
local drop_down_2 = frame.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
2020-07-01 19:35:38 +02:00
local data = {
frame = frame ,
antigrief = antigrief
2020-06-28 14:40:39 +02:00
}
2019-10-20 11:48:14 +02:00
2020-07-01 19:35:38 +02:00
draw_events ( data )
2019-10-28 18:38:36 +02:00
end )
2019-10-20 11:48:14 +02:00
local admin_functions = {
2020-06-28 14:40:39 +02:00
[ ' jail ' ] = jail ,
[ ' 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 ,
[ ' delete_all_blueprints ' ] = delete_all_blueprints
}
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 )
local a = 1
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
a = a + 1
end
local y = string.sub ( str , y_pos , y_pos + a )
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 )
2020-06-28 14:40:39 +02:00
local player = game.players [ event.player_index ]
2020-12-14 20:36:37 +02:00
2020-06-28 14:40:39 +02:00
local frame = Tabs.comfy_panel_get_active_frame ( player )
if not frame then
return
end
2020-06-29 15:50:01 +02:00
if not event.element . valid then
2020-06-28 14:40:39 +02:00
return
end
local name = event.element . name
2020-06-29 15:50:01 +02:00
if name == ' mini_camera ' or name == ' mini_cam_element ' then
player.gui . center [ ' mini_camera ' ] . destroy ( )
return
end
if frame.name ~= ' Admin ' then
return
end
2021-01-12 22:52:45 +02:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Gui Click ' )
2020-12-14 20:36:37 +02: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
player.print ( ' No target player selected. ' , { r = 0.88 , g = 0.88 , b = 0.88 } )
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
if not event.element . caption then
return
end
local position = get_position_from_string ( event.element . caption )
if not position then
return
end
2020-06-29 15:50:01 +02:00
local surface = get_surface_from_string ( event.element . caption )
if not surface then
return
end
2020-06-28 14:40:39 +02:00
if player.gui . center [ ' mini_camera ' ] then
if player.gui . center [ ' mini_camera ' ] . caption == event.element . caption then
player.gui . center [ ' mini_camera ' ] . destroy ( )
return
end
end
2020-06-29 15:50:01 +02:00
create_mini_camera_gui ( player , event.element . caption , position , surface )
2019-10-20 11:48:14 +02:00
end
local function on_gui_selection_state_changed ( event )
2020-06-28 14:40:39 +02:00
local player = game.players [ event.player_index ]
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
if not global.admin_panel_selected_history_index then
global.admin_panel_selected_history_index = { }
end
global.admin_panel_selected_history_index [ player.name ] = event.element . selected_index
2019-10-20 11:48:14 +02:00
2020-06-28 14:40:39 +02:00
local frame = Tabs.comfy_panel_get_active_frame ( player )
if not frame then
return
end
if frame.name ~= ' Admin ' then
return
end
2021-01-12 22:52:45 +02:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Selection Changed ' )
2020-12-14 20:36:37 +02:00
if is_spamming then
return
end
2020-06-29 15:50:01 +02:00
create_admin_panel ( player , frame )
end
if name == ' admin_player_select ' then
if not global.admin_panel_selected_player_index then
global.admin_panel_selected_player_index = { }
end
global.admin_panel_selected_player_index [ player.name ] = event.element . selected_index
local frame = Tabs.comfy_panel_get_active_frame ( player )
if not frame then
return
end
if frame.name ~= ' Admin ' then
return
end
2021-01-12 22:52:45 +02:00
local is_spamming = SpamProtection.is_spamming ( player , nil , ' Admin Player Select ' )
2020-12-14 20:36:37 +02:00
if is_spamming then
return
end
2020-06-28 14:40:39 +02:00
create_admin_panel ( player , frame )
end
end
2019-10-28 18:38:36 +02:00
2020-06-28 14:40:39 +02:00
comfy_panel_tabs [ ' Admin ' ] = { gui = create_admin_panel , admin = true }
2019-10-28 18:38:36 +02:00
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 )