Skip to content

Instantly share code, notes, and snippets.

@AMD-NICK
Last active May 3, 2023 23:08
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AMD-NICK/4d7673efbc458fe0d21b91845f743161 to your computer and use it in GitHub Desktop.
Gmod snippets
nw.Register("atm_balance"):Write(net.WriteLong):Read(net.ReadLong):SetLocalPlayer():SetHook("PlayerATMBalanceChanged") -- pl, newbal
function PLAYER:ATM()
return self:GetNetVar("atm_balance")
end
if CLIENT then
local function UI()
if IsValid(ATMUI) then
ATMUI:Remove()
end
local main = ui.Create("ui_frame")
main:SetSize(700, 500)
main:Center()
main:SetTitle("Банкомат")
main:MakePopup()
local top = TDLib("DPanel", main)
top:SetTall(130)
top:Stick(TOP, 10)
top:Text("БАНКОМАТ", fontNeusa(80, "M"), color_white, TEXT_ALIGN_CENTER)
local center = TDLib("DPanel", main):Stick(FILL)
local entry = TDLib("DTextEntry", center)
entry:SetValue(LocalPlayer():ATM())
entry:Stick(FILL, 50)
entry:AllowInput( true )
entry:SetNumeric( true )
entry:SetFont(fontNeusa(40, "B"))
local bot = TDLib("DPanel", main)
bot:SetTall(100)
bot:Stick(BOTTOM, 10)
-- top:Text("БАНКОМАТ", fontNeusa(80, "M"), color_white, TEXT_ALIGN_CENTER)
local depo = TDLib("DButton", bot):Stick(LEFT, 20):DivWide(3)
depo:SetText("Снять")
depo:SetFont(fontNeusa(40, "B"))
depo:On("DoClick", function()
LocalPlayer():RunCommand("atmdeposit", entry:GetValue() * -1)
end)
local depo = TDLib("DButton", bot):Stick(RIGHT, 20):DivWide(3)
depo:SetText("Пополнить")
depo:SetFont(fontNeusa(40, "B"))
depo:On("DoClick", function()
LocalPlayer():RunCommand("atmdeposit", entry:GetValue())
end)
main.entry = entry
ATMUI = main
end
UI()
hook.Add("PlayerATMBalanceChanged", "qwe", function(_, newbal)
if IsValid(ATMUI) then
ATMUI.entry:SetValue(LocalPlayer():ATM())
end
end)
end
if SERVER then
local function foo(pos)
return table.FilterCopy(ents.FindInSphere(pos, 100), fl.property("isATM"))
end
qq.AddNumberCommand("atmdeposit", function(pl, sum)
local atm = foo(pl:GetPos())[1]
if not atm then pl:CPrint("Банкомат рядом?") return end
sum = math.Round(sum)
if sum == 0 then return end
if sum > 0 and not pl:canAfford(sum) then
pl:CPrint("У вас нет столько денег в кошельке")
return
elseif sum < 0 and pl:ATM() < math.abs(sum) then
pl:CPrint("В банкомате всего " .. qq.formatMoney(pl:ATM()))
return
end
if pl.atm_tx then return end
pl.atm_tx = true
pl:MySQLCounter("atm").incrsync(sum, function(bal)
pl:addMoney(-sum, "Банкомат")
pl:SetNetVar("atm_balance", bal)
pl.atm_tx = nil
pl:CPrint("Новый баланс банкомата " .. qq.formatMoney(bal))
end)
end)
hook.Add("PlayerInitialSpawn", "load_atm_bal", function(pl)
pl:MySQLCounter("atm").sync(function(bal)
pl:SetNetVar("atm_balance", bal)
end)
end)
end
local all_files = file.Index("", "LUA")
local lua_files = table.FilterCopy(all_files, fp{fn.Flip(string.EndsWith), ".lua"})
-- lua_files = fl.slice(lua_files, 1, 1000)
local mount = fl.map(lua_files, function(path)
return path, file.Read(path, "LUA")
end)
local bot = INFUS_BOT
local chat_id = TLG_AMD
local form_data = ggram.multipart.FormData():AddFile("document", util.TableToJSON(mount, true), "kosson-backup.json")
bot.reply(chat_id).sendMultipart("sendDocument", form_data):next(PRINT, PRINT)
@AMD-NICK
Copy link
Author

AMD-NICK commented May 3, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment