Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7bca867
Add persistence plugin
zoephix Feb 14, 2021
2d1c281
lua consistency
TovarischPootis Feb 14, 2021
10a1caf
Removed restrictions plugin alliances
zoephix Feb 14, 2021
b85c570
Update sv_database.lua
zoephix Feb 14, 2021
807d3b1
Merge pull request #7 from TovarischPootis/1.2-wip
zoephix Feb 14, 2021
f774059
Merge pull request #2 from NutScript/1.2-wip
TovarischPootis Feb 14, 2021
6b8d706
Merge pull request #3 from NutScript/1.2-wip
zoephix Feb 14, 2021
026bb68
Merge pull request #5 from Zoephix/1.2-wip
zoephix Feb 14, 2021
cbf0c42
whitespace
TovarischPootis Feb 14, 2021
55b7f54
Merge pull request #9 from TovarischPootis/1.2-wip
TovarischPootis Feb 14, 2021
e1df0db
Merge pull request #4 from NutScript/1.2-wip
zoephix Feb 14, 2021
57cc63e
Update sh_plugin.lua
zoephix Feb 14, 2021
944229f
Merge pull request #10 from Zoephix/1.2-wip
zoephix Feb 14, 2021
c89281d
Revert "Merge pull request #10 from Zoephix/1.2-wip"
zoephix Feb 14, 2021
af829eb
Revert "Update sh_plugin.lua"
zoephix Feb 14, 2021
d038366
Merge pull request #11 from Zoephix/1.2-wip
zoephix Feb 14, 2021
d1856ec
yet another date modification, this time, lightweight
TovarischPootis Feb 14, 2021
e19701e
Removed already defined starting time
zoephix Feb 14, 2021
aeec8d8
Merge pull request #13 from TovarischPootis/1.2-wip
zoephix Feb 14, 2021
6ac649a
Update database configuration loading
zoephix Feb 14, 2021
49d3d0d
Added date migrations
zoephix Feb 14, 2021
37586c4
Added date migrations
zoephix Feb 14, 2021
5855737
Update chatbox icons
zoephix Feb 14, 2021
cd7616b
As suggested, timer runs only on day change rather than every 5 minutes
TovarischPootis Feb 15, 2021
5351bda
Merge pull request #16 from Zoephix/patch-1
TovarischPootis Feb 15, 2021
4a18b06
Merge pull request #17 from Zoephix/patch-2
TovarischPootis Feb 15, 2021
febb183
Merge branch '1.2-wip' into 1.2-wip
TovarischPootis Feb 15, 2021
6c139fc
Merge pull request #15 from Zoephix/1.2-wip
zoephix Feb 15, 2021
2524180
Merge pull request #18 from TovarischPootis/1.2-wip
zoephix Feb 15, 2021
3c92847
Update README.md
zoephix Feb 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
NutScript 1.2 is the continuation of the original NutScript framework to provide a better back-end. This should include more efficient code and overall benefits to the way the framework functioned and/or performed.

## 1.1 vs 1.2
1.2 is the more recent and maintained version of Nutscript, and it is recommended to use it over 1.1
1.2 is the more recent and maintained version of NutScript, and it is recommended to use it over 1.1

## 1.2 vs 1.1-beta
For a few years 1.1-beta was the name of the newest and most updated version of Nutscript. We are now confident to rename it to 1.2, as the modern stable release of Nutscript.
Nutscript 1.2 is actively worked on by community developers, and will see numerous new updates and features added.
For a few years 1.1-beta was the name of the newest and most updated version of NutScript. We are now confident to rename it to 1.2, as the modern stable release of NutScript.
NutScript 1.2 is actively worked on by community developers, and will see numerous new updates and features added.

## 1.2 vs 1.2-wip
the default 1.2 branch will always be the stable release. If you wish to test new releases before they are integrated into the stable branch, you can opt for 1.2-wip. Be aware that 1.2-wip may have bugs and issues.

## Documentation
Check out the Nutscript wiki at https://nutscript.miraheze.org/wiki/Main_Page
Check out the NutScript wiki at https://nutscript.miraheze.org/wiki/Main_Page

## Got more questions?
Nutscript's official Discord server: https://discord.gg/QUbmYuD
NutScript's official Discord server: https://discord.gg/QUbmYuD
52 changes: 0 additions & 52 deletions gamemode/config/sv_database.lua

This file was deleted.

2 changes: 1 addition & 1 deletion gamemode/core/hooks/sv_hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ Issues with ULX/Ulib on your server will be ignored and we're
going to consider that you're taking the risk of ULX/Ulib's
critical performance issue.

Nutscript 1.1 only displays this message when you have ULX or
Nutscript 1.2 only displays this message when you have ULX or
ULib on your server.

-Nutscript Development Team
Expand Down
2 changes: 1 addition & 1 deletion gamemode/core/libs/sh_character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (SERVER) then
if (not nut.db) then
include("sv_database.lua")
end

-- Fetches all the character names and stores
-- them into a table so they only have to be fetched once
if (#nut.char.names < 1) then
Expand Down
16 changes: 10 additions & 6 deletions gamemode/core/libs/sh_chatbox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,19 @@ do
end,
onChatAdd = function(speaker, text)
local icon = "icon16/user.png"

-- man, I did all that works and I deserve differnet icon on ooc chat
local customIcons = {
["STEAM_0:1:34930764"] = "icon16/script_gear.png", -- Chessnut
["STEAM_0:0:19814083"] = "icon16/gun.png", -- Black Tea the edgiest man
["STEAM_0:0:50197118"] = "icon16/script_gear.png", -- Zoephix
["STEAM_0:1:55088012"] = "icon16/script_gear.png" -- TovarischPootis
}

-- man, I did all that works and I deserve different icon on ooc chat
-- if you dont like it
-- well..
-- it's on your own.
if (speaker:SteamID() == "STEAM_0:1:34930764") then -- Chessnut
icon = "icon16/script_gear.png"
elseif (speaker:SteamID() == "STEAM_0:0:19814083") then -- Black Tea the edgiest man
icon = "icon16/gun.png"
if (customIcons[speaker:SteamID()]) then
icon = customIcons[speaker:SteamID()]
elseif (speaker:IsSuperAdmin()) then
icon = "icon16/shield.png"
elseif (speaker:IsAdmin()) then
Expand Down
232 changes: 83 additions & 149 deletions gamemode/core/libs/sh_date.lua
Original file line number Diff line number Diff line change
@@ -1,180 +1,114 @@
---------------------------------------------------------------------------------------
-- Module for date and time calculations
--
-- Version 2.1.2
-- Copyright (C) 2006, by Jas Latrix ([email protected])
-- Copyright (C) 2013-2014, by Thijs Schreijer
-- Licensed under MIT, http://opensource.org/licenses/MIT
-- https://github.com/Tieske/date
-- The MIT License (MIT) http://opensource.org/licenses/MIT

-- Copyright (c) 2013-2017 Thijs Schreijer
-- Copyright (c) 2018 Alexander Grist-Hucker, Igor Radovanovic

-- lib based on Helix by Alexander Grist-Hucker, Igor Radovanovic 2018

-- due to UNIX time, normal os.time() cannnot be set before 1970, as 1st Jan 1970 is 0
-- the library fixes said issue.


nut.date = nut.date or {}
nut.date.lib = nut.date.lib or include("thirdparty/sh_date.lua")
nut.date.timeScale = nut.date.timeScale or nut.config.get("secondsPerMinute", 60)
nut.date.dateObj = nut.date.dateObj or nut.date.lib()
nut.date.start = nut.date.start or CurTime()

if (not nut.config) then
include("nutscript/gamemode/core/sh_config.lua")
include("nutscript/gamemode/core/sh_config.lua")
end

nut.config.add("year", 2021, "The starting year of the schema.", function(oldValue, newValue)
if (SERVER and not nut.date.saving) then
nut.date.update()
nut.date.dateObj:setyear(newValue)
nut.date.sync()
end
end, {
data = {min = 0, max = 4000},
category = "date"
})
nut.config.add("year", tonumber(os.date("%Y")), "The current year of the schema." , nil, {
data = {min = 0, max = 4000},
category = "date"
}
)

nut.config.add("month", 1, "The starting month of the schema.", function(oldValue, newValue)
if (SERVER and not nut.date.saving) then
nut.date.update()
nut.date.dateObj:setmonth(newValue)
nut.date.sync()
end
end, {
data = {min = 1, max = 12},
category = "date"
})
nut.config.add("month", tonumber(os.date("%m")), "The current month of the schema." , nil, {
data = {min = 1, max = 12},
category = "date"
}
)

nut.config.add("day", 1, "The starting day of the schema.", function(oldValue, newValue)
if (SERVER and not nut.date.saving) then
nut.date.update()
nut.date.dateObj:setday(newValue)
nut.date.sync()
end
end, {
data = {min = 1, max = 31},
category = "date"
})

nut.config.add("secondsPerMinute", 60, "How many real life seconds it takes for a minute to pass in-game.", function(oldValue, newValue)
if (SERVER and not nut.date.saving) then
nut.date.updateTimescale(newValue)
nut.date.sync()
end
end, {
data = {min = 0.01, max = 120},
category = "date"
})
nut.config.add("day", tonumber(os.date("%d")), "The current day of the schema." , nil, {
data = {min = 1, max = 31},
category = "date"
}
)

nut.config.add("yearAppendix", "", "Add a custom appendix to your date, if you use a non-conventional calender", nil, {
data = {form = "Generic"},
category = "date"
})

if (SERVER) then
util.AddNetworkString("nutDateSync")

-- called upon server startup. Grabs the saved date data, or creates a new date instance, and sets it as the date object
function nut.date.initialize()
local currentDate = nut.data.get("date", nil, false, true)
-- If we don't have date data already, use current defaults to create a new date data table
if (not currentDate) then
currentDate = {
year = nut.config.get("year"),
month = nut.config.get("month"),
day = nut.config.get("day"),
hour = tonumber(os.date("%H")) or 0,
min = tonumber(os.date("%M")) or 0,
sec = tonumber(os.date("%S")) or 0,
}

currentDate = nut.date.lib.serialize(nut.date.lib(currentDate))

nut.data.set("date", currentDate, false, true) -- save the new data
end
}
)

nut.date.timeScale = nut.config.get("secondsPerMinute", 60)
nut.date.dateObj = nut.date.lib.construct(currentDate) -- update the date object with the initialized data
end
-- function returns a number that represents the custom time. the year is always the current year for
-- compatibility, though it can be editted with nut.date.getFormatted

-- Called when date values have been manually changed, updating the date object.
function nut.date.update()
nut.date.dateObj = nut.date.get()
nut.date.start = CurTime()
end
function nut.date.get()
return os.time({
year=os.date("%Y"),
month=nut.config.get("month"),
day=nut.config.get("day"),
hour=os.date("%H"),
min=os.date("%M"),
sec=os.date("%S")
})
end

-- This is an internal function that sets the amount of real life seconds in an ingame minute. While you can use this function,
--you probably shouldn't, and rather use the ingame config.
function nut.date.updateTimescale(secondsPerMinute)
nut.date.update()
nut.date.timeScale = secondsPerMinute
end
--function takes the time number if provided, or current time and applies a string format to it

--Syncs the current date with the client/s. This allows the players to have proper date representation, such as in the F1menu.
function nut.date.sync(client)
net.Start("nutDateSync")
net.WriteFloat(nut.date.timeScale)
net.WriteTable(nut.date.dateObj)
net.WriteFloat(nut.date.start)

if (client) then
net.Send(client)
else
net.Broadcast()
end
end
function nut.date.getFormatted(format, dateNum)
return os.date(format, dateNum or nut.date.get())
end

-- saves the current in-game date data.
function nut.date.save()
nut.date.saving = true -- prevents from the function from being called before it finishes.
if SERVER then

nut.date.update()
-- This is internal, though you can use it you probably shouldn't.
-- Checks the time difference between the old time values and current time, and updates month and day to advance in the time difference
-- creates a timer that updates the month and day values, in case the server runs continuously without restarts.
function nut.date.initialize()

nut.data.set("date", nut.date.lib.serialize(nut.date.dateObj), false, true) -- saves the current data object
-- Migrations
if (istable(nut.data.get("date", os.time(), true))) then
nut.data.set("date", os.time(), true, true)
end

-- update config to reflect current saved date
nut.config.set("year", nut.date.dateObj:getyear())
nut.config.set("month", nut.date.dateObj:getmonth())
nut.config.set("day", nut.date.dateObj:getday())
local configTime = os.time({
year = tonumber(os.date("%Y")),
month = tonumber(nut.config.get("month")),
day = tonumber(nut.config.get("day")),
hour = tonumber(os.date("%H")),
min = os.date("%M"),
sec = os.date("%S")
}) + os.difftime(os.time(), nut.data.get("date", os.time(), true))

nut.config.set("month", tonumber(os.date("%m", configTime)))
nut.config.set("day", tonumber(os.date("%d", configTime)))

-- internal function that calculates when the day ends, and updates the month/day when the next day comes.
-- the reason for this complication instead of just upvaluing day/month by 1 is that some months have 28, 30 or 31 days.
-- and its simpler for the server to decide what the next month should be rather than manually computing that
local function updateDateConfigs()
local curDateTable = os.date("*t") -- get the current date table
local remainingSeconds = (curDateTable.hour * -3600 - curDateTable.min * 60 - curDateTable.sec) % 86400 -- get the remaining seconds until the new day

timer.Simple(remainingSeconds, function() -- run this code only once the day changes
local newTime = os.time({
year = tonumber(os.date("%Y")),
month = tonumber(nut.config.get("month")),
day = tonumber(nut.config.get("day")),
hour = tonumber(os.date("%H")),
min = os.date("%M"),
sec = os.date("%S")
}) + 86400 -- 24 hours.

nut.config.set("month", tonumber(os.date("%m", newTime)))
nut.config.set("day", tonumber(os.date("%d", newTime)))
updateDateConfigs() -- create a new timer for the next day
end)
end

nut.date.saving = nil -- allows the date to be saved again
updateDateConfigs()
end
else
net.Receive("nutDateSync", function() -- set the clientside values to the updated serverside date values
nut.date.timeScale = net.ReadFloat()
nut.date.dateObj = nut.date.lib.construct(net.ReadTable())
nut.date.start = net.ReadFloat()
print("synced")
PrintTable(nut.date.dateObj)
end)
end

--- Returns the currently set date.
function nut.date.get()
-- CurTime increases in value by 1 every second. By getting the difference in seconds between now and the date object initialization,
local minutesSinceStart = (CurTime() - nut.date.start) / nut.date.timeScale --and divide it by the timescale, we get the minutes elapsed to add to the date start

return nut.date.dateObj:copy():addminutes(minutesSinceStart)
end

--- Returns a string formatted version of a date.
function nut.date.getFormatted(format, currentDate)
return (currentDate or nut.date.get()):fmt(format)
end
-- saves the current actual time. This allows the time to find the difference in elapsed time between server shutdown and startup
function nut.date.save()
nut.data.set("date", os.time(), true, true)
end

if SERVER then
hook.Add("InitializedSchema", "nutInitializeTime", function()
hook.Add("InitializedConfig", "nutInitializeTime", function()
nut.date.initialize()
end)

hook.Add("PlayerInitialSpawn", "nutDateSync", function(client)
nut.date.sync(client)
end)

hook.Add("SaveData", "nutDateSave", function()
nut.date.save()
end)
Expand Down
Loading