mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 19:45:22 +09:00
Added compi :D
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
[chat-popup]
|
||||
message=__1__: __2__
|
||||
ping=You have been mentioned in chat by __1__.
|
||||
|
||||
[damage-popup]
|
||||
player-health=__1__
|
||||
player-damage=__1__
|
||||
100
modules/addons/compilatron.lua
Normal file
100
modules/addons/compilatron.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Game = require 'utils.game'
|
||||
local Task = require 'utils.task'
|
||||
local Token = require 'utils.token'
|
||||
local config = require 'config.compilatron'
|
||||
local messages = config.messages
|
||||
local locations = config.locations
|
||||
|
||||
local compilatrons = {}
|
||||
local current_messages = {}
|
||||
Global.register(
|
||||
{
|
||||
compilatrons = compilatrons,
|
||||
current_messages = current_messages
|
||||
},
|
||||
function(tbl)
|
||||
compilatrons = tbl.compilatrons
|
||||
current_messages = tbl.current_messages
|
||||
end
|
||||
)
|
||||
|
||||
--- This will re-create the speech bubble after it de-spawns called with set_timeout
|
||||
local callback =
|
||||
Token.register(
|
||||
function(data)
|
||||
local ent = data.ent
|
||||
local name = data.name
|
||||
local msg_number = data.msg_number
|
||||
local message =
|
||||
ent.surface.create_entity(
|
||||
{name = 'compi-speech-bubble', text = messages[name][msg_number], position = {0, 0}, source = ent}
|
||||
)
|
||||
current_messages[name] = {message = message, msg_number = msg_number}
|
||||
end
|
||||
)
|
||||
|
||||
--- This will move the messages onto the next message in the loop
|
||||
local function circle_messages()
|
||||
for name, ent in pairs(compilatrons) do
|
||||
local current_message = current_messages[name]
|
||||
local msg_number
|
||||
local message
|
||||
if current_message ~= nil then
|
||||
message = current_message.message
|
||||
if message ~= nil then
|
||||
message.destroy()
|
||||
end
|
||||
msg_number = current_message.msg_number
|
||||
msg_number = (msg_number < #messages[name]) and msg_number + 1 or 1
|
||||
else
|
||||
msg_number = 1
|
||||
end
|
||||
-- this calls the callback above to re-spawn the message after some time
|
||||
Task.set_timeout_in_ticks(300, callback, {ent = ent, name = name, msg_number = msg_number})
|
||||
end
|
||||
end
|
||||
|
||||
Event.on_nth_tick(config.message_cycle, circle_messages)
|
||||
|
||||
local Public = {}
|
||||
|
||||
--- This will add a compilatron to the global and start his message cycle
|
||||
-- @tparam entity LuaEntity the compilatron entity that moves around
|
||||
-- @tparam name string the name of the location that the complitron is at
|
||||
function Public.add_compilatron(entity, name)
|
||||
if not entity and not entity.valid then
|
||||
return
|
||||
end
|
||||
if name == nil then
|
||||
return
|
||||
end
|
||||
compilatrons[name] = entity
|
||||
local message =
|
||||
entity.surface.create_entity(
|
||||
{name = 'compi-speech-bubble', text = messages[name][1], position = {0, 0}, source = entity}
|
||||
)
|
||||
current_messages[name] = {message = message, msg_number = 1}
|
||||
end
|
||||
|
||||
--- This spawns a new compilatron on a surface with the given location tag (not a position)
|
||||
-- @tparam surface LuaSurface the surface to spawn the compilatron on
|
||||
-- @tparam location string the location tag that is in the config file
|
||||
function Public.spawn_compilatron(surface,location)
|
||||
local position = locations[location]
|
||||
local pos = surface.find_non_colliding_position('compilatron', position, 1.5, 0.5)
|
||||
local compi = surface.create_entity {name='compilatron',position=pos,force=game.forces.neutral}
|
||||
Public.add_compilatron(compi,location)
|
||||
end
|
||||
|
||||
-- When the first player is created this will create all comilatrons that are resisted in the config
|
||||
Event.add(defines.events.on_player_created,function(event)
|
||||
if not event.player_index == 1 then return end
|
||||
local player = Game.get_player_by_index(event.player_index)
|
||||
for location,pos in pairs(locations) do
|
||||
Public.spawn_compilatron(player.surface,location)
|
||||
end
|
||||
end)
|
||||
|
||||
return Public
|
||||
@@ -1,10 +0,0 @@
|
||||
[exp-commands]
|
||||
kill-already-dead=You are already dead.
|
||||
admin-chat-format=[Admin Chat] [color=__3__]__1__: __2__
|
||||
tp-no-position-found=No position to teleport to was found, please try again later.
|
||||
tp-to-self=Player can not be teleported to themselves.
|
||||
chelp-title=Help results for "__1__":
|
||||
chelp-footer=(__1__ results found; page __2__ of __3__)
|
||||
chelp-format=/__1__ __2__ - __3__ __4__
|
||||
chelp-alias=Alias: __1__
|
||||
chelp-out-of-range=__1__ is an invalid page number.
|
||||
Reference in New Issue
Block a user