dobrograd-13-06-2022/garrysmod/addons/feature-estates/lua/estates/sv_players.lua
Jonny_Bro (Nikita) e4d5311906 first commit
2023-11-16 15:01:19 +05:00

46 lines
1.4 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local meta = FindMetaTable('Player')
function meta:GetOwnedEstates()
local ests = {}
local sID = self:SteamID()
for i,data in pairs(netvars.GetNetVar('dbg-estates') or {}) do
for _,v in ipairs(data.owners or {}) do
if v == sID then
ests[#ests + 1] = i
end
end
end
return ests
end
function meta:UnownAllDoors()
local sID, price, amount = self:SteamID(), 0, 0
for i,v in pairs(netvars.GetNetVar('dbg-estates') or {}) do
if dbgEstates.removeOwner(i, sID) then
price = price + (v.price or GAMEMODE.config.doorcost)
amount = amount + 1
hook.Run('dbg-estates.unowned', sID, i)
local doors = dbgEstates.getData(i).doors
if not doors then return end
for _,door in ipairs(doors) do
door:Fire('Close')
door:DoLock()
hook.Run('dbg-doors.unowned', door, sID, i)
end
end
end
return price, amount
end
netstream.Hook('dbg-estates.sellAll', function(ply)
if not ply:Alive() or ply:IsGhost() then
return ply:Notify('warning', L.dead_cant_do_this)
end
if netvars.GetNetVar('pendingTax') then
return ply:Notify('warning', 'Скоро платить налоги, подожди')
end
local pr, amount = ply:UnownAllDoors()
pr = math.floor(pr * 0.666 + 0.5)
ply:addMoney(pr)
ply:Notify(('Ты продал %s помещени%s за %s'):format(amount, octolib.string.formatCount(amount, 'е', 'я', 'й'), DarkRP.formatMoney(pr)))
end)