diff --git a/modules/rpg/test.lua b/modules/rpg/test.lua new file mode 100644 index 00000000..948303bb --- /dev/null +++ b/modules/rpg/test.lua @@ -0,0 +1,92 @@ +local states = { + ['attack'] = 'nuclear-smoke', + ['support'] = 'poison-capsule-smoke' +} + +local Task = require 'utils.task' +local Token = require 'utils.token' + +local smokes = { + 'artillery-smoke', + 'car-smoke', + 'fire-smoke', + 'fire-smoke-on-adding-fuel', + 'fire-smoke-without-glow', + 'light-smoke', + 'nuclear-smoke', + 'poison-capsule-particle-smoke', + 'poison-capsule-smoke', + 'smoke', + 'smoke-building', + 'smoke-explosion-lower-particle-small', + 'smoke-explosion-particle', + 'smoke-explosion-particle-small', + 'smoke-explosion-particle-stone-small', + 'smoke-explosion-particle-tiny', + 'smoke-fast', + 'smoke-train-stop', + 'soft-fire-smoke', + 'tank-smoke', + 'train-smoke', + 'turbine-smoke' +} + +local function get_area(pos, dist) + local area = { + left_top = { + x = pos.x - dist, + y = pos.y - dist + }, + right_bottom = { + x = pos.x + dist, + y = pos.y + dist + } + } + return area +end + +local do_something_token = + Token.register( + function(event) + local cs = event.cs + local smoke = event.smoke + local p = event.p + cs.create_trivial_smoke({name = smoke, position = p}) + game.print(smoke) + end +) + +local function area_of_effect(player, state, radius) + if not radius then + return + end + + local cs = player.surface + local cp = player.position + + if radius and radius > 256 then + radius = 256 + end + + local area = get_area(cp, radius) + + if not states[state] then + return + end + + for x = area.left_top.x, area.right_bottom.x, 1 do + for y = area.left_top.y, area.right_bottom.y, 1 do + local d = math.floor((cp.x - x) ^ 2 + (cp.y - y) ^ 2) + if d < radius then + local p = {x = x, y = y} + local c = 10 + for _, smoke in pairs(smokes) do + c = c + 200 + Task.set_timeout_in_ticks(c, do_something_token, {cs = cs, smoke = smoke, p = p}) + end + end + end + end +end + +area_of_effect(game.player, 'attack', 32) diff --git a/utils/commands/where.lua b/utils/commands/where.lua index 810b2d9e..2577715b 100644 --- a/utils/commands/where.lua +++ b/utils/commands/where.lua @@ -54,13 +54,7 @@ local function validate_player(player) if not player.valid then return false end - if not player.character then - return false - end - if not player.connected then - return false - end - if not game.players[player.index] then + if player.admin then return false end return true @@ -77,30 +71,31 @@ local function validate_frame(frame) return true end -local function create_mini_camera_gui(player, caption, position, surface) +local function create_mini_camera_gui(player, target) + if not player or not player.valid then + return + end + if player.gui.center[locate_player_frame_name] then player.gui.center[locate_player_frame_name].destroy() remove_player_data(player) return end - local target_player = game.players[caption] - - if validate_player(target_player) then + if validate_player(target) then local player_data = create_player_data(player) - player_data.target_player = target_player + player_data.target = target else remove_player_data(player) - player.print('[Where] Please type a name of a player who is connected.', Color.warning) return end local frame = player.gui.center[locate_player_frame_name] if not validate_frame(frame) then - frame = player.gui.center.add({type = 'frame', name = locate_player_frame_name, caption = caption}) + frame = player.gui.center.add({type = 'frame', name = locate_player_frame_name, caption = target.name}) end - surface = tonumber(surface) + local surface = tonumber(target.surface.index) if frame[player_frame_name] and frame[player_frame_name].valid then frame[player_frame_name].destroy() @@ -111,7 +106,7 @@ local function create_mini_camera_gui(player, caption, position, surface) { type = 'camera', name = player_frame_name, - position = position, + position = target.position, zoom = 0.4, surface_index = surface } @@ -132,12 +127,13 @@ commands.add_command( if not cmd.parameter then return end - local target_player = game.players[cmd.parameter] + + local target_player = game.get_player(cmd.parameter) if validate_player(target_player) then local player_data = create_player_data(player) player_data.target_player = target_player - create_mini_camera_gui(player, target_player.name, target_player.position, target_player.surface.index) + create_mini_camera_gui(player, target_player) else remove_player_data(player) player.print('[Where] Please type a name of a player who is connected.', Color.warning) diff --git a/utils/gui/player_list.lua b/utils/gui/player_list.lua index 7522aed3..39d57f0e 100644 --- a/utils/gui/player_list.lua +++ b/utils/gui/player_list.lua @@ -635,7 +635,7 @@ local function player_list_show(data) if game.players[player_list[i].name].admin then trusted = '[color=red][A][/color]' .. trusted - tooltip = 'This player is an admin of this server.' .. minimap .. tooltip + tooltip = 'This player is an admin of this server.' .. tooltip elseif jailed[player_list[i].name] then trusted = '[color=orange][J][/color]' .. trusted tooltip = 'This player is currently jailed.' .. minimap .. tooltip @@ -857,16 +857,16 @@ local function on_gui_click(event) end --Locate other players local index = tonumber(element.name) - if index and game.players[index] and index == game.players[index].index then + if index and game.get_player(index) and index == game.get_player(index).index then local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList Locate Player') if is_spamming then return end - local target = game.players[index] + local target = game.get_player(index) if not target or not target.valid then return end - Where.create_mini_camera_gui(player, target.name, target.position, target.surface.index) + Where.create_mini_camera_gui(player, target) end --Poke other players if string.sub(element.name, 1, 11) == 'poke_player' then diff --git a/utils/gui/poll.lua b/utils/gui/poll.lua index 704a0158..6d0c507d 100644 --- a/utils/gui/poll.lua +++ b/utils/gui/poll.lua @@ -636,6 +636,10 @@ local function create_poll(event) local player = event.player local data = Gui.get_data(event.element) + if not data then + return + end + local frame = data.frame local question = data.question