Added ExpGamingCommands.repair

This commit is contained in:
Cooldude2606
2018-06-24 20:21:18 +01:00
parent 56762fcf19
commit 83db4651dc
6 changed files with 63 additions and 41 deletions

View File

@@ -8,6 +8,9 @@ Discord: https://discord.gg/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local Game = require('FactorioStdLib.Game')
local Ranking = require('ExpGamingCore.Ranking')
-- Set an item to true to disallow it from being repaired
local disallow = {
['loader']=true,
@@ -17,11 +20,26 @@ local disallow = {
['infinity-chest']=true
}
local const = 100
-- Given const = 100: admin+ has unlimited, admin has const (100), mod has const / 2 (50), member has const / 5 (20)
local const = 100
commands.add_command('repair', 'Repairs all destoryed and damaged entites in an area.', {'range'}, function(event,args)
local range = tonumber(args.range)
--- Used so that the value can be overriden if tempban is present
-- @local
-- @function repairDisallow
-- @param player the player who called the command
-- @param entity the entity which was repaired
local repairDisallow = function(player,entity)
player_return('You have repaired: '..entity.name..' this item is not allowed.',defines.text_color.crit,player)
entity.destroy()
end
--- Used to repair and heal items in an area, different ranks get different size areas
-- @command repair
-- @param range the range that items are repaired in
commands.add_command('repair', 'Repairs all destoryed and damaged entites in an area.', {
['range']={true,'number-int'}
}, function(event,args)
local range = args.range
local player = Game.get_player(event)
local rank = Ranking.get_rank(player)
local highest_admin_power = Ranking.get_group('Admin').highest.power-1
@@ -33,15 +51,17 @@ commands.add_command('repair', 'Repairs all destoryed and damaged entites in an
local sq_range = range^2
for key, entity in pairs(player.surface.find_entities_filtered({area=area,type='entity-ghost'})) do
if entity.force == player.force and (entity.position.x-center.x)^2+(entity.position.y-center.y)^2 < sq_range then
if disallow[entity.ghost_prototype.name] then
player_return('You have repaired: '..entity.name..' this item is not allowed.',defines.text_color.crit,player)
Admin.temp_ban(player,'<server>','Attempt To Repair A Banned Item')
entity.destroy()
elseif entity.time_to_live ~= max_time_to_live then
entity.revive() end
if disallow[entity.ghost_prototype.name] then repairDisallow(player,entity)
elseif entity.time_to_live ~= max_time_to_live then entity.revive() end
end
end
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
end
end)
return {
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
}

View File

@@ -0,0 +1,24 @@
{
"name": "repair",
"version": "4.0.0",
"type": "Module",
"description": "Allows items to be healed and repaired with a command",
"location": "<blank>",
"keywords": [
"ExpGaming",
"Command",
"Heal",
"Repair",
"Ghosts",
"Revive"
],
"author": "<blank>",
"contact": "<blank>",
"license": "<blank>",
"dependencies": {
"ExpGamingLib": "^4.0.0",
"FactorioStdLib.Game": "^0.8.0",
"ExpGamingCore.Ranking": "^4.0.0",
"ExpGamingAdmin.TempBan": "?^4.0.0"
}
}

View File

@@ -0,0 +1,7 @@
-- not_luadoc=true
local temp_ban = require('ExpGamingAdmin.TempBan')
return function repairDisallow(player,entity)
player_return('You have repaired: '..entity.name..' this item is not allowed.',defines.text_color.crit,player)
temp_ban(player,'<server>','Attempt To Repair A Banned Item')
entity.destroy()
end

View File

@@ -15,7 +15,7 @@ commands.add_command('tag', 'Give yourself a custom tag. Use "" to have more tha
local player = Game.get_player(event)
local rank = Ranking.get_rank(player)
player.tag = rank.tag..' - '..args.tag
player.print('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)
--- Gives you a tag
@@ -27,5 +27,5 @@ commands.add_command('tag-clear', 'Removes a custom tag. Player can be self (/ta
local player = args.player
local rank = Ranking.get_rank(player)
player.tag = rank.tag
player.print('Your tag has been removed.')
player_return('Your tag has been removed.')
end)

View File

@@ -14,6 +14,7 @@
"contact": "<blank>",
"license": "<blank>",
"dependencies": {
"ExpGamingLib": "^4.0.0",
"ExpGamingCore.Ranking": "^4.0.0",
"ExpGamingCore.Commands": "^4.0.0",
"FactorioStdLib.Game": "^0.8.0"

View File

@@ -1,30 +0,0 @@
--[[
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/r6dC2uK
]]
--Please Only Edit Below This Line-----------------------------------------------------------
local const = 20
-- this is the max lenth of a tag
commands.add_command('tag', 'Give yourself a custom tag. Use /tag-clear self to remove tag', {'tag',true}, function(event,args)
local player = Game.get_player(event)
local rank = Ranking.get_rank(player)
if string.len(args.tag) > const then player_return({'commands.invalid-length',const}) return commands.error end
player.tag = rank.tag..' - '..args.tag
end)
commands.add_command('tag-clear', 'Removes a custom tag. Player can be self (/tag-clear self)', {'player'}, function(event,args)
local _player = Game.get_player(event)
local _rank = Ranking.get_rank(_player)
local player = Game.get_player(args.player)
local rank = Ranking.get_rank(player)
if args.player ~= 'self' and not player then player_return({'commands.invalid-player',args.player}) return commands.error end
if args.player == 'self' or _player.name == player.name then _player.tag = _rank.tag
elseif _rank.power < rank.power then player.tag = rank.tag
else player_return({'commands.unauthorized'}) return commands.error end
end)