mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Formated upto ExpGamingCore.Commands
This commit is contained in:
@@ -1,11 +1,9 @@
|
|||||||
--- A full ranking system for factorio.
|
--- A full ranking system for factorio.
|
||||||
-- @module ExpGamingCommands.kill
|
-- @module ExpGamingAdmin.Commands@4.0.0
|
||||||
-- @author Cooldude2606
|
-- @author Cooldude2606
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||||
|
|
||||||
-- this file should be replaced with a collection but idk if fsm can hanndle collections in a collection
|
local Admin = require('ExpGamingAdmin.AdminLib@^4.0.0')
|
||||||
|
|
||||||
local Admin = require('ExpGamingAdmin.AdminLib')
|
|
||||||
|
|
||||||
--- Used to clear all parts of a player, removing warnings, reports, jail and temp ban
|
--- Used to clear all parts of a player, removing warnings, reports, jail and temp ban
|
||||||
-- @command clear-all
|
-- @command clear-all
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "admin",
|
"name": "Commands",
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"type": "Submodule",
|
"type": "Submodule",
|
||||||
"description": "Admins many of the admin featues which the script can use as in game commands.",
|
"description": "Admins many of the admin featues which the script can use as in game commands.",
|
||||||
@@ -24,5 +24,5 @@
|
|||||||
"ExpGamingAdmin.Reports": "^?4.0.0",
|
"ExpGamingAdmin.Reports": "^?4.0.0",
|
||||||
"ExpGamingAdmin.ClearInventory": "?^4.0.0"
|
"ExpGamingAdmin.ClearInventory": "?^4.0.0"
|
||||||
},
|
},
|
||||||
"collection": "ExpGamingCommands_4.0.0"
|
"collection": "ExpGamingAdmin_4.0.0"
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
local Admin = Admin
|
local Admin = Admin
|
||||||
local Ranking = require('ExpGamingCore.Ranking')
|
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
|
||||||
|
|
||||||
--- Reports a player
|
--- Reports a player
|
||||||
-- @command report
|
-- @command report
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
local Admin = Admin
|
local Admin = Admin
|
||||||
local Ranking = require('ExpGamingCore.Ranking')
|
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
|
||||||
|
|
||||||
--- Gives a warning to a player
|
--- Gives a warning to a player
|
||||||
-- @command warn
|
-- @command warn
|
||||||
@@ -241,6 +241,34 @@
|
|||||||
"ExpGamingCore.Sync": "?^4.0.0"
|
"ExpGamingCore.Sync": "?^4.0.0"
|
||||||
},
|
},
|
||||||
"collection": "ExpGamingAdmin_4.0.0"
|
"collection": "ExpGamingAdmin_4.0.0"
|
||||||
|
},
|
||||||
|
"Commands": {
|
||||||
|
"name": "Commands",
|
||||||
|
"version": "4.0.0",
|
||||||
|
"type": "Submodule",
|
||||||
|
"description": "Admins many of the admin featues which the script can use as in game commands.",
|
||||||
|
"location": "https://github.com/explosivegaming/scenario/releases/download/v4.0-core/ExpGamingCommands.admin_4.0.0.zip",
|
||||||
|
"keywords": [
|
||||||
|
"ExpGaming",
|
||||||
|
"Admin",
|
||||||
|
"Tools",
|
||||||
|
"Commands",
|
||||||
|
"Temp ban",
|
||||||
|
"Jail",
|
||||||
|
"Clear Inventory",
|
||||||
|
"Report",
|
||||||
|
"Warnings"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"ExpGamingLib": "^4.0.0",
|
||||||
|
"ExpGamingCore.Commands": "^4.0.0",
|
||||||
|
"ExpGamingAdmin.TempBan": "?^4.0.0",
|
||||||
|
"ExpGamingAdmin.Jail": "?^4.0.0",
|
||||||
|
"ExpGamingAdmin.Warnings": "?^4.0.0",
|
||||||
|
"ExpGamingAdmin.Reports": "^?4.0.0",
|
||||||
|
"ExpGamingAdmin.ClearInventory": "?^4.0.0"
|
||||||
|
},
|
||||||
|
"collection": "ExpGamingAdmin_4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {}
|
"dependencies": {}
|
||||||
|
|||||||
@@ -1,39 +1,39 @@
|
|||||||
--- A full ranking system for factorio.
|
--- A full ranking system for factorio.
|
||||||
-- @module ExpGamingCommands.kill
|
-- @module ExpGamingCommands.bonus@^4.0.0
|
||||||
-- @author Cooldude2606
|
-- @author Cooldude2606
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||||
|
|
||||||
|
local global = global{}
|
||||||
|
local Game = require('FactorioStdLib.Game@^0.8.0')
|
||||||
|
|
||||||
-- these are the settings which are changed with scale being as +100%
|
-- these are the settings which are changed with scale being as +100%
|
||||||
local settings = {
|
local settings = {
|
||||||
{key='character_mining_speed_modifier',scale=3},
|
character_mining_speed_modifier=3,
|
||||||
{key='character_crafting_speed_modifier',scale=3},
|
character_crafting_speed_modifier=3,
|
||||||
{key='character_running_speed_modifier',scale=3},
|
character_running_speed_modifier=3,
|
||||||
{key='character_build_distance_bonus',scale=20},
|
character_build_distance_bonus=20,
|
||||||
{key='character_reach_distance_bonus',scale=20},
|
character_reach_distance_bonus=20,
|
||||||
{key='character_inventory_slots_bonus',scale=200}
|
character_inventory_slots_bonus=200
|
||||||
}
|
}
|
||||||
|
|
||||||
local global = global{}
|
|
||||||
local Game = require('FactorioStdLib.Game')
|
|
||||||
|
|
||||||
--- Allows a player to set there bonus
|
--- Allows a player to set there bonus
|
||||||
-- @command bonus
|
-- @command bonus
|
||||||
-- @param bonus the amount of bonus there will get
|
-- @param bonus the amount of bonus there will get
|
||||||
commands.add_command('bonus', 'Set your player bonus (default is 20, guest has 0)', {
|
commands.add_command('bonus', 'Set your player bonus (default is 20, guest has 0)', {
|
||||||
['bonus'] = {true,'number-range',-1,50} -- -1 < math.floor(bonus) <= 50
|
['bonus'] = {true,'number-range-int',-1,50} -- -1 < math.floor(bonus) <= 50
|
||||||
}, function(event,args)
|
}, function(event,args)
|
||||||
local player = Game.get_player(event)
|
local player = Game.get_player(event)
|
||||||
local bonus = args.bonus
|
local bonus = args.bonus
|
||||||
for _,setting in pairs(settings) do player[setting.key] = setting.scale*math.floor(bonus)*0.01 end
|
for key,setting in pairs(settings) do player[key] = setting*math.floor(bonus)*0.01 end
|
||||||
global[player.index]=bonus
|
global[player.index]=bonus
|
||||||
player_return('Bonus set to: '..math.floor(bonus)..'%')
|
player_return('Bonus set to: '..math.floor(bonus)..'%')
|
||||||
end)
|
end).default_admin_only = true
|
||||||
|
|
||||||
script.on_event(defines.events.on_player_respawned,function(event)
|
script.on_event(defines.events.on_player_respawned,function(event)
|
||||||
local player = Game.get_player(event)
|
local player = Game.get_player(event)
|
||||||
local bonus = global[player.index]
|
local bonus = global[player.index]
|
||||||
if bonus then
|
if bonus then
|
||||||
for _,setting in pairs(settings) do player[setting.key] = setting.scale*math.floor(bonus)*0.01 end
|
for _,setting in pairs(settings) do player[key] = setting*math.floor(bonus)*0.01 end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -54,8 +54,8 @@ end)
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
on_init= function(self)
|
on_init= function(self)
|
||||||
if loaded_modules['ExpGamingCore.Ranking'] then
|
if loaded_modules['ExpGamingCore.Ranking@^4.0.0'] then
|
||||||
local Ranking = require('ExpGamingCore.Ranking')
|
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
|
||||||
-- instant respawn
|
-- instant respawn
|
||||||
script.on_event(defines.events.on_pre_player_died,function(event)
|
script.on_event(defines.events.on_pre_player_died,function(event)
|
||||||
local player = Game.get_player(event)
|
local player = Game.get_player(event)
|
||||||
@@ -74,10 +74,10 @@ return {
|
|||||||
script.on_event(defines.events.rank_change,function(event)
|
script.on_event(defines.events.rank_change,function(event)
|
||||||
local player = Game.get_player(event)
|
local player = Game.get_player(event)
|
||||||
if event.new_rank:allowed('bonus') then
|
if event.new_rank:allowed('bonus') then
|
||||||
for _,setting in pairs(settings) do player[setting.key] = setting.scale*0.2 end
|
for _,setting in pairs(settings) do player[key] = setting*0.2 end
|
||||||
global[player.index]=20
|
global[player.index]=20
|
||||||
else
|
else
|
||||||
for _,setting in pairs(settings) do player[setting.key] = 0 end
|
for _,setting in pairs(settings) do player[key] = 0 end
|
||||||
global[player.index]=nil
|
global[player.index]=nil
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
--- A full ranking system for factorio.
|
--- A full ranking system for factorio.
|
||||||
-- @module ExpGamingCommands.kill
|
-- @module ExpGamingCommands.cheatMode@4.0.0
|
||||||
-- @author Cooldude2606
|
-- @author Cooldude2606
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||||
|
|
||||||
@@ -11,4 +11,4 @@ commands.add_command('cheat-mode', 'Toggles cheat mode for a player', {
|
|||||||
}, function(event,args)
|
}, function(event,args)
|
||||||
local player = args.player or game.player
|
local player = args.player or game.player
|
||||||
if player.cheat_mode == true then player.cheat_mode = false else player.cheat_mode = true end
|
if player.cheat_mode == true then player.cheat_mode = false else player.cheat_mode = true end
|
||||||
end)
|
end).default_admin_only = true
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
--- A full ranking system for factorio.
|
--- A full ranking system for factorio.
|
||||||
-- @module ExpGamingCommands.kill
|
-- @module ExpGamingCommands.home@4.0.0
|
||||||
-- @author Cooldude2606
|
-- @author Cooldude2606
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||||
|
|
||||||
local Game = require('FactorioStdLib.Game')
|
local Game = require('FactorioStdLib.Game@^0.8.0')
|
||||||
local global = global{}
|
local global = global{}
|
||||||
|
|
||||||
--- Sets the home for a player
|
--- Sets the home for a player
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
--- A full ranking system for factorio.
|
--- A full ranking system for factorio.
|
||||||
-- @module ExpGamingCommands.kill
|
-- @module ExpGamingCommands.kill@4.0.0
|
||||||
-- @author Cooldude2606
|
-- @author Cooldude2606
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||||
|
|
||||||
local Game = require('FactorioStdLib.Game')
|
local Game = require('FactorioStdLib.Game@^4.0.0')
|
||||||
|
|
||||||
--- Kills a player of a lower rank
|
--- Kills a player of a lower rank
|
||||||
-- @command kill
|
-- @command kill
|
||||||
@@ -15,4 +15,4 @@ commands.add_command('kill', 'Kills a player. No player name kills yourself.', {
|
|||||||
local player = args.player
|
local player = args.player
|
||||||
if player then player.character.die()
|
if player then player.character.die()
|
||||||
else _player.character.die() end
|
else _player.character.die() end
|
||||||
end)
|
end).default_admin_only = true
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"type": "Submodule",
|
"type": "Submodule",
|
||||||
"description": "Adds a command which can be used to kill a player or yourself.",
|
"description": "Adds a command which can be used to kill a player or yourself.",
|
||||||
"location": "https://github.com/explosivegaming/scenario/releases/download/v4.0-core/ExpGamingCommands.kill_4.0.0.zip",
|
"location": "https://github.com/explosivegaming/scenario/releases/download/v4.0-core/ExpGamingAdmin.Commands_4.0.0.zip",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Command",
|
"Command",
|
||||||
"ExpGaming",
|
"ExpGaming",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
--- A full ranking system for factorio.
|
--- A full ranking system for factorio.
|
||||||
-- @module ExpGamingCommands.kill
|
-- @module ExpGamingCommands.repair@4.0.0
|
||||||
-- @author Cooldude2606
|
-- @author Cooldude2606
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||||
|
|
||||||
|
|
||||||
local Game = require('FactorioStdLib.Game')
|
local Game = require('FactorioStdLib.Game@^0.8.0')
|
||||||
local Ranking = require('ExpGamingCore.Ranking')
|
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
|
||||||
|
|
||||||
-- Set an item to true to disallow it from being repaired
|
-- Set an item to true to disallow it from being repaired
|
||||||
local disallow = {
|
local disallow = {
|
||||||
@@ -18,13 +18,22 @@ local disallow = {
|
|||||||
|
|
||||||
-- Given const = 100: admin+ has unlimited, admin has const (100), mod has const / 2 (50), member has const / 5 (20)
|
-- Given const = 100: admin+ has unlimited, admin has const (100), mod has const / 2 (50), member has const / 5 (20)
|
||||||
local const = 100
|
local const = 100
|
||||||
|
local repairDisallow
|
||||||
|
|
||||||
|
-- Module Define
|
||||||
|
local module_verbose = false
|
||||||
|
local ThisModule = {
|
||||||
|
on_init = function(self)
|
||||||
|
if loaded_modules['ExpGamingAdmin.TempBan@^4.0.0'] then verbose('ExpGamingAdmin.TempBan is installed; Loading tempban src') repairDisallow = require(module_path..'/src/tempban') end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
--- Used so that the value can be overriden if tempban is present
|
--- Used so that the value can be overriden if tempban is present
|
||||||
-- @local
|
-- @local
|
||||||
-- @function repairDisallow
|
-- @function repairDisallow
|
||||||
-- @param player the player who called the command
|
-- @param player the player who called the command
|
||||||
-- @param entity the entity which was repaired
|
-- @param entity the entity which was repaired
|
||||||
local repairDisallow = function(player,entity)
|
repairDisallow = function(player,entity)
|
||||||
player_return('You have repaired: '..entity.name..' this item is not allowed.',defines.textcolor.crit,player)
|
player_return('You have repaired: '..entity.name..' this item is not allowed.',defines.textcolor.crit,player)
|
||||||
entity.destroy()
|
entity.destroy()
|
||||||
end
|
end
|
||||||
@@ -54,10 +63,6 @@ commands.add_command('repair', 'Repairs all destoryed and damaged entites in an
|
|||||||
for key, entity in pairs(player.surface.find_entities(area)) do
|
for key, entity in pairs(player.surface.find_entities(area)) do
|
||||||
if entity.force == player.force and (entity.position.x-center.x)^2+(entity.position.y-center.y)^2 < sq_range and entity.health then entity.health = 10000 end
|
if entity.force == player.force and (entity.position.x-center.x)^2+(entity.position.y-center.y)^2 < sq_range and entity.health then entity.health = 10000 end
|
||||||
end
|
end
|
||||||
end)
|
end).default_admin_only = true
|
||||||
|
|
||||||
return {
|
return ThisModule
|
||||||
on_init = function(self)
|
|
||||||
if loaded_modules['ExpGamingAdmin.TempBan'] then verbose('ExpGamingAdmin.TempBan is installed; Loading tempban src') repairDisallow = require(module_path..'/src/tempban') end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,34 +14,6 @@
|
|||||||
"contact": "Discord: Cooldude2606#5241",
|
"contact": "Discord: Cooldude2606#5241",
|
||||||
"license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE",
|
"license": "https://github.com/explosivegaming/scenario/blob/master/LICENSE",
|
||||||
"submodules": {
|
"submodules": {
|
||||||
"admin": {
|
|
||||||
"name": "admin",
|
|
||||||
"version": "4.0.0",
|
|
||||||
"type": "Submodule",
|
|
||||||
"description": "Admins many of the admin featues which the script can use as in game commands.",
|
|
||||||
"location": "https://github.com/explosivegaming/scenario/releases/download/v4.0-core/ExpGamingCommands.admin_4.0.0.zip",
|
|
||||||
"keywords": [
|
|
||||||
"ExpGaming",
|
|
||||||
"Admin",
|
|
||||||
"Tools",
|
|
||||||
"Commands",
|
|
||||||
"Temp ban",
|
|
||||||
"Jail",
|
|
||||||
"Clear Inventory",
|
|
||||||
"Report",
|
|
||||||
"Warnings"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"ExpGamingLib": "^4.0.0",
|
|
||||||
"ExpGamingCore.Commands": "^4.0.0",
|
|
||||||
"ExpGamingAdmin.TempBan": "?^4.0.0",
|
|
||||||
"ExpGamingAdmin.Jail": "?^4.0.0",
|
|
||||||
"ExpGamingAdmin.Warnings": "?^4.0.0",
|
|
||||||
"ExpGamingAdmin.Reports": "^?4.0.0",
|
|
||||||
"ExpGamingAdmin.ClearInventory": "?^4.0.0"
|
|
||||||
},
|
|
||||||
"collection": "ExpGamingCommands_4.0.0"
|
|
||||||
},
|
|
||||||
"bonus": {
|
"bonus": {
|
||||||
"name": "bonus",
|
"name": "bonus",
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
@@ -108,7 +80,7 @@
|
|||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"type": "Submodule",
|
"type": "Submodule",
|
||||||
"description": "Adds a command which can be used to kill a player or yourself.",
|
"description": "Adds a command which can be used to kill a player or yourself.",
|
||||||
"location": "https://github.com/explosivegaming/scenario/releases/download/v4.0-core/ExpGamingCommands.kill_4.0.0.zip",
|
"location": "https://github.com/explosivegaming/scenario/releases/download/v4.0-core/ExpGamingAdmin.Commands_4.0.0.zip",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Command",
|
"Command",
|
||||||
"ExpGaming",
|
"ExpGaming",
|
||||||
@@ -160,7 +132,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ExpGamingLib": "^4.0.0",
|
"ExpGamingLib": "^4.0.0",
|
||||||
"ExpGamingCore.Ranking": "^4.0.0",
|
"ExpGamingCore.Ranking": "?^4.0.0",
|
||||||
"ExpGamingCore.Commands": "^4.0.0",
|
"ExpGamingCore.Commands": "^4.0.0",
|
||||||
"FactorioStdLib.Game": "^0.8.0"
|
"FactorioStdLib.Game": "^0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
--- A full ranking system for factorio.
|
--- A full ranking system for factorio.
|
||||||
-- @module ExpGamingCommands.kill
|
-- @module ExpGamingCommands@4.0.0
|
||||||
-- @author Cooldude2606
|
-- @author Cooldude2606
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||||
|
|
||||||
local Game = require('FactorioStdLib.Game')
|
local Game = require('FactorioStdLib.Game@^0.8.0')
|
||||||
local Ranking = require('ExpGamingCore.Ranking')
|
local Ranking -- ExpGamingCore.Ranking@^4.0.0
|
||||||
|
|
||||||
|
-- Module Define
|
||||||
|
local module_verbose = false
|
||||||
|
local ThisModule = {
|
||||||
|
on_init=function()
|
||||||
|
if loaded_modules['ExpGamingCore.Ranking@^4.0.0'] then Ranking = require('ExpGamingCore.Ranking@^4.0.0') end
|
||||||
|
--code
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
--- Gives you a tag
|
--- Gives you a tag
|
||||||
-- @command tag
|
-- @command tag
|
||||||
@@ -13,8 +22,10 @@ commands.add_command('tag', 'Give yourself a custom tag. Use "" to have more tha
|
|||||||
['tag'] = {true,'string-len',20}
|
['tag'] = {true,'string-len',20}
|
||||||
}, function(event,args)
|
}, function(event,args)
|
||||||
local player = Game.get_player(event)
|
local player = Game.get_player(event)
|
||||||
local rank = Ranking.get_rank(player)
|
if Ranking then
|
||||||
player.tag = rank.tag..' - '..args.tag
|
local rank = Ranking.get_rank(player)
|
||||||
|
player.tag = rank.tag..' - '..args.tag
|
||||||
|
else player.tag = args.tag end
|
||||||
player_return('Your tag has been set. Use /tag-clear to remove your tag')
|
player_return('Your tag has been set. Use /tag-clear to remove your tag')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -25,7 +36,10 @@ commands.add_command('tag-clear', 'Removes a custom tag. Player can be self (/ta
|
|||||||
['player'] = {true,'player-rank'}
|
['player'] = {true,'player-rank'}
|
||||||
}, function(event,args)
|
}, function(event,args)
|
||||||
local player = args.player
|
local player = args.player
|
||||||
local rank = Ranking.get_rank(player)
|
if Ranking then
|
||||||
player.tag = rank.tag
|
local rank = Ranking.get_rank(player)
|
||||||
|
player.tag = rank.tag
|
||||||
|
else player.tag = '' end
|
||||||
player_return('Your tag has been removed.')
|
player_return('Your tag has been removed.')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ExpGamingLib": "^4.0.0",
|
"ExpGamingLib": "^4.0.0",
|
||||||
"ExpGamingCore.Ranking": "^4.0.0",
|
"ExpGamingCore.Ranking": "?^4.0.0",
|
||||||
"ExpGamingCore.Commands": "^4.0.0",
|
"ExpGamingCore.Commands": "^4.0.0",
|
||||||
"FactorioStdLib.Game": "^0.8.0"
|
"FactorioStdLib.Game": "^0.8.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
--- A full ranking system for factorio.
|
--- A full ranking system for factorio.
|
||||||
-- @module ExpGamingCommands.kill
|
-- @module ExpGamingCommands.teleport@4.0.0
|
||||||
-- @author Cooldude2606
|
-- @author Cooldude2606
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||||
|
|
||||||
local Admin = require('ExpGamingAdmin.Teleport')
|
local Admin = require('ExpGamingAdmin.Teleport@^4.0.0')
|
||||||
|
|
||||||
--- Teleports the user to the player given
|
--- Teleports the user to the player given
|
||||||
-- @command go-to
|
-- @command go-to
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
--- A full ranking system for factorio.
|
--- Command system that allows middle ware and auto validation of command arguments.
|
||||||
-- @module ExpGamingCore.Commands
|
-- @module ExpGamingCore.Commands@4.0.0
|
||||||
-- @alias commands
|
|
||||||
-- @author Cooldude2606
|
-- @author Cooldude2606
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||||
|
-- @alias commands
|
||||||
|
|
||||||
local Game = require('FactorioStdLib.Game')
|
local Game = require('FactorioStdLib.Game@^0.8.0')
|
||||||
local Color = require('FactorioStdLib.Color')
|
local Color = require('FactorioStdLib.Color@^0.8.0')
|
||||||
local Ranking -- this is optional and is hanndled by it being present, it is loaded on init
|
|
||||||
|
|
||||||
--- Used as an error constant for validation
|
--- Used as an error constant for validation
|
||||||
-- @field commands.error
|
-- @field commands.error
|
||||||
@@ -15,6 +14,11 @@ local Ranking -- this is optional and is hanndled by it being present, it is loa
|
|||||||
commands.error = setmetatable({},{__call=function(...) return ... end})
|
commands.error = setmetatable({},{__call=function(...) return ... end})
|
||||||
commands._add_command = commands.add_command
|
commands._add_command = commands.add_command
|
||||||
local data = {}
|
local data = {}
|
||||||
|
local middleware = {}
|
||||||
|
|
||||||
|
--- Used to add middle ware to the command handler, functions should return true or false
|
||||||
|
-- @tparam function callback function(player,commandName,event) should return true to allow next middle ware to run
|
||||||
|
function commands.add_middleware(callback) if not is_type(callback,'function') then error('Callback is not a function',2) return end table.insert(middleware,callback) end
|
||||||
|
|
||||||
--- Index of all command data
|
--- Index of all command data
|
||||||
-- @field commands.data
|
-- @field commands.data
|
||||||
@@ -50,6 +54,7 @@ setmetatable(commands,{
|
|||||||
-- @field player_rank-online converts the input to a player if the player is a lower rank than the user and online
|
-- @field player_rank-online converts the input to a player if the player is a lower rank than the user and online
|
||||||
-- @field player_rank_alive converts the input to a player if the player is a lower rank than the user and online and alive
|
-- @field player_rank_alive converts the input to a player if the player is a lower rank than the user and online and alive
|
||||||
commands.validate = {
|
commands.validate = {
|
||||||
|
['boolean']=function(value,event) local value = value.lower() if value == 'true' or valule == 'yes' or value == 'y' or value == '1' then return true else return false end end,
|
||||||
['string']=function(value,event) return tostring(value) end,
|
['string']=function(value,event) return tostring(value) end,
|
||||||
['string-inf']=function(value,event) return tostring(value) end,
|
['string-inf']=function(value,event) return tostring(value) end,
|
||||||
['string-len']=function(value,event,max) return tostring(value) and tostring(value):len() <= max and tostring(value) or commands.error{'commands.error-string-len'} end,
|
['string-len']=function(value,event,max) return tostring(value) and tostring(value):len() <= max and tostring(value) or commands.error{'commands.error-string-len'} end,
|
||||||
@@ -60,10 +65,14 @@ commands.validate = {
|
|||||||
['player']=function(value,event) return Game.get_player(player) or commands.error{'commands.error-player'} end,
|
['player']=function(value,event) return Game.get_player(player) or commands.error{'commands.error-player'} end,
|
||||||
['player-online']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or player.conected and player or commands.error{'commands.error-player-online'} end,
|
['player-online']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or player.conected and player or commands.error{'commands.error-player-online'} end,
|
||||||
['player-alive']=function(value,event) local player,err = commands.validate['player-online'](value) return err and commands.error(err) or player.character and player.character.health > 0 and player or commands.error{'commands.error-player-alive'} end,
|
['player-alive']=function(value,event) local player,err = commands.validate['player-online'](value) return err and commands.error(err) or player.character and player.character.health > 0 and player or commands.error{'commands.error-player-alive'} end,
|
||||||
['player-rank']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or Ranking and Ranking.get_rank(player).power > Ranking.get_rank(event).power or not player.admin and Game.get_player(event).admin or commands.error{'commands.error-player-rank'} end,
|
['player-rank']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or not player.admin and Game.get_player(event).admin and player or commands.error{'commands.error-player-rank'} end,
|
||||||
['player-rank-online']=function(value,event) local player,err = commands.validate['player-online'](value) return err and commands.error(err) or Ranking and Ranking.get_rank(player).power > Ranking.get_rank(event).power or not player.admin and Game.get_player(event).admin or commands.error{'commands.error-player-rank'} end,
|
['player-rank-online']=function(value,event) local player,err = commands.validate['player-online'](value) if err then return commands.error(err) end local player,err = commands.validate['player-rank'](player) if err then return commands.error(err) end return player end,
|
||||||
['player-rank-alive']=function(value,event) local player,err = commands.validate['player-alive'](value) return err and commands.error(err) or Ranking and Ranking.get_rank(player).power > Ranking.get_rank(event).power or not player.admin and Game.get_player(event).admin or commands.error{'commands.error-player-rank'} end
|
['player-rank-alive']=function(value,event) local player,err = commands.validate['player-alive'](value) if err then return commands.error(err) end local player,err = commands.validate['player-rank'](player) if err then return commands.error(err) end return player end,
|
||||||
}
|
}
|
||||||
|
--- Adds a function to the validation list
|
||||||
|
-- @tparam string name the name of the validation
|
||||||
|
-- @tparam function callback function(value,event) which returns either the value to be used or commands.error{'error-message'}
|
||||||
|
function commands.add_validation(name,callback) if not is_type(callback,'function') then error('Callback is not a function',2) return end commands.validate[name]=callback end
|
||||||
|
|
||||||
--- Returns the inputs of this command as a formated string
|
--- Returns the inputs of this command as a formated string
|
||||||
-- @usage commands.format_inputs('interface') -- returns <code> (if you have ExpGamingCore.Server)
|
-- @usage commands.format_inputs('interface') -- returns <code> (if you have ExpGamingCore.Server)
|
||||||
@@ -136,58 +145,61 @@ function commands.get_commands(player)
|
|||||||
local commands = {}
|
local commands = {}
|
||||||
local player = Game.get_player(player)
|
local player = Game.get_player(player)
|
||||||
if not player then return error('Invalid player',2) end
|
if not player then return error('Invalid player',2) end
|
||||||
local rank = Ranking.get_rank(player)
|
|
||||||
for name,data in pairs(data) do
|
for name,data in pairs(data) do
|
||||||
if rank:allowed(name) then table.insert(commands,data) end
|
if #middleware > 0 then for _,callback in pairs(middleware) do
|
||||||
|
local success, err = pcall(callback,player_name,command.name,command)
|
||||||
|
if not success then error(err)
|
||||||
|
elseif err then table.insert(commands,data) end
|
||||||
|
end elseif data.default_admin_only == true and player.admin then table.insert(commands,data) end
|
||||||
end
|
end
|
||||||
return commands
|
return commands
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function logMessage(player_name,command,message,args)
|
||||||
|
game.write_file('commands.log',
|
||||||
|
game.tick
|
||||||
|
..' Player: "'..player_name..'"'
|
||||||
|
..' '..message..': "'..command.name..'"'
|
||||||
|
..' With args of: '..table.tostring(args)
|
||||||
|
..'\n'
|
||||||
|
, true, 0)
|
||||||
|
end
|
||||||
|
|
||||||
--- Used to call the custom commands
|
--- Used to call the custom commands
|
||||||
-- @usage You dont its an internal command
|
-- @usage You dont its an internal command
|
||||||
-- @tparam table command the event rasied by the command
|
-- @tparam table command the event rasied by the command
|
||||||
local function run_custom_command(command)
|
local function run_custom_command(command)
|
||||||
local data = commands.data[command.name]
|
local data = commands.data[command.name]
|
||||||
local player_name = Game.get_player(command) and Game.get_player(command).name or 'server'
|
local player_name = Game.get_player(command) and Game.get_player(command).name or 'server'
|
||||||
-- is the player allowed to use this command, if no ExpGamingCore.Ranking then this is ingroned
|
-- runs all middle ware if any, if there is no middle where then it relyis on .default_admin_only
|
||||||
if Ranking and Ranking.meta and Ranking.meta.rank_count > 0 and not Ranking.get_rank(player_name):allowed(command.name)
|
if #middleware > 0 then for _,callback in pairs(middleware) do
|
||||||
or not Ranking and data.admin_only == true and game.player and not game.player.admin then
|
local success, err = pcall(callback,player_name,command.name,command)
|
||||||
|
if not success then error(err)
|
||||||
|
elseif not err then
|
||||||
|
player_return({'commands.unauthorized'},defines.textcolor.crit)
|
||||||
|
logMessage(player_name,command,'Failed to use command (Unauthorized)',commands.validate_args(command))
|
||||||
|
if game.player then game.player.play_sound{path='utility/cannot_build'} end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end elseif data.default_admin_only == true and game.player and not game.player.admin then
|
||||||
player_return({'commands.unauthorized'},defines.textcolor.crit)
|
player_return({'commands.unauthorized'},defines.textcolor.crit)
|
||||||
|
logMessage(player_name,command,'Failed to use command (Unauthorized)',commands.validate_args(command))
|
||||||
if game.player then game.player.play_sound{path='utility/cannot_build'} end
|
if game.player then game.player.play_sound{path='utility/cannot_build'} end
|
||||||
game.write_file('commands.log',
|
|
||||||
game.tick
|
|
||||||
..' Player: "'..player_name..'"'
|
|
||||||
..' Failed to use command (Unauthorized): "'..command.name..'"'
|
|
||||||
..' With args of: '..table.tostring(commands.validate_args(command))
|
|
||||||
..'\n'
|
|
||||||
, true, 0)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- gets the args for the command
|
-- gets the args for the command
|
||||||
local args, err = commands.validate_args(command)
|
local args, err = commands.validate_args(command)
|
||||||
if args == commands.error then
|
if args == commands.error then
|
||||||
player_return({'commands.'..err,command.name,commands.format_inputs(data)},defines.textcolor.high)
|
player_return({'commands.'..err,command.name,commands.format_inputs(data)},defines.textcolor.high)
|
||||||
|
logMessage(player_name,command,'Failed to use command (Invalid Args)',args)
|
||||||
if game.player then game.player.play_sound{path='utility/deconstruct_big'} end
|
if game.player then game.player.play_sound{path='utility/deconstruct_big'} end
|
||||||
game.write_file('commands.log',
|
|
||||||
game.tick
|
|
||||||
..' Player: "'..player_name..'"'
|
|
||||||
..' Failed to use command (Invalid Args): "'..command.name..'"'
|
|
||||||
..' With args of: '..table.tostring(args)
|
|
||||||
..'\n'
|
|
||||||
, true, 0)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- runs the command
|
-- runs the command
|
||||||
local success, err = pcall(data.callback,command,args)
|
local success, err = pcall(data.callback,command,args)
|
||||||
if not success then error(err) end
|
if not success then error(err) end
|
||||||
if err ~= commands.error and player_name ~= 'server' then player_return({'commands.command-ran'},defines.textcolor.info) end
|
if err ~= commands.error and player_name ~= 'server' then player_return({'commands.command-ran'},defines.textcolor.info) end
|
||||||
game.write_file('commands.log',
|
logMessage(player_name,command,'Used command',args)
|
||||||
game.tick
|
|
||||||
..' Player: "'..player_name..'"'
|
|
||||||
..' Used command: "'..command.name..'"'
|
|
||||||
..' With args of: '..table.tostring(args)
|
|
||||||
..'\n'
|
|
||||||
, true, 0)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Used to define commands
|
--- Used to define commands
|
||||||
@@ -227,19 +239,16 @@ commands.add_command = function(name, description, inputs, callback)
|
|||||||
return data[name]
|
return data[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
function commands:on_init()
|
|
||||||
if loaded_modules['ExpGamingCore.Ranking'] then Ranking = require('ExpGamingCore.Ranking') end
|
|
||||||
end
|
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
command example
|
command example
|
||||||
|
|
||||||
locale file
|
**locale file**
|
||||||
[foo]
|
[foo]
|
||||||
description=__1__ this is a command
|
description=__1__ this is a command
|
||||||
|
|
||||||
|
**control.lua**
|
||||||
commands.add_command('foo',{'foo.description'},{
|
commands.add_command('foo',{'foo.description'},{
|
||||||
['player']={true,'player'}, -- a required arg that must be a valid player
|
['player']={true,'player'}, -- a required arg that must be a valid player
|
||||||
['number']={true,'number-range',0,10}, -- a required arg that must be a number 0<X<=10
|
['number']={true,'number-range',0,10}, -- a required arg that must be a number 0<X<=10
|
||||||
|
|||||||
@@ -15,8 +15,7 @@
|
|||||||
"ExpGamingLib": "^4.0.0",
|
"ExpGamingLib": "^4.0.0",
|
||||||
"FactorioStdLib.Table": "^0.8.0",
|
"FactorioStdLib.Table": "^0.8.0",
|
||||||
"FactorioStdLib.Color": "^0.8.0",
|
"FactorioStdLib.Color": "^0.8.0",
|
||||||
"FactorioStdLib.Game": "^0.8.0",
|
"FactorioStdLib.Game": "^0.8.0"
|
||||||
"ExpGamingCore.Ranking": "?^4.0.0"
|
|
||||||
},
|
},
|
||||||
"collection": "ExpGamingCore_4.0.0"
|
"collection": "ExpGamingCore_4.0.0"
|
||||||
}
|
}
|
||||||
@@ -438,6 +438,7 @@ require(module_path..'/src/config',{Ranking=Ranking})
|
|||||||
|
|
||||||
function Ranking:on_init()
|
function Ranking:on_init()
|
||||||
if loaded_modules['ExpGamingCore.Server'] then verbose('ExpGamingCore.Server is installed; Loading server src') require(module_path..'/src/server',{Ranking=Ranking}) end
|
if loaded_modules['ExpGamingCore.Server'] then verbose('ExpGamingCore.Server is installed; Loading server src') require(module_path..'/src/server',{Ranking=Ranking}) end
|
||||||
|
if loaded_modules['ExpGamingCore.Commands'] then verbose('ExpGamingCore.Server is installed; Loading commands src') require(module_path..'/src/commands',{Ranking=Ranking}) end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Ranking:on_post()
|
function Ranking:on_post()
|
||||||
|
|||||||
28
modules/ExpGamingCore/Ranking/src/commands.lua
Normal file
28
modules/ExpGamingCore/Ranking/src/commands.lua
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
local Ranking = Ranking
|
||||||
|
|
||||||
|
commands.add_validation('player-rank',function(value,event)
|
||||||
|
local player,err = commands.validate['player'](value)
|
||||||
|
return err and commands.error(err)
|
||||||
|
or Ranking.get_rank(player).power > Ranking.get_rank(event).power and player
|
||||||
|
or commands.error{'commands.error-player-rank'}
|
||||||
|
end)
|
||||||
|
|
||||||
|
commands.add_validation('player-rank-online',function(value,event)
|
||||||
|
local player,err = commands.validate['player-online'](value)
|
||||||
|
if err then return commands.error(err) end
|
||||||
|
local player,err = commands.validate['player-rank'](player)
|
||||||
|
if err then return commands.error(err) end
|
||||||
|
return player
|
||||||
|
end)
|
||||||
|
|
||||||
|
commands.add_validation('player-rank-alive',function(value,event)
|
||||||
|
local player,err = commands.validate['player-alive'](value)
|
||||||
|
if err then return commands.error(err) end
|
||||||
|
local player,err = commands.validate['player-rank'](player)
|
||||||
|
if err then return commands.error(err) end
|
||||||
|
return player
|
||||||
|
end)
|
||||||
|
|
||||||
|
commands.add_middleware(function(player_name,command_name,event)
|
||||||
|
return Ranking.get_rank(player_name):allowed(command_name)
|
||||||
|
end)
|
||||||
@@ -19,7 +19,7 @@ return {
|
|||||||
['ExpGamingCore.Server@^4.0.0']='./modules/ExpGamingCore/Server',
|
['ExpGamingCore.Server@^4.0.0']='./modules/ExpGamingCore/Server',
|
||||||
['ExpGamingCommands.tags@4.0.0']='./modules/ExpGamingCommands/tags',
|
['ExpGamingCommands.tags@4.0.0']='./modules/ExpGamingCommands/tags',
|
||||||
['ExpGamingCore.Commands@^4.0.0']='./modules/ExpGamingCore/Commands',
|
['ExpGamingCore.Commands@^4.0.0']='./modules/ExpGamingCore/Commands',
|
||||||
['ExpGamingCommands.kill@4.0.0']='./modules/ExpGamingCommands/kill',
|
['ExpGamingAdmin.Commands@4.0.0']='./modules/ExpGamingCommands/kill',
|
||||||
['ExpGamingCommands.home@4.0.0']='./modules/ExpGamingCommands/home',
|
['ExpGamingCommands.home@4.0.0']='./modules/ExpGamingCommands/home',
|
||||||
['ExpGamingCommands.cheatMode@4.0.0']='./modules/ExpGamingCommands/cheatMode',
|
['ExpGamingCommands.cheatMode@4.0.0']='./modules/ExpGamingCommands/cheatMode',
|
||||||
['ExpGamingCommands.bonus@4.0.0']='./modules/ExpGamingCommands/bonus',
|
['ExpGamingCommands.bonus@4.0.0']='./modules/ExpGamingCommands/bonus',
|
||||||
|
|||||||
Reference in New Issue
Block a user