mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-28 20:05:22 +09:00
Colours and sounds
This commit is contained in:
26
ExpLib.lua
26
ExpLib.lua
@@ -38,27 +38,21 @@ end
|
||||
-- player_return(a)
|
||||
-- @param rtn the value to return
|
||||
-- @param player the player to print to
|
||||
function ExpLib.player_return(rtn,player)
|
||||
function ExpLib.player_return(rtn,colour,player)
|
||||
local colour = colour or defines.color.white
|
||||
local player = player or game.player
|
||||
if player then
|
||||
local player = Game.get_player(player)
|
||||
if not player then return end
|
||||
player.play_sound{path='utility/scenario_message'}
|
||||
if is_type(rtn,'table') then
|
||||
-- test if its a localised string
|
||||
if is_type(rtn.__self,'userdata') then player.print('Cant Display Userdata')
|
||||
elseif is_type(rtn[1],'string') and string.find(rtn[1],'.+[.].+') and not string.find(rtn[1],'%s') then pcall(player.print,rtn)
|
||||
else player.print(table.to_string(rtn))
|
||||
if is_type(rtn.__self,'userdata') then player.print('Cant Display Userdata',colour)
|
||||
elseif is_type(rtn[1],'string') and string.find(rtn[1],'.+[.].+') and not string.find(rtn[1],'%s') then pcall(player.print,rtn,colour)
|
||||
else player.print(table.to_string(rtn),colour)
|
||||
end
|
||||
elseif is_type(rtn,'function') then player.print('Cant Display Functions')
|
||||
else player.print(tostring(rtn))
|
||||
end
|
||||
elseif game.player then
|
||||
if is_type(rtn,'table') then
|
||||
-- test if its a localised string
|
||||
if is_type(rtn.__self,'userdata') then player.print('Cant Display Userdata')
|
||||
elseif is_type(rtn[1],'string') and string.find(rtn[1],'.+[.].+') and not string.find(rtn[1],'%s') then pcall(game.player.print,rtn)
|
||||
else game.player.print(table.to_string(rtn))
|
||||
end
|
||||
elseif is_type(rtn,'function') then game.player.print('Cant Display Functions')
|
||||
else game.player.print(tostring(rtn))
|
||||
elseif is_type(rtn,'function') then player.print('Cant Display Functions',colour)
|
||||
else player.print(tostring(rtn),colour)
|
||||
end
|
||||
else
|
||||
if is_type(rtn,'table') then log(table.to_string(rtn))
|
||||
|
||||
@@ -82,7 +82,8 @@ local function run_custom_command(command)
|
||||
local player_name = Game.get_player(command) and Game.get_player(command).name or 'server'
|
||||
-- is the player allowed to use this command
|
||||
if is_type(Ranking,'table') and Ranking._presets and Ranking._presets().meta.rank_count > 0 and not Ranking.get_rank(player_name):allowed(command.name) then
|
||||
player_return{'commands.unauthorized'}
|
||||
player_return({'commands.unauthorized'},defines.text_color.crit)
|
||||
if game.player then game.player.play_sound{path='utility/cannot_build'} end
|
||||
game.write_file('commands.log','\n'..game.tick
|
||||
..' Player: '..player_name
|
||||
..' Failed to use command (Unauthorized): '..command.name
|
||||
@@ -93,7 +94,8 @@ local function run_custom_command(command)
|
||||
-- gets the args for the command
|
||||
local args, valid = command_args(command,command_data)
|
||||
if not valid then
|
||||
player_return{'commands.invalid-inputs',command.name,command_inputs(command_data)}
|
||||
player_return({'commands.invalid-inputs',command.name,command_inputs(command_data)},defines.text_color.high)
|
||||
if game.player then game.player.play_sound{path='utility/deconstruct_big'} end
|
||||
game.write_file('commands.log','\n'..game.tick
|
||||
..' Player: '..player_name
|
||||
..' Failed to use command (Invalid Args): '..command.name
|
||||
@@ -104,7 +106,7 @@ local function run_custom_command(command)
|
||||
-- runs the command
|
||||
local success, err = pcall(command_calls[command.name],event,args)
|
||||
if err then error(err) end
|
||||
player_return{'commands.command-ran'}
|
||||
player_return({'commands.command-ran'},defines.text_color.info)
|
||||
game.write_file('commands.log','\n'..game.tick
|
||||
..' Player: '..player_name
|
||||
..' Used command: '..command.name
|
||||
|
||||
@@ -83,16 +83,17 @@ end
|
||||
-- @param rank_base the rank that acts as the cut off point (rank is always included)
|
||||
-- @param rtn what do you want to return to the players
|
||||
-- @tparam bolean below if true rank below base are printed to
|
||||
function Ranking.print(rank_base,rtn,below)
|
||||
function Ranking.print(rank_base,rtn,colour,below)
|
||||
local colour = colour or defines.color.white
|
||||
local rank_base = Ranking.get_rank(rank_base)
|
||||
local ranks = Ranking._ranks()
|
||||
if below then
|
||||
for power,rank in pairs(ranks) do
|
||||
if rank_base.power >= power then rank:print(rtn) end
|
||||
if rank_base.power >= power then rank:print(rtn,colour) end
|
||||
end
|
||||
else
|
||||
for power,rank in pairs(ranks) do
|
||||
if rank_base.power <= power then rank:print(rtn) end
|
||||
if rank_base.power <= power then rank:print(rtn,colour) end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -104,18 +105,20 @@ end
|
||||
-- @param[opt='server'] by_player the player who is giving the rank
|
||||
-- @param[opt=game.tick] tick the tick that the rank is being given on
|
||||
function Ranking.give_rank(player,rank,by_player,tick)
|
||||
local print_colour = defines.text_color.info
|
||||
local tick = tick or game.tick
|
||||
local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or game.player and game.player.name or 'server'
|
||||
local rank = Ranking.get_rank(rank) or Ranking.get_rank(Ranking._presets().meta.default)
|
||||
local player = Game.get_player(player)
|
||||
local player = Game.get_player(player) or error('No Player To Give Rank')
|
||||
local old_rank = Ranking.get_rank(player) or Ranking.get_rank(Ranking._presets().meta.default)
|
||||
local message = 'ranking.rank-down'
|
||||
-- messaging
|
||||
if old_rank.name == rank.name then return end
|
||||
if rank.power < old_rank.power then message = 'ranking.rank-up' end
|
||||
game.print{message,player.name,rank.name,by_player_name}
|
||||
if rank.group.name ~= 'User' then player.print{'ranking.rank-given',rank.name} end
|
||||
if player.tag ~= old_rank.tag then player.print{'ranking.tag-reset'} end
|
||||
if rank.power < old_rank.power then message = 'ranking.rank-up' player.play_sound{path='utility/achievement_unlocked'}
|
||||
else player.play_sound{path='utility/game_lost'} end
|
||||
game.print({message,player.name,rank.name,by_player_name},print_colour)
|
||||
if rank.group.name ~= 'User' then player_return({'ranking.rank-given',rank.name},print_colour,player) end
|
||||
if player.tag ~= old_rank.tag then player_return({'ranking.tag-reset'},print_colour,player) end
|
||||
-- rank change
|
||||
player.permission_group = game.permissions.get_group(rank.name)
|
||||
player.tag = rank.tag
|
||||
@@ -194,15 +197,14 @@ end
|
||||
-- @tparam bolean online get only online players
|
||||
-- @treturn table a table of all players in this rank
|
||||
function Ranking._rank:get_players(online)
|
||||
local players = game.permissions.get_group(rank.name).players
|
||||
local _return = {}
|
||||
if online then
|
||||
for _,player in pairs(game.connected_players) do
|
||||
if Ranking.get_rank(player).name == self.name then table.insert(_return,player) end
|
||||
for _,player in pairs(players) do
|
||||
if player.connected then table.insert(_return,player) end
|
||||
end
|
||||
else
|
||||
for _,player in pairs(game.players) do
|
||||
if Ranking.get_rank(player).name == self.name then table.insert(_return,player) end
|
||||
end
|
||||
_return = players
|
||||
end
|
||||
return _return
|
||||
end
|
||||
@@ -210,10 +212,11 @@ end
|
||||
--- Print a message to all players of this rank
|
||||
-- @usage rank:print('foo')
|
||||
-- @param rtn any value you want to return
|
||||
function Ranking._rank:print(rtn)
|
||||
function Ranking._rank:print(rtn,colour)
|
||||
local colour = colour or defines.color.white
|
||||
if not Server or not Server._thread then
|
||||
for _,player in pairs(self:get_players()) do
|
||||
player_return(rtn,player)
|
||||
player_return(rtn,colour,player)
|
||||
end
|
||||
else
|
||||
-- using threads to make less lag
|
||||
@@ -223,7 +226,7 @@ function Ranking._rank:print(rtn)
|
||||
end)
|
||||
thread:on_event('success',function(thread,players)
|
||||
for _,player in pairs(players) do
|
||||
player_return(thread.data.rtn,player)
|
||||
player_return(thread.data.rtn,colour,player)
|
||||
end
|
||||
end)
|
||||
thread:queue()
|
||||
|
||||
@@ -51,7 +51,7 @@ http://lua-api.factorio.com/latest/defines.html#defines.input_action
|
||||
local root = Ranking._group:create{
|
||||
name='Root',
|
||||
allow={
|
||||
['server-interface'] = true
|
||||
['interface'] = true
|
||||
},
|
||||
disallow={}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user