mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 19:45:22 +09:00
Iterate save using pairs instaid of ipairs, remove erronus require, add save fuction
This commit is contained in:
@@ -141,7 +141,8 @@ Roles.new_role('Sponsor','Spon')
|
||||
'command/home-get',
|
||||
'command/return',
|
||||
'fast-tree-decon',
|
||||
'command/load-quickbar'
|
||||
'command/load-quickbar',
|
||||
'command/save-quickbar'
|
||||
}
|
||||
|
||||
Roles.new_role('Supporter','Sup')
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
--[[-- Commands Module - Quickbar
|
||||
- Adds a command that allows players to load Quickbar presets
|
||||
@commands LoadQuickbar
|
||||
@commands SaveQuickbar
|
||||
]]
|
||||
|
||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
local Game = require 'utils.game' --- @dep utils.game
|
||||
local config = require 'config.preset_player_quickbar' --- @dep config.preset_player_quickbar
|
||||
require 'config.expcore.command_general_parse'
|
||||
|
||||
|
||||
--- Loads your quickbar preset
|
||||
@@ -16,10 +16,29 @@ Commands.new_command('load-quickbar','Loads your preset Quickbar items')
|
||||
:register(function(player)
|
||||
if config[player.name] then
|
||||
local custom_quickbar = config[player.name]
|
||||
for i, item_name in ipairs(custom_quickbar) do
|
||||
player.set_quick_bar_slot(i, item_name)
|
||||
for i, item_name in pairs(custom_quickbar) do
|
||||
if item_name ~= nil and item_name ~= '' then
|
||||
player.set_quick_bar_slot(i, item_name)
|
||||
end
|
||||
end
|
||||
else
|
||||
Commands.error('Quickbar preset not found')
|
||||
end
|
||||
end)
|
||||
|
||||
--- Saves your quickbar preset to the script-output folder
|
||||
-- @command save-quickbar
|
||||
Commands.new_command('save-quickbar','Saves your Quickbar preset items to file')
|
||||
:register(function(player)
|
||||
local quickbar_names = {}
|
||||
for i=1, 100 do
|
||||
local slot = player.get_quick_bar_slot(i)
|
||||
if slot ~= nil then
|
||||
table.insert(quickbar_names, slot.name)
|
||||
else
|
||||
table.insert(quickbar_names, "")
|
||||
end
|
||||
end
|
||||
game.write_file("quickbar_preset.txt", game.table_to_json(quickbar_names), false)
|
||||
Commands.print("Quickbar saved to local script-output folder")
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user