GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #12 from NutScript/revert-8-1.2 · NutScript/NutScript@23446c3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • entities/entities
    • nut_item.lua
  • gamemode/core
    • libs
      • sh_date.lua
      • thirdparty
        • sh_date.lua
    • meta/item
      • sv_item.lua
    • sh_util.lua
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎entities/entities/nut_item.lua‎

Copy file name to clipboardExpand all lines: entities/entities/nut_item.lua
+7-13Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ ENT.RenderGroup = RENDERGROUP_BOTH
99

1010
if (SERVER) then
1111
function ENT:Initialize()
12-
--self:SetModel("models/props_junk/watermelon01.mdl")
13-
--self:SetSolid(SOLID_VPHYSICS)
14-
--self:PhysicsInit(SOLID_VPHYSICS)
12+
self:SetModel("models/props_junk/watermelon01.mdl")
13+
self:SetSolid(SOLID_VPHYSICS)
14+
self:PhysicsInit(SOLID_VPHYSICS)
1515
self:SetCollisionGroup(COLLISION_GROUP_WEAPON)
1616
self.health = 50
1717

@@ -51,20 +51,14 @@ if (SERVER) then
5151
and "models/props_junk/cardboard_box004a.mdl"
5252
or itemTable.worldModel
5353
end
54-
self:SetModel(model or "models/props_junk/watermelon01.mdl")
55-
self:SetSkin(itemTable.skin or 0)
56-
57-
if itemTable.groups then -- this has to be done after the model is set, hence why it looks a little messy
58-
for k, v in pairs(itemTable.groups) do
59-
if isstring(k) then k = self:FindBodygroupByName(k) end
60-
self:SetBodygroup(k, v)
61-
end
62-
end
6354

55+
self:SetSkin(itemTable.skin or 0)
56+
self:SetModel(model)
6457
self:PhysicsInit(SOLID_VPHYSICS)
6558
self:SetSolid(SOLID_VPHYSICS)
6659
self:setNetVar("id", itemTable.uniqueID)
6760
self.nutItemID = itemID
61+
6862
if (table.Count(itemTable.data) > 0) then
6963
self:setNetVar("data", itemTable.data)
7064
end
@@ -211,4 +205,4 @@ function ENT:getData(key, default)
211205
return default
212206
end
213207
return data[key]
214-
end
208+
end
Collapse file

‎gamemode/core/libs/sh_date.lua‎

Copy file name to clipboard
+153-27Lines changed: 153 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,181 @@
1+
---------------------------------------------------------------------------------------
2+
-- Module for date and time calculations
3+
--
4+
-- Version 2.1.2
5+
-- Copyright (C) 2006, by Jas Latrix ([email protected])
6+
-- Copyright (C) 2013-2014, by Thijs Schreijer
7+
-- Licensed under MIT, http://opensource.org/licenses/MIT
8+
-- https://github.com/Tieske/date
9+
-- The MIT License (MIT) http://opensource.org/licenses/MIT
10+
11+
-- Copyright (c) 2013-2017 Thijs Schreijer
12+
-- Copyright (c) 2018 Alexander Grist-Hucker, Igor Radovanovic
13+
14+
-- lib based on Helix by Alexander Grist-Hucker, Igor Radovanovic 2018
15+
16+
-- due to UNIX time, normal os.time() cannnot be set before 1970, as 1st Jan 1970 is 0
17+
-- the library fixes said issue.
18+
19+
120
nut.date = nut.date or {}
2-
nut.date.cache = nut.date.cache or {}
3-
nut.date.start = nut.date.start or os.time()
21+
nut.date.lib = nut.date.lib or include("thirdparty/sh_date.lua")
22+
nut.date.timeScale = nut.date.timeScale or nut.config.get("secondsPerMinute", 60)
23+
nut.date.dateObj = nut.date.dateObj or nut.date.lib()
24+
nut.date.start = nut.date.start or CurTime()
425

5-
if (!nut.config) then
26+
if (not nut.config) then
627
include("nutscript/gamemode/core/sh_config.lua")
728
end
829

9-
nut.config.add("year", 2015, "The starting year of the schema.", nil, {
30+
nut.config.add("year", 2021, "The starting year of the schema.", function(oldValue, newValue)
31+
if (SERVER and not nut.date.saving) then
32+
nut.date.update()
33+
nut.date.dateObj:setyear(newValue)
34+
nut.date.sync()
35+
end
36+
end, {
1037
data = {min = 0, max = 4000},
1138
category = "date"
1239
})
1340

14-
nut.config.add("month", 1, "The starting month of the schema.", nil, {
41+
nut.config.add("month", 1, "The starting month of the schema.", function(oldValue, newValue)
42+
if (SERVER and not nut.date.saving) then
43+
nut.date.update()
44+
nut.date.dateObj:setmonth(newValue)
45+
nut.date.sync()
46+
end
47+
end, {
1548
data = {min = 1, max = 12},
1649
category = "date"
1750
})
1851

19-
nut.config.add("day", 1, "The starting day of the schema.", nil, {
52+
nut.config.add("day", 1, "The starting day of the schema.", function(oldValue, newValue)
53+
if (SERVER and not nut.date.saving) then
54+
nut.date.update()
55+
nut.date.dateObj:setday(newValue)
56+
nut.date.sync()
57+
end
58+
end, {
2059
data = {min = 1, max = 31},
2160
category = "date"
2261
})
2362

63+
nut.config.add("secondsPerMinute", 60, "How many real life seconds it takes for a minute to pass in-game.", function(oldValue, newValue)
64+
if (SERVER and not nut.date.saving) then
65+
nut.date.updateTimescale(newValue)
66+
nut.date.sync()
67+
end
68+
end, {
69+
data = {min = 0.01, max = 120},
70+
category = "date"
71+
})
72+
73+
nut.config.add("yearAppendix", "", "Add a custom appendix to your date, if you use a non-conventional calender", nil, {
74+
data = {form = "Generic"},
75+
category = "date"
76+
})
77+
2478
if (SERVER) then
25-
function nut.date.get()
26-
local unixTime = os.time()
79+
util.AddNetworkString("nutDateSync")
2780

28-
return (unixTime - (nut.date.start or unixTime)) + os.time({
29-
year = nut.config.get("year"),
30-
month = nut.config.get("month"),
31-
day = nut.config.get("day")
32-
})
81+
-- called upon server startup. Grabs the saved date data, or creates a new date instance, and sets it as the date object
82+
function nut.date.initialize()
83+
local currentDate = nut.data.get("date", nil, false, true)
84+
-- If we don't have date data already, use current defaults to create a new date data table
85+
if (not currentDate) then
86+
currentDate = {
87+
year = nut.config.get("year"),
88+
month = nut.config.get("month"),
89+
day = nut.config.get("day"),
90+
hour = tonumber(os.date("%H")) or 0,
91+
min = tonumber(os.date("%M")) or 0,
92+
sec = tonumber(os.date("%S")) or 0,
93+
}
94+
95+
currentDate = nut.date.lib.serialize(nut.date.lib(currentDate))
96+
97+
nut.data.set("date", currentDate, false, true) -- save the new data
98+
end
99+
100+
nut.date.timeScale = nut.config.get("secondsPerMinute", 60)
101+
nut.date.dateObj = nut.date.lib.construct(currentDate) -- update the date object with the initialized data
33102
end
34103

35-
function nut.date.send(client)
36-
netstream.Start(client, "dateSync", CurTime(), os.time() - nut.date.start)
104+
-- Called when date values have been manually changed, updating the date object.
105+
function nut.date.update()
106+
nut.date.dateObj = nut.date.get()
107+
nut.date.start = CurTime()
37108
end
38-
else
39-
function nut.date.get()
40-
local realTime = RealTime()
41109

42-
-- Add the starting time + offset + current time played.
43-
return nut.date.start + os.time({
44-
year = nut.config.get("year"),
45-
month = nut.config.get("month"),
46-
day = nut.config.get("day")
47-
}) + (realTime - (nut.joinTime or realTime))
110+
-- This is an internal function that sets the amount of real life seconds in an ingame minute. While you can use this function,
111+
--you probably shouldn't, and rather use the ingame config.
112+
function nut.date.updateTimescale(secondsPerMinute)
113+
nut.date.update()
114+
nut.date.timeScale = secondsPerMinute
48115
end
49116

50-
netstream.Hook("dateSync", function(curTime, offset)
51-
offset = offset + (CurTime() - curTime)
117+
--Syncs the current date with the client/s. This allows the players to have proper date representation, such as in the F1menu.
118+
function nut.date.sync(client)
119+
net.Start("nutDateSync")
120+
net.WriteFloat(nut.date.timeScale)
121+
net.WriteTable(nut.date.dateObj)
122+
net.WriteFloat(nut.date.start)
123+
124+
if (client) then
125+
net.Send(client)
126+
else
127+
net.Broadcast()
128+
end
129+
end
130+
131+
-- saves the current in-game date data.
132+
function nut.date.save()
133+
nut.date.saving = true -- prevents from the function from being called before it finishes.
134+
135+
nut.date.update()
136+
137+
nut.data.set("date", nut.date.lib.serialize(nut.date.dateObj), false, true) -- saves the current data object
138+
139+
-- update config to reflect current saved date
140+
nut.config.set("year", nut.date.dateObj:getyear())
141+
nut.config.set("month", nut.date.dateObj:getmonth())
142+
nut.config.set("day", nut.date.dateObj:getday())
143+
144+
nut.date.saving = nil -- allows the date to be saved again
145+
end
146+
else
147+
net.Receive("nutDateSync", function() -- set the clientside values to the updated serverside date values
148+
nut.date.timeScale = net.ReadFloat()
149+
nut.date.dateObj = nut.date.lib.construct(net.ReadTable())
150+
nut.date.start = net.ReadFloat()
151+
print("synced")
152+
PrintTable(nut.date.dateObj)
153+
end)
154+
end
155+
156+
--- Returns the currently set date.
157+
function nut.date.get()
158+
-- CurTime increases in value by 1 every second. By getting the difference in seconds between now and the date object initialization,
159+
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
160+
161+
return nut.date.dateObj:copy():addminutes(minutesSinceStart)
162+
end
163+
164+
--- Returns a string formatted version of a date.
165+
function nut.date.getFormatted(format, currentDate)
166+
return (currentDate or nut.date.get()):fmt(format)
167+
end
168+
169+
if SERVER then
170+
hook.Add("InitializedSchema", "nutInitializeTime", function()
171+
nut.date.initialize()
172+
end)
173+
174+
hook.Add("PlayerInitialSpawn", "nutDateSync", function(client)
175+
nut.date.sync(client)
176+
end)
52177

53-
nut.date.start = offset
178+
hook.Add("SaveData", "nutDateSave", function()
179+
nut.date.save()
54180
end)
55181
end

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.