mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-01-01 05:01:40 +09:00
Merge pull request #99 from Cooldude2606/feature/bonus-basic
Basic bonus command added
This commit is contained in:
@@ -23,6 +23,7 @@ return {
|
|||||||
'modules.commands.spawn',
|
'modules.commands.spawn',
|
||||||
'modules.commands.warnings',
|
'modules.commands.warnings',
|
||||||
'modules.commands.find',
|
'modules.commands.find',
|
||||||
|
'modules.commands.bonus',
|
||||||
-- QoL Addons
|
-- QoL Addons
|
||||||
'modules.addons.chat-popups',
|
'modules.addons.chat-popups',
|
||||||
'modules.addons.damage-popups',
|
'modules.addons.damage-popups',
|
||||||
|
|||||||
9
config/bonuses.lua
Normal file
9
config/bonuses.lua
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
--- Lists all bonuses which can be used, name followed by min max
|
||||||
|
return {
|
||||||
|
character_mining_speed_modifier={0,3},
|
||||||
|
character_crafting_speed_modifier={0,3},
|
||||||
|
character_running_speed_modifier={0,3},
|
||||||
|
character_build_distance_bonus={0,20},
|
||||||
|
character_reach_distance_bonus={0,20},
|
||||||
|
character_inventory_slots_bonus={0,200}
|
||||||
|
}
|
||||||
@@ -34,6 +34,7 @@ Roles.new_role('System','SYS')
|
|||||||
:set_flag('is_admin')
|
:set_flag('is_admin')
|
||||||
:set_flag('is_spectator')
|
:set_flag('is_spectator')
|
||||||
:set_flag('report-immune')
|
:set_flag('report-immune')
|
||||||
|
:set_flag('instance-respawn')
|
||||||
:set_allow_all()
|
:set_allow_all()
|
||||||
|
|
||||||
Roles.new_role('Senior Administrator','SAdmin')
|
Roles.new_role('Senior Administrator','SAdmin')
|
||||||
@@ -41,6 +42,7 @@ Roles.new_role('Senior Administrator','SAdmin')
|
|||||||
:set_flag('is_admin')
|
:set_flag('is_admin')
|
||||||
:set_flag('is_spectator')
|
:set_flag('is_spectator')
|
||||||
:set_flag('report-immune')
|
:set_flag('report-immune')
|
||||||
|
:set_flag('instance-respawn')
|
||||||
:set_parent('Administrator')
|
:set_parent('Administrator')
|
||||||
:allow{
|
:allow{
|
||||||
'command/interface',
|
'command/interface',
|
||||||
@@ -54,6 +56,7 @@ Roles.new_role('Administrator','Admin')
|
|||||||
:set_flag('is_admin')
|
:set_flag('is_admin')
|
||||||
:set_flag('is_spectator')
|
:set_flag('is_spectator')
|
||||||
:set_flag('report-immune')
|
:set_flag('report-immune')
|
||||||
|
:set_flag('instance-respawn')
|
||||||
:set_parent('Moderator')
|
:set_parent('Moderator')
|
||||||
:allow{
|
:allow{
|
||||||
}
|
}
|
||||||
@@ -64,6 +67,7 @@ Roles.new_role('Moderator','Mod')
|
|||||||
:set_flag('is_admin')
|
:set_flag('is_admin')
|
||||||
:set_flag('is_spectator')
|
:set_flag('is_spectator')
|
||||||
:set_flag('report-immune')
|
:set_flag('report-immune')
|
||||||
|
:set_flag('instance-respawn')
|
||||||
:set_parent('Trainee')
|
:set_parent('Trainee')
|
||||||
:allow{
|
:allow{
|
||||||
'command/assign-role',
|
'command/assign-role',
|
||||||
@@ -76,6 +80,7 @@ Roles.new_role('Moderator','Mod')
|
|||||||
'command/clear-warnings',
|
'command/clear-warnings',
|
||||||
'command/clear-temp-ban',
|
'command/clear-temp-ban',
|
||||||
'command/clear-inventory',
|
'command/clear-inventory',
|
||||||
|
'command/bonus',
|
||||||
'gui/rocket-info/toggle-active',
|
'gui/rocket-info/toggle-active',
|
||||||
'gui/rocket-info/remote_launch',
|
'gui/rocket-info/remote_launch',
|
||||||
}
|
}
|
||||||
@@ -106,6 +111,7 @@ Roles.new_role('Sponsor','Spon')
|
|||||||
:set_custom_color{r=247,g=246,b=54}
|
:set_custom_color{r=247,g=246,b=54}
|
||||||
:set_flag('is_spectator')
|
:set_flag('is_spectator')
|
||||||
:set_flag('report-immune')
|
:set_flag('report-immune')
|
||||||
|
:set_flag('instance-respawn')
|
||||||
:set_parent('Pay to Win')
|
:set_parent('Pay to Win')
|
||||||
:allow{
|
:allow{
|
||||||
}
|
}
|
||||||
@@ -115,10 +121,12 @@ Roles.new_role('Pay to Win','P2W')
|
|||||||
:set_custom_color{r=238,g=172,b=44}
|
:set_custom_color{r=238,g=172,b=44}
|
||||||
:set_flag('is_spectator')
|
:set_flag('is_spectator')
|
||||||
:set_flag('report-immune')
|
:set_flag('report-immune')
|
||||||
|
:set_flag('instance-respawn')
|
||||||
:set_parent('Donator')
|
:set_parent('Donator')
|
||||||
:allow{
|
:allow{
|
||||||
'gui/rocket-info/toggle-active',
|
'gui/rocket-info/toggle-active',
|
||||||
'gui/rocket-info/remote_launch',
|
'gui/rocket-info/remote_launch',
|
||||||
|
'command/bonus',
|
||||||
}
|
}
|
||||||
|
|
||||||
Roles.new_role('Donator','Don')
|
Roles.new_role('Donator','Don')
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ end
|
|||||||
|
|
||||||
--- Adds a new param to the command this will be displayed in the help and used to parse the input
|
--- Adds a new param to the command this will be displayed in the help and used to parse the input
|
||||||
-- @tparam string name the name of the new param that is being added to the command
|
-- @tparam string name the name of the new param that is being added to the command
|
||||||
-- @tparam[opt=true] boolean optional is this param required for this command, these must be after all required params
|
-- @tparam[opt=false] boolean optional is this param required for this command, these must be after all required params
|
||||||
-- @tparam[opt=pass function through] ?string|function parse this function will take the input and return a new (or same) value
|
-- @tparam[opt=pass function through] ?string|function parse this function will take the input and return a new (or same) value
|
||||||
-- @param[opt] ... extra args you want to pass to the parse function; for example if the parse is general use
|
-- @param[opt] ... extra args you want to pass to the parse function; for example if the parse is general use
|
||||||
-- parse param - input: string - the input given by the user for this param
|
-- parse param - input: string - the input given by the user for this param
|
||||||
@@ -436,12 +436,17 @@ end
|
|||||||
-- parse return - the value that will be passed to the command callback, must not be nil and if reject then command is not run
|
-- parse return - the value that will be passed to the command callback, must not be nil and if reject then command is not run
|
||||||
-- @treturn Commands._prototype pass through to allow more functions to be called
|
-- @treturn Commands._prototype pass through to allow more functions to be called
|
||||||
function Commands._prototype:add_param(name,optional,parse,...)
|
function Commands._prototype:add_param(name,optional,parse,...)
|
||||||
if optional ~= false then optional = true end
|
local parse_args = {...}
|
||||||
|
if type(optional) ~= 'boolean' then
|
||||||
|
parse_args = {parse,...}
|
||||||
|
parse = optional
|
||||||
|
optional = false
|
||||||
|
end
|
||||||
parse = parse or function(string) return string end
|
parse = parse or function(string) return string end
|
||||||
self.params[name] = {
|
self.params[name] = {
|
||||||
optional=optional,
|
optional=optional,
|
||||||
parse=parse,
|
parse=parse,
|
||||||
parse_args={...}
|
parse_args=parse_args
|
||||||
}
|
}
|
||||||
self.max_param_count = self.max_param_count+1
|
self.max_param_count = self.max_param_count+1
|
||||||
if not optional then
|
if not optional then
|
||||||
|
|||||||
58
modules/commands/bonus.lua
Normal file
58
modules/commands/bonus.lua
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
local Commands = require 'expcore.commands'
|
||||||
|
local Roles = require 'expcore.roles'
|
||||||
|
local Event = require 'utils.event'
|
||||||
|
local Game = require 'utils.game'
|
||||||
|
local Store = require 'expcore.store'
|
||||||
|
local config = require 'config.bonuses'
|
||||||
|
require 'config.expcore-commands.parse_general'
|
||||||
|
|
||||||
|
local bonus_store =
|
||||||
|
Store.register(function(value,category)
|
||||||
|
local player = Game.get_player_from_any(category)
|
||||||
|
for bonus,min_max in pairs(config) do
|
||||||
|
local increase = min_max[2]*value
|
||||||
|
player[bonus] = min_max[1]+increase
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
Commands.new_command('bonus','Changes the amount of bonus you receive')
|
||||||
|
:add_param('amount','integer-range',0,50)
|
||||||
|
:register(function(player,amount)
|
||||||
|
local percent = amount/100
|
||||||
|
Store.set(bonus_store,player.name,percent)
|
||||||
|
end)
|
||||||
|
|
||||||
|
Event.add(defines.events.on_player_respawned,function(event)
|
||||||
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
|
local value = Store.get(bonus_store,player.name)
|
||||||
|
if value then
|
||||||
|
for bonus,min_max in pairs(config) do
|
||||||
|
local increase = min_max[2]*value
|
||||||
|
player[bonus] = min_max[1]+increase
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
Event.add(defines.events.on_pre_player_died,function(event)
|
||||||
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
|
if Roles.player_has_flag(player,'instance-respawn') then
|
||||||
|
player.ticks_to_respawn = 120
|
||||||
|
-- manually dispatch death event because it is not fired when ticks_to_respawn is set pre death
|
||||||
|
Event.dispatch{
|
||||||
|
name=defines.events.on_player_died,
|
||||||
|
tick=event.tick,
|
||||||
|
player_index=event.player_index,
|
||||||
|
cause = event.cause
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
local function role_update(event)
|
||||||
|
local player = Game.get_player_by_index(event.player_index)
|
||||||
|
if not Roles.player_allowed(player,'command/bonus') then
|
||||||
|
Store.clear(bonus_store,player.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Event.add(Roles.player_role_assigned,role_update)
|
||||||
|
Event.add(Roles.player_role_unassigned,role_update)
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
--- A full ranking system for factorio.
|
|
||||||
-- @module ExpGamingCommands.bonus@^4.0.0
|
|
||||||
-- @author Cooldude2606
|
|
||||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
|
||||||
|
|
||||||
local global = {}
|
|
||||||
Global.register(global,function(tbl) global = tbl end)
|
|
||||||
local Game = require('FactorioStdLib.Game')
|
|
||||||
|
|
||||||
-- these are the settings which are changed with scale being as +100%
|
|
||||||
local settings = {
|
|
||||||
character_mining_speed_modifier=3,
|
|
||||||
character_crafting_speed_modifier=3,
|
|
||||||
character_running_speed_modifier=3,
|
|
||||||
character_build_distance_bonus=20,
|
|
||||||
character_reach_distance_bonus=20,
|
|
||||||
character_inventory_slots_bonus=200
|
|
||||||
}
|
|
||||||
|
|
||||||
--- Allows a player to set there bonus
|
|
||||||
-- @command bonus
|
|
||||||
-- @param bonus the amount of bonus there will get
|
|
||||||
commands.add_command('bonus', 'Set your player bonus (default is 20, guest has 0)', {
|
|
||||||
['bonus'] = {true,'number-range-int',-1,50} -- -1 < math.floor(bonus) <= 50
|
|
||||||
}, function(event,args)
|
|
||||||
local player = Game.get_player(event)
|
|
||||||
local bonus = args.bonus
|
|
||||||
for key,setting in pairs(settings) do player[key] = setting*math.floor(bonus)*0.01 end
|
|
||||||
global[player.index]=bonus
|
|
||||||
player_return('Bonus set to: '..math.floor(bonus)..'%')
|
|
||||||
end).default_admin_only = true
|
|
||||||
|
|
||||||
Event.add(defines.events.on_player_respawned,function(event)
|
|
||||||
local player = Game.get_player(event)
|
|
||||||
local bonus = global[player.index]
|
|
||||||
if bonus then
|
|
||||||
for key,setting in pairs(settings) do player[key] = setting*math.floor(bonus)*0.01 end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- overridden by ExpGamingCore.Role if present
|
|
||||||
Event.add(defines.events.on_pre_player_died,function(event)
|
|
||||||
local player = Game.get_player(event)
|
|
||||||
if player.admin then
|
|
||||||
player.ticks_to_respawn = 120
|
|
||||||
-- manually dispatch death event because it is not fired when ticks_to_respawn is set pre death
|
|
||||||
Event.dispatch{
|
|
||||||
name=defines.events.on_player_died,
|
|
||||||
tick=event.tick,
|
|
||||||
player_index=event.player_index,
|
|
||||||
cause = event.cause
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
return {
|
|
||||||
on_init= function(self)
|
|
||||||
if loaded_modules['ExpGamingCore.Role'] then
|
|
||||||
local Role = require('ExpGamingCore.Role')
|
|
||||||
-- instant respawn
|
|
||||||
Event.add(defines.events.on_pre_player_died,function(event)
|
|
||||||
local player = Game.get_player(event)
|
|
||||||
if Role.allowed(player,'bonus-respawn') then
|
|
||||||
player.ticks_to_respawn = 120
|
|
||||||
-- manually dispatch death event because it is not fired when ticks_to_respawn is set pre death
|
|
||||||
script.raise_event(defines.events.on_player_died,{
|
|
||||||
name=defines.events.on_player_died,
|
|
||||||
tick=event.tick,
|
|
||||||
player_index=event.player_index,
|
|
||||||
cause = event.cause
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
-- either clears or adds default when rank changed
|
|
||||||
Event.add(defines.events.role_change,function(event)
|
|
||||||
local player = Game.get_player(event)
|
|
||||||
if Role.allowed(player,'bonus') then
|
|
||||||
for key,setting in pairs(settings) do player[key] = setting*0.2 end
|
|
||||||
global[player.index]=20
|
|
||||||
else
|
|
||||||
for key in pairs(settings) do player[key] = 0 end
|
|
||||||
global[player.index]=nil
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "ExpGamingCommands.bonus",
|
|
||||||
"version": "4.0.0",
|
|
||||||
"description": "Allows a bonus to be applied to players and instant respawn.",
|
|
||||||
"location": "FSM_ARCHIVE",
|
|
||||||
"keywords": [
|
|
||||||
"Instant Respawn",
|
|
||||||
"Bonus",
|
|
||||||
"Cheat",
|
|
||||||
"Commands",
|
|
||||||
"ExpGaming",
|
|
||||||
"Respawn"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
|
||||||
"FactorioStdLib.Game": "^0.8.0",
|
|
||||||
"ExpGamingLib": "^4.0.0",
|
|
||||||
"ExpGamingCore.Command": "^4.0.0",
|
|
||||||
"ExpGamingCore.Role": "?^4.0.0"
|
|
||||||
},
|
|
||||||
"collection": "ExpGamingCommands@4.0.0",
|
|
||||||
"submodules": {}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user