ежедневная и крафты

This commit is contained in:
heyshawtyy committed 2026-11-19 13:46:05 +05:00
1 parent 828297cc6a
commit ce8184576e
31 files changed
+3371

No files matched your search

+85
View File
@@ -0,0 +1,85 @@
-- Daily login (7-day cycle) and playtime (9 tiers per day) rewards. Data: PlayerData.Rewards(player).
-- Attributes for the UI: RW_LoginDay (gifts claimed in total), RW_LoginReady (today's gift not claimed yet),
-- RW_PlaySec (seconds played today), RW_PlayClaimed (bit i-1 = playtime tier i claimed today).
-- Day = UTC date (00:00 UTC = 03:00 MSK). A missed day does not reset the cycle.
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local folder = RS:WaitForChild("OrnamentMachine")
local Config = require(folder:WaitForChild("Config"))
local PD = require(script.Parent:WaitForChild("OrnamentPlayerData"))
local R = Config.REWARDS
local TICK = 10
local remote = folder:FindFirstChild("RewardsRemote") or Instance.new("RemoteFunction")
remote.Name = "RewardsRemote"
remote.Parent = folder
local function today() return os.date("!%Y-%m-%d") end
local function state(player)
local r = PD.Rewards(player)
if not r then return nil end
local t = today()
if r.PlayDate ~= t then r.PlayDate, r.PlaySec, r.PlayClaimed = t, 0, 0 end
return r
end
local function publish(player, r)
player:SetAttribute("RW_LoginDay", r.LoginDay)
player:SetAttribute("RW_LoginReady", r.LoginDate ~= today())
player:SetAttribute("RW_PlaySec", r.PlaySec)
player:SetAttribute("RW_PlayClaimed", r.PlayClaimed)
end
local function grant(player, g)
if g.Shards then PD.AddShards(player, g.Shards) end
for id, n in g.Boosters or {} do PD.AddBooster(player, id, n) end
if g.XP then PD.AddXP(player, g.XP) end
end
local function claimed(mask, i) return math.floor(mask / 2 ^ (i - 1)) % 2 == 1 end
remote.OnServerInvoke = function(player, action, idx)
local r = state(player)
if not r then return false, "Not loaded yet" end
if action == "Login" then
if r.LoginDate == today() then return false, "Come back tomorrow" end
local day = r.LoginDay % #R.LOGIN + 1
grant(player, R.LOGIN[day])
r.LoginDay += 1
r.LoginDate = today()
elseif action == "Play" then
idx = tonumber(idx)
local tier = idx and R.PLAYTIME[idx]
if not tier then return false end
if claimed(r.PlayClaimed, idx) then return false, "Already claimed" end
if r.PlaySec < tier.Minutes * 60 then return false, "Keep playing" end
grant(player, tier)
r.PlayClaimed += 2 ^ (idx - 1)
else
return false
end
PD.MarkDirty(player)
publish(player, r)
return true
end
local function onJoin(player)
local t0 = os.clock()
repeat task.wait(0.5) until PD.Get(player) or not player.Parent or os.clock() - t0 > 60
local r = player.Parent and state(player)
if r then publish(player, r) end
end
Players.PlayerAdded:Connect(onJoin)
for _, p in Players:GetPlayers() do task.spawn(onJoin, p) end
-- playtime: +TICK seconds for every player in the game
task.spawn(function()
while true do
task.wait(TICK)
for _, p in Players:GetPlayers() do
local r = state(p)
if r then
r.PlaySec += TICK
PD.MarkDirty(p)
publish(p, r)
end
end
end
end)
+210
View File
@@ -0,0 +1,210 @@
-- Rewards window (same look as the Workshop: ShopKit chrome, ray cards, pill buttons): daily login gifts (7-day
-- cycle) + playtime gifts (9 tiers per day). HUD button = a copy of the Workshop button with the gift art and a red
-- badge with the number of gifts ready. Server: OrnamentRewardsServer (RW_* player attributes, RewardsRemote).
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local folder = RS:WaitForChild("OrnamentMachine")
local Config = require(folder:WaitForChild("Config"))
local remote = folder:WaitForChild("RewardsRemote")
local K = require(player:WaitForChild("PlayerScripts"):WaitForChild("OrnamentCraftUI"):WaitForChild("ShopKit"))
local R = Config.REWARDS
local new, art, label, maxText = K.new, K.art, K.label, K.maxText
local GOLD, WHITE, SOFT = K.GOLD, K.WHITE, K.SOFT
local function attr(k, d) local v = player:GetAttribute(k); if v == nil then return d end return v end
local function rewardLines(g)
local t = {}
if g.Shards then table.insert(t, { string.format("+%d shards", g.Shards), Color3.fromRGB(150, 230, 255) }) end
for _, id in { "Luck2", "Luck3" } do
local n = g.Boosters and g.Boosters[id]
if n then table.insert(t, { string.format(id == "Luck2" and "+%d Luck x2" or "+%d Luck x3", n), id == "Luck2" and Color3.fromRGB(150, 255, 160) or GOLD }) end
end
if g.XP then table.insert(t, { string.format("+%d XP", g.XP), Color3.fromRGB(255, 190, 255) }) end
return t
end
local function timeText(m)
if m < 60 then return string.format("%d min", m) end
if m % 60 == 0 then return string.format("%d h", m // 60) end
return string.format("%d h %d min", m // 60, m % 60)
end
local function iconOf(g)
if g.Boosters and g.Boosters.Luck3 then return "🍀" elseif g.Boosters then return "☘️" elseif (g.Shards or 0) >= 100 then return "💎" end
return "❄️"
end
---------------------------------------------------------------- window (design canvas 1400 x 1000, scaled to the screen)
local gui = new("ScreenGui", { Name = "RewardsGui", ResetOnSpawn = false, DisplayOrder = 30, Enabled = false, IgnoreGuiInset = true,
ZIndexBehavior = Enum.ZIndexBehavior.Sibling, Parent = player:WaitForChild("PlayerGui") })
local overlay = new("TextButton", { Text = "", AutoButtonColor = false, Size = UDim2.fromScale(1, 1), BackgroundColor3 = Color3.new(0, 0, 0),
BackgroundTransparency = 0.45, Parent = gui })
local panel = new("Frame", { AnchorPoint = Vector2.new(0.5, 0.5), Position = UDim2.fromScale(0.5, 0.53), Size = UDim2.fromOffset(1400, 1000),
BackgroundTransparency = 1, Parent = overlay })
local uiScale = new("UIScale", { Parent = panel })
local function rescale()
local v = workspace.CurrentCamera.ViewportSize
uiScale.Scale = math.min(v.X / 1480, v.Y / 1120)
end
rescale(); workspace.CurrentCamera:GetPropertyChangedSignal("ViewportSize"):Connect(rescale)
local refresh
local function closeWin() gui.Enabled = false end
overlay.Activated:Connect(function() end)
local ch = K.chrome({
win = { panel = panel, overlay = overlay }, title = "Rewards", subtitle = "Gifts for coming in and for playing",
tabs = {
{ id = "Daily", text = "Daily login", icon = "📅", tip = "Come in every day for a gift! Missing a day doesn't reset your progress." },
{ id = "Play", text = "Playtime", icon = "⏰", tip = "" },
},
closeWindow = closeWin, fmtNum = function(v) return tostring(math.floor(v + 0.5)) end,
onTab = function() if refresh then refresh() end end,
})
ch.setBalance(attr("Shards", 0), true)
player:GetAttributeChangedSignal("Shards"):Connect(function() ch.setBalance(attr("Shards", 0)) end)
local busy = false
local function claim(action, idx, pill)
if busy then return end
busy = true
pill.set("busy")
local ok, res = pcall(function() return remote:InvokeServer(action, idx) end)
busy = false
if ok and res then K.floatText(pill.button.Parent, "🎁", GOLD) end
refresh()
end
-- a gift card: ray card art, title, big icon, reward lines, pill button
local function card(page, x, y, w, h, title, g, big, onClick)
local c = art(big and "cardViolet" or "cardOrange", { Position = UDim2.fromOffset(x, y), Size = UDim2.fromOffset(w, h),
ScaleType = Enum.ScaleType.Slice, SliceCenter = K.CARD_SLICE, ZIndex = 5, Parent = page })
maxText(label({ Position = UDim2.fromOffset(14, 22), Size = UDim2.new(1, -28, 0, 40), Text = title, TextScaled = true, TextColor3 = GOLD,
TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = c }, 2.5), 34)
label({ Position = UDim2.fromOffset(14, 62), Size = UDim2.new(1, -28, 0, 58), Text = iconOf(g), TextScaled = true,
TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = c }, 0)
local lines = rewardLines(g)
local lh = math.min(30, 84 / #lines)
for i, ln in lines do
maxText(label({ Position = UDim2.fromOffset(10, 124 + (i - 1) * lh), Size = UDim2.new(1, -20, 0, lh - 2), Text = ln[1], TextScaled = true,
TextColor3 = ln[2], TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = c }, 2), 26)
end
local pill
pill = K.pill(c, { Position = UDim2.new(0, 16, 1, -70), Size = UDim2.new(1, -32, 0, 56), ZIndex = 7, TextMax = 26 }, function() onClick(pill) end)
return { frame = c, pill = pill }
end
local dailyPage = ch.makePage("Daily")
local dailyCards = {}
for i, g in R.LOGIN do
local row, col = (i - 1) // 4, (i - 1) % 4
local x = row == 0 and col * 315 or 157 + col * 315
dailyCards[i] = card(dailyPage, x, row * 288, 300, 276, string.format("Day %d", i), g, i == #R.LOGIN, function(p) claim("Login", nil, p) end)
end
local playPage = ch.makePage("Play")
local playCards = {}
for i, g in R.PLAYTIME do
local row, col = (i - 1) // 5, (i - 1) % 5
local x = row == 0 and col * 255 or 127 + col * 255
playCards[i] = card(playPage, x, row * 288, 240, 276, timeText(g.Minutes), g, i == #R.PLAYTIME, function(p) claim("Play", i, p) end)
end
---------------------------------------------------------------- state -> cards
local playAt = os.clock()
player:GetAttributeChangedSignal("RW_PlaySec"):Connect(function() playAt = os.clock() end)
local function playSec() return attr("RW_PlaySec", 0) + math.min(os.clock() - playAt, 10) end
local function untilMidnight()
local t = os.date("!*t")
return 86400 - (t.hour * 3600 + t.min * 60 + t.sec)
end
local function countdown(s)
s = math.max(0, math.floor(s))
if s >= 3600 then return string.format("in %d:%02d:%02d", s // 3600, s // 60 % 60, s % 60) end
return string.format("in %d:%02d", s // 60, s % 60)
end
local function isClaimed(mask, i) return math.floor(mask / 2 ^ (i - 1)) % 2 == 1 end
local function counts()
local daily = attr("RW_LoginReady", false) and 1 or 0
local mask, sec, play = attr("RW_PlayClaimed", 0), playSec(), 0
for i, g in R.PLAYTIME do if not isClaimed(mask, i) and sec >= g.Minutes * 60 then play += 1 end end
return daily, play
end
local function setCard(cd, state, text)
if cd.pill.state ~= "busy" or not busy then cd.pill.set(state, text) end
cd.frame.ImageTransparency = state == "done" and 0.35 or 0
end
function refresh()
local total, ready, n = attr("RW_LoginDay", 0), attr("RW_LoginReady", false), #R.LOGIN
local done = total % n
if not ready and done == 0 and total > 0 then done = n end
for i, cd in dailyCards do
if i <= done then setCard(cd, "done", "Claimed")
elseif i == done + 1 and ready then setCard(cd, "ready", "Claim")
elseif i == done + 1 then setCard(cd, "off", countdown(untilMidnight()))
else setCard(cd, "off", (i == done + 2 and not ready) and "Tomorrow" or string.format("Day %d", i)) end
end
local mask, sec = attr("RW_PlayClaimed", 0), playSec()
for i, cd in playCards do
local need = R.PLAYTIME[i].Minutes * 60
if isClaimed(mask, i) then setCard(cd, "done", "Claimed")
elseif sec >= need then setCard(cd, "ready", "Claim")
else setCard(cd, "off", countdown(need - sec)) end
end
local d, p = counts()
ch.tabs.Daily.setBadge(d); ch.tabs.Play.setBadge(p)
if ch.current() == "Play" then
local s = math.floor(sec)
ch.tip.Text = string.format("Today's playtime: %d:%02d · resets at 00:00 UTC", s // 3600, s // 60 % 60)
end
end
local function open(tab)
gui.Enabled = true
ch.showTab(tab or (attr("RW_LoginReady", false) and "Daily" or ch.current() or "Daily"), true)
panel.Position = UDim2.fromScale(0.5, 0.56)
K.tween(panel, 0.25, { Position = UDim2.fromScale(0.5, 0.53) }, Enum.EasingStyle.Back)
refresh()
end
---------------------------------------------------------------- HUD button (copy of the Workshop button, gift art)
task.spawn(function()
local menu = player.PlayerGui:WaitForChild("OrnamentCraftGui"):WaitForChild("Hud"):WaitForChild("Menu")
local tpl = menu:WaitForChild("WorkshopButton", 30)
if not tpl then return end
local b = tpl:Clone()
b.Name = "RewardsButton"
b.LayoutOrder = 999
local badge, strip
for _, d in b:GetDescendants() do
if d:IsA("TextLabel") and d.Text == "Workshop" then d.Text = "Rewards"
elseif d:IsA("TextLabel") and d.Parent:IsA("Frame") and d.Parent.BackgroundTransparency < 0.5 then badge = d -- red count circle
elseif d:IsA("ImageLabel") then
-- own 3-state strip (normal / hover / pressed), made from the Shop button art: GUI\HUD\button-states-v2\rewards-states.png
d.Image = "rbxassetid://127792380990286"
strip = d
end
end
b.Parent = menu
b.Activated:Connect(function() if gui.Enabled then closeWin() else open() end end)
if strip then -- show frame 1 / 2 / 3 of the strip like the other HUD buttons
local hover, down = false, false
local function paint() strip.Position = UDim2.fromScale(down and -2 or hover and -1 or 0, 0) end
b.MouseEnter:Connect(function() hover = true; paint() end)
b.MouseLeave:Connect(function() hover, down = false, false; paint() end)
b.MouseButton1Down:Connect(function() down = true; paint() end)
b.MouseButton1Up:Connect(function() down = false; paint() end)
paint()
end
while true do
local d, p = counts()
if badge then
badge.Text = tostring(d + p)
local box = badge.Parent
if box and box:IsA("GuiObject") and box ~= b then box.Visible = d + p > 0 else badge.Visible = d + p > 0 end
end
if gui.Enabled then refresh() end
task.wait(1)
end
end)
-- today's login gift waiting -> open the window a few seconds after joining
task.delay(6, function()
if attr("RW_LoginReady", false) and not gui.Enabled then open("Daily") end
end)
+74
View File
@@ -0,0 +1,74 @@
# Installs the rewards system into the open place via Studio MCP (Config, PlayerData, LangRU edits + 2 new scripts)
import json, os, subprocess, sys
HERE = os.path.dirname(os.path.abspath(__file__)); TOOLS = os.path.dirname(HERE)
SID = "0411fa4a-b0e9-4eb3-8d9b-e8e08277ee91"
def call(tool, args):
a = os.path.join(TOOLS, "args_rw.json"); json.dump({**args, "studio_id": SID, "datamodel_type": "Edit"}, open(a, "w", encoding="utf-8"), ensure_ascii=False)
r = subprocess.run([sys.executable, os.path.join(TOOLS, "rbx.py"), tool, a], capture_output=True, text=True, encoding="utf-8")
print(tool, args.get("file_path"), "->", ((r.stdout or "") + (r.stderr or "")).strip()[:300])
E = lambda o, n: {"old_string": o, "new_string": n}
CONFIG = '''---------------------------------------------------------------- rewards: daily login + playtime (OrnamentRewardsServer)
-- LOGIN: a 7-day cycle, one gift per UTC day (a missed day does not reset it). PLAYTIME: per UTC day, Minutes played.
Config.REWARDS = {
LOGIN = {
{ Shards = 30 },
{ Boosters = { Luck2 = 1 } },
{ Shards = 60 },
{ Boosters = { Luck2 = 2 } },
{ Shards = 100, XP = 50 },
{ Boosters = { Luck3 = 1 } },
{ Shards = 200, Boosters = { Luck3 = 1 }, XP = 100 },
},
PLAYTIME = {
{ Minutes = 15, Shards = 15 },
{ Minutes = 30, Shards = 25 },
{ Minutes = 45, Boosters = { Luck2 = 1 } },
{ Minutes = 60, Shards = 50 },
{ Minutes = 90, Boosters = { Luck2 = 2 } },
{ Minutes = 120, Shards = 80, XP = 50 },
{ Minutes = 150, Boosters = { Luck3 = 1 } },
{ Minutes = 180, Shards = 120 },
{ Minutes = 240, Shards = 200, Boosters = { Luck3 = 1 }, XP = 100 },
},
}
---------------------------------------------------------------- premium shop (Robux, Developer Products)'''
PD_FUN = '''---------------------------------------------------------------- daily login / playtime rewards (OrnamentRewardsServer)
function PlayerData.Rewards(player)
local p = profiles[player]
if not p then return nil end
local r = p.data.Rewards
if type(r) ~= "table" then r = {}; p.data.Rewards = r end
r.LoginDay = tonumber(r.LoginDay) or 0
r.LoginDate = type(r.LoginDate) == "string" and r.LoginDate or ""
r.PlayDate = type(r.PlayDate) == "string" and r.PlayDate or ""
r.PlaySec = tonumber(r.PlaySec) or 0
r.PlayClaimed = tonumber(r.PlayClaimed) or 0
return r
end
-- marks the profile for saving without re-publishing every attribute (playtime ticks)
function PlayerData.MarkDirty(player)
local p = profiles[player]
if p then p.dirty = true end
end
---------------------------------------------------------------- settings'''
RU = [("Rewards", "Награды"), ("🎁 Rewards", "🎁 Награды"), ("Daily login", "Вход каждый день"), ("Playtime", "Время в игре"),
("Day %d", "День %s"), ("%d min", "%s мин"), ("%d h", "%s ч"), ("%d h %d min", "%s ч %s мин"),
("+%d shards", "+%s осколков"), ("+%d Luck x2", "+%s Удача x2"), ("+%d Luck x3", "+%s Удача x3"), ("+%d XP", "+%s опыта"),
("Claim", "Забрать"), ("Claimed", "Получено"), ("Tomorrow", "Завтра"),
("in %d:%02d", "через %s:%s"), ("in %d:%02d:%02d", "через %s:%s:%s"),
("Come in every day for a gift! Missing a day doesn't reset your progress.", "Заходи каждый день за подарком! Пропуск дня не сбрасывает прогресс."),
("Today's playtime: %d:%02d · resets at 00:00 UTC", "Сегодня в игре: %s:%s · обнуляется в 03:00 МСК")]
call("multi_edit", {"file_path": "game.ReplicatedStorage.OrnamentMachine.Config", "edits": [
E("---------------------------------------------------------------- premium shop (Robux, Developer Products)", CONFIG)]})
call("multi_edit", {"file_path": "game.ServerScriptService.OrnamentPlayerData", "edits": [
E('\t\tSettings = { Master = 1, Music = 1, Effects = 1, UI = 1, MusicOn = true, Lang = "auto" },\n\t}\nend',
'\t\tSettings = { Master = 1, Music = 1, Effects = 1, UI = 1, MusicOn = true, Lang = "auto" },\n'
'\t\tRewards = { LoginDay = 0, LoginDate = "", PlayDate = "", PlaySec = 0, PlayClaimed = 0 }, -- OrnamentRewardsServer\n\t}\nend'),
E("---------------------------------------------------------------- settings\n-- partial update", PD_FUN.replace("---------------------------------------------------------------- settings", "---------------------------------------------------------------- settings\n-- partial update"))]})
call("multi_edit", {"file_path": "game.ReplicatedStorage.OrnamentMachine.LangRU", "edits": [
E('return {\n\t{ "Common", "Обычная" },', 'return {\n' + "".join('\t{ "%s", "%s" },\n' % p for p in RU) + '\t{ "Common", "Обычная" },')]})
for path, cls, fn in (("game.ServerScriptService.OrnamentRewardsServer", "Script", "RewardsServer.server.luau"),
("game.StarterPlayer.StarterPlayerScripts.RewardsUI", "LocalScript", "RewardsUI.client.luau")):
call("multi_edit", {"file_path": path, "className": cls, "edits": [E("", open(os.path.join(HERE, fn), encoding="utf-8").read())]})