mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 04:06:39 +09:00
Added ExpGamingCommands.bonus
This commit is contained in:
86
modules/ExpGamingCommands/bonus/control.lua
Normal file
86
modules/ExpGamingCommands/bonus/control.lua
Normal file
@@ -0,0 +1,86 @@
|
||||
--- A full ranking system for factorio.
|
||||
-- @module ExpGamingCommands.kill
|
||||
-- @author Cooldude2606
|
||||
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
|
||||
|
||||
-- these are the settings which are changed with scale being as +100%
|
||||
local settings = {
|
||||
{key='character_mining_speed_modifier',scale=3},
|
||||
{key='character_crafting_speed_modifier',scale=3},
|
||||
{key='character_running_speed_modifier',scale=3},
|
||||
{key='character_build_distance_bonus',scale=20},
|
||||
{key='character_reach_distance_bonus',scale=20},
|
||||
{key='character_inventory_slots_bonus',scale=200}
|
||||
}
|
||||
|
||||
local global = global{}
|
||||
local Game = require('FactorioStdLib.Game')
|
||||
|
||||
--- 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',-1,50} -- -1 < math.floor(bonus) <= 50
|
||||
}, function(event,args)
|
||||
local player = Game.get_player(event)
|
||||
local bonus = args.bonus
|
||||
for _,setting in pairs(settings) do player[setting.key] = setting.scale*math.floor(bonus)*0.01 end
|
||||
global[player.index]=bonus
|
||||
player_return('Bonus set to: '..math.floor(bonus)..'%')
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_player_respawned,function(event)
|
||||
local player = Game.get_player(event)
|
||||
local bonus = global[player.index]
|
||||
if bonus then
|
||||
for _,setting in pairs(settings) do player[setting.key] = setting.scale*math.floor(bonus)*0.01 end
|
||||
end
|
||||
end)
|
||||
|
||||
-- overided by ExpGamingCore.Ranking if present
|
||||
script.on_event(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.Ranking'] then
|
||||
local Ranking = require('ExpGamingCore.Ranking')
|
||||
-- instant respawn
|
||||
script.on_event(defines.events.on_pre_player_died,function(event)
|
||||
local player = Game.get_player(event)
|
||||
if Ranking.get_rank(player):allowed('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
|
||||
Event.dispatch{
|
||||
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
|
||||
script.on_event(defines.events.rank_change,function(event)
|
||||
local player = Game.get_player(event)
|
||||
if event.new_rank:allowed('bonus') then
|
||||
for _,setting in pairs(settings) do player[setting.key] = setting.scale*0.2 end
|
||||
global[player.index]=20
|
||||
else
|
||||
for _,setting in pairs(settings) do player[setting.key] = 0 end
|
||||
global[player.index]=nil
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
}
|
||||
24
modules/ExpGamingCommands/bonus/softmod.json
Normal file
24
modules/ExpGamingCommands/bonus/softmod.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "bonus",
|
||||
"version": "4.0.0",
|
||||
"type": "Module",
|
||||
"description": "Allows a bonus to be applied to players and instant respawn.",
|
||||
"location": "<blank>",
|
||||
"keywords": [
|
||||
"Instant Respawn",
|
||||
"Bonus",
|
||||
"Cheat",
|
||||
"Commands",
|
||||
"ExpGaming",
|
||||
"Respawn"
|
||||
],
|
||||
"author": "<blank>",
|
||||
"contact": "<blank>",
|
||||
"license": "<blank>",
|
||||
"dependencies": {
|
||||
"FactorioStdLib.Game": "^0.8.0",
|
||||
"ExpGamingLib": "^4.0.0",
|
||||
"ExpGamingCore.Commands": "^4.0.0",
|
||||
"ExpGamingCore.Ranking": "?^4.0.0"
|
||||
}
|
||||
}
|
||||
@@ -1,66 +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 settings = {
|
||||
{key='character_mining_speed_modifier',scale=3},
|
||||
{key='character_crafting_speed_modifier',scale=3},
|
||||
{key='character_running_speed_modifier',scale=3},
|
||||
{key='character_build_distance_bonus',scale=20},
|
||||
{key='character_reach_distance_bonus',scale=20},
|
||||
{key='character_inventory_slots_bonus',scale=200}
|
||||
}
|
||||
|
||||
local function _bonus(reset)
|
||||
global.addons = not reset and global.addons or {}
|
||||
global.addons.bonus = not reset and global.addons.bonus or {}
|
||||
return global.addons.bonus
|
||||
end
|
||||
|
||||
commands.add_command('bonus', 'Set your player bonus (default is 20, guest has 0)', {'bonus'}, function(event,args)
|
||||
local player = Game.get_player(event)
|
||||
local bonus = tonumber(args.bonus)
|
||||
if not bonus or bonus < 0 or bonus > 50 then player_return{'commands.invalid-range',0,50} return commands.error end
|
||||
for _,setting in pairs(settings) do player[setting.key] = setting.scale*math.floor(bonus)*0.01 end
|
||||
_bonus()[player.index]=bonus
|
||||
player_return('Bonus set to: '..math.floor(bonus)..'%')
|
||||
end)
|
||||
|
||||
Event.register(defines.events.rank_change,function(event)
|
||||
local player = Game.get_player(event)
|
||||
if event.new_rank:allowed('bonus') then
|
||||
for _,setting in pairs(settings) do player[setting.key] = setting.scale*0.2 end
|
||||
_bonus()[player.index]=20
|
||||
else
|
||||
for _,setting in pairs(settings) do player[setting.key] = 0 end
|
||||
_bonus()[player.index]=nil
|
||||
end
|
||||
end)
|
||||
|
||||
Event.register(defines.events.on_player_respawned,function(event)
|
||||
local player = Game.get_player(event)
|
||||
local bonus = _bonus()[player.index]
|
||||
if bonus then
|
||||
for _,setting in pairs(settings) do player[setting.key] = setting.scale*math.floor(bonus)*0.01 end
|
||||
end
|
||||
end)
|
||||
|
||||
Event.register(defines.events.on_pre_player_died,function(event)
|
||||
local player = Game.get_player(event)
|
||||
if Ranking.get_rank(player):allowed('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
|
||||
Event.dispatch{
|
||||
name=defines.events.on_player_died,
|
||||
tick=event.tick,
|
||||
player_index=event.player_index,
|
||||
cause = event.cause
|
||||
}
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user