Added bonus

This commit is contained in:
Cooldude2606
2019-06-02 17:19:52 +01:00
parent 4e0e5cd9c9
commit d7befd931b
5 changed files with 80 additions and 4 deletions

View File

@@ -23,6 +23,7 @@ return {
'modules.commands.spawn',
'modules.commands.warnings',
'modules.commands.find',
'modules.commands.bonus',
-- QoL Addons
'modules.addons.chat-popups',
'modules.addons.damage-popups',

9
config/bonuses.lua Normal file
View 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}
}

View File

@@ -34,6 +34,7 @@ Roles.new_role('System','SYS')
:set_flag('is_admin')
:set_flag('is_spectator')
:set_flag('report-immune')
:set_flag('instance-respawn')
:set_allow_all()
Roles.new_role('Senior Administrator','SAdmin')
@@ -41,6 +42,7 @@ Roles.new_role('Senior Administrator','SAdmin')
:set_flag('is_admin')
:set_flag('is_spectator')
:set_flag('report-immune')
:set_flag('instance-respawn')
:set_parent('Administrator')
:allow{
'command/interface',
@@ -54,6 +56,7 @@ Roles.new_role('Administrator','Admin')
:set_flag('is_admin')
:set_flag('is_spectator')
:set_flag('report-immune')
:set_flag('instance-respawn')
:set_parent('Moderator')
:allow{
}
@@ -64,6 +67,7 @@ Roles.new_role('Moderator','Mod')
:set_flag('is_admin')
:set_flag('is_spectator')
:set_flag('report-immune')
:set_flag('instance-respawn')
:set_parent('Trainee')
:allow{
'command/assign-role',
@@ -76,6 +80,7 @@ Roles.new_role('Moderator','Mod')
'command/clear-warnings',
'command/clear-temp-ban',
'command/clear-inventory',
'command/bonus',
'gui/rocket-info/toggle-active',
'gui/rocket-info/remote_launch',
}
@@ -106,6 +111,7 @@ Roles.new_role('Sponsor','Spon')
:set_custom_color{r=247,g=246,b=54}
:set_flag('is_spectator')
:set_flag('report-immune')
:set_flag('instance-respawn')
:set_parent('Pay to Win')
:allow{
}
@@ -115,6 +121,7 @@ Roles.new_role('Pay to Win','P2W')
:set_custom_color{r=238,g=172,b=44}
:set_flag('is_spectator')
:set_flag('report-immune')
:set_flag('instance-respawn')
:set_parent('Donator')
:allow{
'gui/rocket-info/toggle-active',

View File

@@ -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
-- @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
-- @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
@@ -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
-- @treturn Commands._prototype pass through to allow more functions to be called
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
self.params[name] = {
optional=optional,
parse=parse,
parse_args={...}
parse_args=parse_args
}
self.max_param_count = self.max_param_count+1
if not optional then

View File

@@ -1,4 +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'
Commands.new_command('bonus','Changes the amount of bonus you receive')
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)