Skip to content

Commit

Permalink
update + fix
Browse files Browse the repository at this point in the history
  • Loading branch information
notderpaul committed Mar 10, 2024
1 parent 814699a commit ade88b5
Show file tree
Hide file tree
Showing 9 changed files with 449 additions and 187 deletions.
515 changes: 330 additions & 185 deletions AddictScript/Addict.lua

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion AddictScript/AddictScriptChangelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
________________________
v1.46
v1.47
[+] Added Config System (for selected options & only a few for now) // Credits to WiriScript
[+] Addded 'Save Config' Button
[!] Fixed Error when loading Addicted
[!] Code Cleanup
________________________

Report any Bugs/Broken features on the Discord
2 changes: 1 addition & 1 deletion AddictScript/AddictScriptVersion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.46
1.47
14 changes: 14 additions & 0 deletions AddictScript/lib/addict/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
config = {
objgun = {
expl = false
},
net_lists = {
explodeloop = false
},
explosion_other_net_list = {
explosionblamed = false,
explosionaudible = true,
explosionvisible = true,
explosiondamage = true
}
}
100 changes: 100 additions & 0 deletions AddictScript/lib/addict/ini.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
-- Credits to WiriScript --

json = require "pretty.json"

--------------------------
-- FILE
--------------------------

ini = {}

-- Saves a table with key-value pairs in an INI format file.
-- @param fileName string - The name of the file to save.
-- @param obj table - The table containing key-value pairs to be saved in the INI file.
function ini.save(fileName, obj)
local file, err = io.open(fileName, "w")
if not file then
error("Error opening file: " .. err)
end

local sections = {}

for section, tbl in pairs(obj) do
assert(type(tbl) == "table", "Expected field " .. section .. " to be a table, got " .. type(tbl))

local lines = {}
table.insert(lines, string.format("[%s]", section))

for k, v in pairs(tbl) do
table.insert(lines, string.format("%s=%s", k, v))
end

table.insert(sections, table.concat(lines, '\n') .. '\n')
end

file:write(table.concat(sections, '\n'))
file:close()
end

-- Parses a table from an INI format file.
-- @param fileName string - The name of the file to load.
-- @return table - The parsed table from the INI file.
function ini.load(fileName)
assert(type(fileName) == "string", "fileName must be a string")

local file, err = io.open(fileName, "r")
if not file then
error("Error loading file: " .. err)
end

local data = {}
local section

for line in file:lines() do
local tempSection = string.match(line, '^%[([^%]]+)%]$')

if tempSection ~= nil then
section = tonumber(tempSection) and tonumber(tempSection) or tempSection
data[section] = data[section] or {}
end

local param, value = string.match(line, '^([%w_]+)%s*=%s*(.+)$')
if section ~= nil and param and value ~= nil then
if value == "true" then
value = true
elseif value == "false" then
value = false
elseif tonumber(value) then
value = tonumber(value)
end
data[section][tonumber(param) or param] = value
end
end

file:close()
return data
end

local parseJson = json.parse

-- Parses a JSON file and returns the parsed content.
-- @param filePath string - The path to the JSON file.
-- @param withoutNull? boolean - Optional parameter to exclude null values.
-- @return boolean - Indicates success or failure of parsing.
-- @return string|table - If successful, returns the parsed JSON content, otherwise an error message.
json.parse = function(filePath, withoutNull)
local file, err = io.open(filePath, "r")
if not file then
return false, err
end

local content = file:read("a")
local fileName = string.match(filePath, '^.+[\\/](.+)')
if #content == 0 then
file:close()
return false, fileName .. " is empty"
end

file:close()
return pcall(parseJson, content, withoutNull)
end
Binary file removed AddictScript/resources/addictscript/bruh.wav
Binary file not shown.
File renamed without changes.

0 comments on commit ade88b5

Please sign in to comment.