mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 04:51:40 +09:00
Add ExpGaming Lib and ranks are in working condition
This commit is contained in:
37
control.lua
37
control.lua
@@ -22,40 +22,3 @@ credit_loop(require("locale/StdLib/event"))
|
|||||||
credit_loop(require("locale/file-header"))
|
credit_loop(require("locale/file-header"))
|
||||||
|
|
||||||
Event.register(-1,function() global.credits = credits end)
|
Event.register(-1,function() global.credits = credits end)
|
||||||
|
|
||||||
----TEMP-------------------------------------------------------------------------------------
|
|
||||||
function table.val_to_str ( v )
|
|
||||||
if "string" == type( v ) then
|
|
||||||
v = string.gsub( v, "\n", "\\n" )
|
|
||||||
if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
|
|
||||||
return "'" .. v .. "'"
|
|
||||||
end
|
|
||||||
return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
|
|
||||||
else
|
|
||||||
return "table" == type( v ) and table.tostring( v ) or
|
|
||||||
tostring( v )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function table.key_to_str ( k )
|
|
||||||
if "string" == type( k ) and string.match( k, "^[_%player][_%player%d]*$" ) then
|
|
||||||
return k
|
|
||||||
else
|
|
||||||
return "[" .. table.val_to_str( k ) .. "]"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function table.tostring( tbl )
|
|
||||||
local result, done = {}, {}
|
|
||||||
for k, v in ipairs( tbl ) do
|
|
||||||
table.insert( result, table.val_to_str( v ) )
|
|
||||||
done[ k ] = true
|
|
||||||
end
|
|
||||||
for k, v in pairs( tbl ) do
|
|
||||||
if not done[ k ] then
|
|
||||||
table.insert( result,
|
|
||||||
table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return "{" .. table.concat( result, "," ) .. "}"
|
|
||||||
end
|
|
||||||
68
locale/ExpGaming-Core/ExpGaming - Lib.lua
Normal file
68
locale/ExpGaming-Core/ExpGaming - Lib.lua
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
--[[
|
||||||
|
Explosive Gaming
|
||||||
|
|
||||||
|
This file can be used with permission but this and the credit below must remain in the file.
|
||||||
|
Contact a member of management on our discord to seek permission to use our code.
|
||||||
|
Any changes that you may make to the code are yours but that does not make the script yours.
|
||||||
|
Discord: https://discord.gg/XSsBV6b
|
||||||
|
|
||||||
|
The credit below may be used by another script do not remove.
|
||||||
|
]]
|
||||||
|
local credits = {{
|
||||||
|
name='ExpGaming - Lib',
|
||||||
|
owner='Explosive Gaming',
|
||||||
|
dev='Cooldude2606',
|
||||||
|
description='A few basic functions used by scripts',
|
||||||
|
factorio_version='0.15.23',
|
||||||
|
show=false
|
||||||
|
}}
|
||||||
|
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
||||||
|
--Please Only Edit Below This Line-----------------------------------------------------------
|
||||||
|
--this will convert ticks into hours based on game speed
|
||||||
|
function tick_to_hour (tick)
|
||||||
|
local hour = tostring(math.floor(tick/(216000*game.speed)))
|
||||||
|
return hour
|
||||||
|
end
|
||||||
|
--this will convert ticks into minutes based on game speed
|
||||||
|
function tick_to_min (tick)
|
||||||
|
local minutes = math.floor(tick/(3600*game.speed))
|
||||||
|
return minutes
|
||||||
|
end
|
||||||
|
--i stole this from somewhere a long time ago but this and the other two functions convert a table into a string
|
||||||
|
function table.val_to_str ( v )
|
||||||
|
if "string" == type( v ) then
|
||||||
|
v = string.gsub( v, "\n", "\\n" )
|
||||||
|
if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
|
||||||
|
return "'" .. v .. "'"
|
||||||
|
end
|
||||||
|
return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
|
||||||
|
else
|
||||||
|
return "table" == type( v ) and table.to_string( v ) or
|
||||||
|
tostring( v )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function table.key_to_str ( k )
|
||||||
|
if "string" == type( k ) and string.match( k, "^[_%player][_%player%d]*$" ) then
|
||||||
|
return k
|
||||||
|
else
|
||||||
|
return "[" .. table.val_to_str( k ) .. "]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function table.to_string( tbl )
|
||||||
|
local result, done = {}, {}
|
||||||
|
for k, v in ipairs( tbl ) do
|
||||||
|
table.insert( result, table.val_to_str( v ) )
|
||||||
|
done[ k ] = true
|
||||||
|
end
|
||||||
|
for k, v in pairs( tbl ) do
|
||||||
|
if not done[ k ] then
|
||||||
|
table.insert( result,
|
||||||
|
table.key_to_str( k ) .. "=" .. table.val_to_str( v ) )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return "{" .. table.concat( result, "," ) .. "}"
|
||||||
|
end
|
||||||
|
--Please Only Edit Above This Line-----------------------------------------------------------
|
||||||
|
return credits
|
||||||
@@ -18,17 +18,17 @@ local credits = {{
|
|||||||
}}
|
}}
|
||||||
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
||||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
--Please Only Edit Below This Line-----------------------------------------------------------
|
||||||
|
--this will return the rank of the player given
|
||||||
local function get_rank(player)
|
function get_rank(player)
|
||||||
if player then
|
if player then
|
||||||
for _,rank in pairs(global.ranks) do
|
for _,rank in pairs(global.ranks) do
|
||||||
if player.permission_group == game.permissions.get_group(rank.name) then return rank end
|
if player.permission_group == game.permissions.get_group(rank.name) then return rank end
|
||||||
end
|
end
|
||||||
return string.to_rank('Guest')
|
return string_to_rank('Guest')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--this will convert the name of a rank into the rank object
|
||||||
local function string.to_rank(string)
|
function string_to_rank(string)
|
||||||
if type(string) == 'string' then
|
if type(string) == 'string' then
|
||||||
local Foundranks={}
|
local Foundranks={}
|
||||||
for _,rank in pairs(global.ranks) do
|
for _,rank in pairs(global.ranks) do
|
||||||
@@ -38,9 +38,9 @@ local function string.to_rank(string)
|
|||||||
if #Foundranks == 1 then return Foundranks[1] end
|
if #Foundranks == 1 then return Foundranks[1] end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--this will send a message to all members if this rank and above default is mod rank
|
||||||
local function rank_print(msg, rank, inv)
|
function rank_print(msg, rank, inv)
|
||||||
local rank = string.to_rank(rank) or string.to_rank('Mod') -- default mod or higher
|
local rank = string_to_rank(rank) or string_to_rank('Mod') -- default mod or higher
|
||||||
local inv = inv or false
|
local inv = inv or false
|
||||||
for _, player in pairs(game.players) do
|
for _, player in pairs(game.players) do
|
||||||
rankPower = get_rank(player).power
|
rankPower = get_rank(player).power
|
||||||
@@ -55,54 +55,53 @@ local function rank_print(msg, rank, inv)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--this will give the user their new rank and raise the Event.rank_change event
|
||||||
local function give_rank(player,rank,byPlayer)
|
function give_rank(player,rank,by_player)
|
||||||
local byPlayer = byPlayer or 'system'
|
local by_player = by_player or 'system'
|
||||||
local rank = string.to_rank(rank) or rank or string.to_rank('Guest')
|
local rank = string_to_rank(rank) or rank or string_to_rank('Guest')
|
||||||
local old_rank = get_rank(player)
|
local old_rank = get_rank(player)
|
||||||
local message = 'demoted'
|
local message = 'demoted'
|
||||||
if rank.power <= old_rank.power then message = 'promoted' end
|
if rank.power <= old_rank.power then message = 'promoted' end
|
||||||
if byPlayer.name then
|
if by_player.name then
|
||||||
rank_print(player.name..' was '..message..' to '..rank.name..' by '..byPlayer.name,'Guest')
|
rank_print(player.name..' was '..message..' to '..rank.name..' by '..by_player.name,'Guest')
|
||||||
else
|
else
|
||||||
rank_print(player.name..' was '..message..' to '..rank.name..' by <system>','Guest')
|
rank_print(player.name..' was '..message..' to '..rank.name..' by <system>','Guest')
|
||||||
end
|
end
|
||||||
player.permission_group = game.permissions.get_group(rank.name)
|
player.permission_group = game.permissions.get_group(rank.name)
|
||||||
if player.tag:find('-') then player.print('Your Custom Tag Was Reset Due To A Rank Change') end
|
if player.tag:find('-') then player.print('Your Custom Tag Was Reset Due To A Rank Change') end
|
||||||
player.tag = get_rank(player).tag
|
player.tag = get_rank(player).tag
|
||||||
drawToolbar(player)
|
|
||||||
drawPlayerList()
|
|
||||||
if old_rank.name ~= 'Jail' then global.old_ranks[player.index]=old_rank.name end
|
if old_rank.name ~= 'Jail' then global.old_ranks[player.index]=old_rank.name end
|
||||||
|
script.raise_event(Event.rank_change, {player=player, by_player=by_player, new_rank=rank, old_rank=old_rank})
|
||||||
end
|
end
|
||||||
|
--the user's rank is reverted to what it was before the lastest change
|
||||||
local function revert_rank(player,byPlayer)
|
function revert_rank(player,by_player)
|
||||||
local rank = string.to_rank(global.old_ranks[player.index])
|
local rank = string_to_rank(global.old_ranks[player.index])
|
||||||
give_rank(player,rank,byPlayer)
|
give_rank(player,rank,by_player)
|
||||||
end
|
end
|
||||||
|
--the player is given a new rank based on playtime and/or preset ranks
|
||||||
local function find_new_rank(player)
|
function find_new_rank(player)
|
||||||
local function loop_preset_rank(players)
|
local function loop_preset_rank(players,rank)
|
||||||
for _,p in pairs(players) do
|
for _,p in pairs(players) do
|
||||||
if player.name:lower() == p:lower() then return string.to_rank(rank) end
|
if player.name:lower() == p:lower() then return rank end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local current_rank = get_rank(player)
|
local current_rank = get_rank(player)
|
||||||
local old_rank = get_rank(player)
|
local old_rank = get_rank(player)
|
||||||
local possible_ranks = {current_rank}
|
local possible_ranks = {current_rank}
|
||||||
--loops though preset ranks
|
--loops though preset ranks
|
||||||
for rank,players in pairs(preset_ranks) do
|
for rank,players in pairs(global.preset_ranks) do
|
||||||
local rank = loop_preset_rank(players)
|
local found_rank = loop_preset_rank(players, rank)
|
||||||
if rank then table.insert(possible_ranks,string.to_rank(rank)) break end
|
if found_rank then table.insert(possible_ranks,string_to_rank(found_rank)) break end
|
||||||
end
|
end
|
||||||
--loops though rank times
|
--loops though rank times
|
||||||
for _,rank in pairs(global.ranks) do
|
for _,rank in pairs(global.ranks) do
|
||||||
if rank.time and ticktominutes(player.online_time) >= trank.time then table.insert(possible_ranks,string.to_rank(rank)) end
|
if rank.time and tick_to_min(player.online_time) >= rank.time then table.insert(possible_ranks,string_to_rank(rank)) end
|
||||||
end
|
end
|
||||||
--loops though possible ranks
|
--loops though possible ranks
|
||||||
if current_rank.name ~='Jail' then
|
if current_rank.name ~='Jail' then
|
||||||
local highest_rank = possible_ranks[1]
|
local highest_rank = possible_ranks[1]
|
||||||
for _,rank in pairs(possible_ranks) do
|
for _,rank in pairs(possible_ranks) do
|
||||||
if rank.power > highest_rank.power then highest_rank = rank end
|
if rank.power < highest_rank.power then highest_rank = rank end
|
||||||
end
|
end
|
||||||
--gives player new rank if availble
|
--gives player new rank if availble
|
||||||
if highest_rank.name == 'Guest' then
|
if highest_rank.name == 'Guest' then
|
||||||
@@ -115,8 +114,17 @@ local function find_new_rank(player)
|
|||||||
if get_rank(player).power <= 3 and not player.admin then rank_print(player.name..' needs to be promoted.') end
|
if get_rank(player).power <= 3 and not player.admin then rank_print(player.name..' needs to be promoted.') end
|
||||||
if old_rank.name ~= get_rank(player).name then global.old_ranks[player.index]=old_rank.name end
|
if old_rank.name ~= get_rank(player).name then global.old_ranks[player.index]=old_rank.name end
|
||||||
end
|
end
|
||||||
|
--event handlers
|
||||||
Event.register(-1,function() global.old_ranks = {} end)
|
Event.rank_change = script.generate_event_name()
|
||||||
Event.register('on_player_joined_game',function(event) find_new_rank(game.players[game.players[event.player_index]]) end)
|
Event.register(-1,function()
|
||||||
|
global.old_ranks = {}
|
||||||
|
for _,rank in pairs(global.ranks) do
|
||||||
|
game.permissions.create_group(rank.name)
|
||||||
|
for _,toRemove in pairs(rank.disallow) do
|
||||||
|
game.permissions.get_group(rank.name).set_allows_action(defines.input_action[toRemove],false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
Event.register(defines.events.on_player_joined_game,function(event) find_new_rank(game.players[event.player_index]) end)
|
||||||
--Please Only Edit Above This Line-----------------------------------------------------------
|
--Please Only Edit Above This Line-----------------------------------------------------------
|
||||||
return credits
|
return credits
|
||||||
@@ -155,4 +155,4 @@ end
|
|||||||
-- Moves The Ranks to the global array
|
-- Moves The Ranks to the global array
|
||||||
Event.register(-1,function() global.ranks = ranks end)
|
Event.register(-1,function() global.ranks = ranks end)
|
||||||
--Please Only Edit Above This Line-----------------------------------------------------------
|
--Please Only Edit Above This Line-----------------------------------------------------------
|
||||||
return credits, ranks
|
return credits
|
||||||
@@ -19,6 +19,7 @@ local credits = {{
|
|||||||
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
||||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
--Please Only Edit Below This Line-----------------------------------------------------------
|
||||||
--as this is the core file the order in which the files are loaded does matter do not change
|
--as this is the core file the order in which the files are loaded does matter do not change
|
||||||
|
credit_loop(require("ExpGaming - Lib"))
|
||||||
credit_loop(require("ExpGaming - Rank Table"))
|
credit_loop(require("ExpGaming - Rank Table"))
|
||||||
credit_loop(require("ExpGaming - Rank Presets"))
|
credit_loop(require("ExpGaming - Rank Presets"))
|
||||||
credit_loop(require("ExpGaming - Rank Control"))
|
credit_loop(require("ExpGaming - Rank Control"))
|
||||||
|
|||||||
Reference in New Issue
Block a user