Diff
checker
文本
文本
图像
文档
Excel
文件夹
Legal
Enterprise
桌面版
定价
登录
下载 Diffchecker 桌面版
比较文本
查找两个文本文件之间的差异
工具
历史
实时编辑器
隐藏空白更改
折叠未更改行
关闭换行
视图
拆分
统一
比对精度
智能
单词
字符
文本样式
更改外观
语法高亮
选择语法
忽略
文本转换
转到第一个差异
编辑输入
Diffchecker Desktop
运行Diffchecker最安全的方式。获取Diffchecker桌面应用:您的差异永远不会离开您的电脑!
获取桌面版
Untitled diff
创建于
11年前
差异永不过期
清除
导出
分享
解释
113 删除
行
总计
删除
字符
总计
删除
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
150 行
全部复制
477 添加
行
总计
添加
字符
总计
添加
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
506 行
全部复制
复制
已复制
复制
已复制
util.AddNetworkString("DarkRP_PlayerVar")
util.AddNetworkString("DarkRP_UpdateDoorData")
util.AddNetworkString("DarkRP_RemoveDoorData")
util.AddNetworkString("DarkRP_AllDoorData")
/*---------------------------------------------------------------------------
/*---------------------------------------------------------------------------
复制
已复制
复制
已复制
Interface f
unctions
F
unctions
---------------------------------------------------------------------------*/
---------------------------------------------------------------------------*/
复制
已复制
复制
已复制
local eMeta = FindMetaTable("Entity")
function
m
eta:
keysLock
()
function
eM
eta:
getDoorData
()
self:Fire("lock", "", 0)
if
not
self:
isKeysOwnable()
then return
{}
end
if
isfunction(self.Lock) then
self:
Lock(true) end -- SCars
if IsValid(self.EntOwner) and self.EntOwner ~= self
then return
self.EntOwner:keysLock()
end
-- SCars
复制
已复制
复制
已复制
self.DoorData = self.DoorData or {}
hook.Call("onKeysLocked", nil,
self
)
return
self
.DoorData
end
end
复制
已复制
复制
已复制
function
eM
eta:
setKeysNonOwnable(ownable
)
function
m
eta:
keysUnLock(
)
self:
getDoorData().nonOwnable = ownable
self:
Fire("unlock", "", 0)
DarkRP.updateDoorData
(self
, "nonOwnable")
if isfunction(self.UnLock) then self:UnLock(true) end -- SCars
end
if IsValid
(self
.EntOwner) and self.EntOwner ~= self then return self.EntOwner:keysUnLock()
end
-- SCars
复制
已复制
复制
已复制
function eMeta:setKeysTitle(title)
hook.Call("onKeysUnlocked", nil,
self
)
self:getDoorData().title = title
DarkRP.updateDoorData(
self
, "title"
)
end
end
复制
已复制
复制
已复制
function
eMeta:setDoorGroup(group)
function
meta:keysOwn(ply)
self:getDoorData().groupOwn = group
if self:isKeysAllowedToOwn(ply) then
DarkRP.updateDoorData(self, "
groupOwn")
self:addKeysDoorOwner(ply)
return
end
local Owner = self:CPPIGetOwner()
-- Increase vehicle count
if self:IsVehicle() then
if IsValid(ply) then
ply.Vehicles = ply.Vehicles or 0
ply.Vehicles = ply.Vehicles + 1
end
-- Decrease vehicle count of the original owner
if IsValid(Owner) and Owner ~= ply then
Owner.Vehicles = Owner.Vehicles or 1
Owner.Vehicles = Owner.Vehicles - 1
end
end
if self:IsVehicle() then
self:CPPISetOwner(ply)
end
if not self:isKeysOwned() and not self:isKeysOwnedBy(ply) then
local doorData = self:getDoorData()
doorData.owner = ply
DarkRP.updateDoorData(self, "
owner")
end
if ply:GetTable().OwnedNumz == 0 then
timer.Create(ply:UniqueID() .. "propertytax", 270, 0, function() ply.doPropertyTax(ply) end)
end
ply:GetTable().OwnedNumz = ply:GetTable().OwnedNumz + 1
ply:GetTable().Ownedz[self:EntIndex()] = self
end
end
复制
已复制
复制
已复制
function
eM
eta:
addKeysDoorTeam(t
)
function
m
eta:
keysUnOwn(ply
)
local doorData
= self:
getDoorData()
if not ply then
doorData.teamOwn = doorData.teamOwn or {}
ply
= self:
getDoorOwner()
doorData.teamOwn[t] = true
复制
已复制
复制
已复制
DarkRP.updateDoorData(self, "
teamOwn")
if not IsValid(ply) then return end
end
if self:isMasterOwner(ply) then
local doorData = self:getDoorData()
doorData.owner = nil
DarkRP.updateDoorData(self, "
owner")
else
self:removeKeysDoorOwner(ply)
end
ply:GetTable().Ownedz[self:EntIndex()] = nil
ply:GetTable().OwnedNumz = math.Clamp(ply:GetTable().OwnedNumz - 1, 0, math.huge)
end
end
复制
已复制
复制
已复制
function
eMeta:removeKeysDoorTeam(t)
function
pmeta:keysUnOwnAll()
local doorData = self:getDoorData()
for k, v in pairs(ents.GetAll()) do
doorData.teamOwn = doorData.teamOwn or {}
if v:isKeysOwnable() and v:isKeysOwnedBy(self) == true then
doorData.teamOwn[t] = nil
v:Fire("unlock", "", 0.6)
end
end
复制
已复制
复制
已复制
if
fn.Null(doorData.teamOwn)
then
if
self:GetTable().Ownedz
then
doorData.teamOwn
= nil
for k, v in pairs(self.Ownedz) do
if not v:isKeysOwnable() then self.Ownedz[k] = nil continue end
v:keysUnOwn(self)
self.Ownedz[v:EntIndex()]
= nil
end
end
end
复制
已复制
复制
已复制
DarkRP.updateDoorData(self, "teamOwn")
for k, v in pairs(player.GetAll()) do
if v.Ownedz then
for n, m in pairs(v.Ownedz) do
if IsValid(m) and m:isKeysAllowedToOwn(self) then
m:removeKeysAllowedToOwn(self)
end
end
end
end
self.OwnedNumz = 0
end
end
复制
已复制
复制
已复制
function
eMeta:removeAllKeysDoorTeams
()
function
pmeta:doPropertyTax
()
local doorData =
self:
getDoorData()
if not GAMEMODE.Config.propertytax then return end
doorData.teamOwn = nil
if
self:
isCP() and GAMEMODE.Config.cit_propertytax then return end
复制
已复制
复制
已复制
DarkRP.updateDoorData(self, "teamOwn")
local numowned = self.OwnedNumz
if not numowned or numowned <= 0 then return end
local price = 10
local tax = price * numowned + math.random(-5, 5)
if self:canAfford(tax) then
if tax ~= 0 then
self:addMoney(-tax)
DarkRP.notify(self, 0, 5, DarkRP.getPhrase("property_tax", GAMEMODE.Config.currency .. tax))
end
else
DarkRP.notify(self, 1, 8, DarkRP.getPhrase("property_tax_cant_afford"))
self:keysUnOwnAll()
end
end
end
复制
已复制
复制
已复制
function
eMeta:addKeysAllowedToOwn(ply
)
function
pmeta:initiateTax(
)
local
doorData = self:getDoorData()
local
taxtime = GAMEMODE.Config.wallettaxtime
doorData.allowedToOwn = doorData.allowedToOwn or {}
local uniqueid = self:UniqueID() -- so we can destroy the timer if the player leaves
doorData.allowedToOwn[ply:EntIndex()] = true
timer.Create("rp_tax_"..uniqueid, taxtime or 600, 0, function()
if not IsValid(self) then
timer.Destroy("rp_tax_"..uniqueid)
return
end
复制
已复制
复制
已复制
DarkRP.updateDoorData(self, "allowedToOwn")
if not GAMEMODE.Config.wallettax then
return -- Don't remove the hook in case it's turned on afterwards.
end
local money = self:getDarkRPVar("money")
local mintax = GAMEMODE.Config.wallettaxmin / 100
local maxtax = GAMEMODE.Config.wallettaxmax / 100 -- convert to decimals for percentage calculations
local startMoney = GAMEMODE.Config.startingmoney
if money < (startMoney * 2) then
return -- Don't tax players if they have less than twice the starting amount
end
-- Variate the taxes between twice the starting money ($1000 by default) and 200 - 2 times the starting money (100.000 by default)
local tax = (money - (startMoney * 2)) / (startMoney * 198)
tax = math.Min(maxtax, mintax + (maxtax - mintax) * tax)
self:addMoney(-tax * money)
DarkRP.notify(self, 3, 7, DarkRP.getPhrase("taxday", math.Round(tax * 100, 3)))
end)
end
end
复制
已复制
复制
已复制
function
eMeta:removeKeysAllowedToOwn
(ply)
/*---------------------------------------------------------------------------
local doorData = self:getDoorData()
Commands
doorData.allowedToOwn = doorData.allowedToOwn or {}
---------------------------------------------------------------------------*/
doorData.allowedToOwn[ply:EntIndex()] = nil
local time = false
local
function
SetDoorOwnable
(ply)
if time then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", "0.1", "/toggleownable"))
return ""
end
time = true
timer.Simple(0.1, function() time = false end)
复制
已复制
复制
已复制
if
fn.Null(doorData.allowedToOwn
) then
if
not ply:hasDarkRPPrivilege("rp_doorManipulation"
) then
doorData.allowedToOwn = nil
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("no_privilege"))
return ""
end
end
复制
已复制
复制
已复制
DarkRP.updateDoorData(self, "allowedToOwn")
local trace = ply:GetEyeTrace()
end
local ent = trace.Entity
if not IsValid(ent) or (not ent:isDoor() and not ent:IsVehicle()) or ply:GetPos():Distance(ent:GetPos()) > 200 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle")))
return
end
复制
已复制
复制
已复制
function eMeta
:removeAllKeysAllowedToOwn()
if IsValid(ent:getDoorOwner()) then
local doorData = self:getDoorData(
)
ent:keysUnOwn(ent:getDoorOwner())
doorData.allowedToOwn =
nil
end
ent:setKeysNonOwnable(not ent:getKeysNonOwnable())
ent:removeAllKeysExtraOwners()
ent
:removeAllKeysAllowedToOwn()
ent:removeAllKeysDoorTeams()
ent:setDoorGroup(nil
)
ent:setKeysTitle(
nil
)
复制
已复制
复制
已复制
DarkRP.
updat
eDoorData(
self, "allowedToOwn")
-- Save it for future map loads
DarkRP.
stor
eDoorData(
ent)
return ""
end
end
复制
已复制
复制
已复制
DarkRP.defineChatCommand("toggleownable", SetDoorOwnable)
复制
已复制
复制
已复制
function eMeta:addKeysDoorOwner(ply)
local time3 = false
local doorData = self:getDoorData()
local function SetDoorGroupOwnable(ply, arg)
doorData.extraOwners = doorData.extraOwners or {}
if time3 then
doorData.extraOwners[ply:EntIndex()]
= true
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", "0.1", "/togglegroupownable"))
return ""
end
time3
= true
timer.Simple(0.1, function() time3 = false end)
复制
已复制
复制
已复制
DarkRP.updateDoorData(self, "extraOwners"
)
local trace = ply:GetEyeTrace(
)
复制
已复制
复制
已复制
self:removeKeysAllowedToOwn(ply)
if not ply:hasDarkRPPrivilege("rp_doorManipulation") then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("no_privilege"))
return ""
end
local ent = trace.Entity
if not IsValid(ent) or (not ent:isDoor() and not ent:IsVehicle()) or ply:GetPos():Distance(ent:GetPos()) > 200 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle")))
return
end
if not RPExtraTeamDoors[arg] and arg ~= "" then DarkRP.notify(ply, 1, 10, DarkRP.getPhrase("door_group_doesnt_exist")) return "" end
ent:keysUnOwn()
ent:removeAllKeysDoorTeams()
local group = arg ~= "" and arg or nil
ent:setDoorGroup(group)
-- Save it for future map loads
DarkRP.storeDoorGroup(ent, group)
DarkRP.storeTeamDoorOwnability(ent)
DarkRP.notify(ply, 0, 8, DarkRP.getPhrase("door_group_set"))
return ""
end
end
复制
已复制
复制
已复制
DarkRP.defineChatCommand("togglegroupownable", SetDoorGroupOwnable)
复制
已复制
复制
已复制
function eMeta:removeKeysDoorOwner(ply)
local time4 = false
local doorData = self:getDoorData()
local function SetDoorTeamOwnable(ply, arg)
doorData.extraOwners = doorData.extraOwners or {}
if time4 then
doorData.extraOwners[ply:EntIndex()] = nil
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", "0.1", "/toggleteamownable"))
return ""
end
time4 = true
timer.Simple( 0.1, function() time4 = false end )
local trace = ply:GetEyeTrace()
复制
已复制
复制
已复制
if
fn.Null(doorData.extraOwners
) then
local ent = trace.Entity
doorData.extraOwners = nil
if
not ply:hasDarkRPPrivilege("rp_doorManipulation"
) then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("no_privilege"))
return ""
end
end
复制
已复制
复制
已复制
DarkRP.updateDoorData(self, "extraOwners")
if not IsValid(ent) or (not ent:isDoor() and not ent:IsVehicle()) or ply:GetPos():Distance(ent:GetPos()) > 200 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle")))
return ""
end
arg = tonumber(arg)
if not RPExtraTeams[arg] and arg ~= nil then DarkRP.notify(ply, 1, 10, DarkRP.getPhrase("job_doesnt_exist")) return "" end
if IsValid(ent:getDoorOwner()) then
ent:keysUnOwn(ent:getDoorOwner())
end
ent:setDoorGroup(nil)
DarkRP.storeDoorGroup(ent, nil)
local doorTeams = ent:getKeysDoorTeams()
if not doorTeams or not doorTeams[arg] then
ent:addKeysDoorTeam(arg)
else
ent:removeKeysDoorTeam(arg)
end
DarkRP.notify(ply, 0, 8, DarkRP.getPhrase("door_group_set"))
DarkRP.storeTeamDoorOwnability(ent)
ent:keysUnOwn()
return ""
end
end
复制
已复制
复制
已复制
DarkRP.defineChatCommand("toggleteamownable", SetDoorTeamOwnable)
复制
已复制
复制
已复制
function eMeta:removeAllKeysExtraOwners()
local time2 = false
local
doorData
=
self:getDoorData
()
local function OwnDoor(ply)
doorData.extraOwners
=
nil
if time2 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", "0.1", "/toggleown"))
return ""
end
time2 = true
timer.Simple(0.1, function() time2 = false end)
local
team
=
ply:Team
()
local trace
=
ply:GetEyeTrace()
复制
已复制
复制
已复制
DarkRP.updateDoorData(self, "extraOwners")
if IsValid(trace.Entity) and trace.Entity:isKeysOwnable() and ply:GetPos():Distance(trace.Entity:GetPos()) < 200 then
local Owner = trace.Entity:CPPIGetOwner()
if ply:isArrested() then
DarkRP.notify(ply, 1, 5, DarkRP.getPhrase("door_unown_arrested"))
return ""
end
if trace.Entity:getKeysNonOwnable() or trace.Entity:getKeysDoorGroup() or not fn.Null(trace.Entity:getKeysDoorTeams() or {}) then
DarkRP.notify(ply, 1, 5, DarkRP.getPhrase("door_unownable"))
return ""
end
if trace.Entity:isKeysOwnedBy(ply) then
if trace.Entity:isMasterOwner(ply) then
trace.Entity:removeAllKeysExtraOwners()
trace.Entity:removeAllKeysAllowedToOwn()
trace.Entity:Fire("unlock", "", 0)
end
trace.Entity:keysUnOwn(ply)
trace.Entity:setKeysTitle(nil)
local GiveMoneyBack = math.floor((((trace.Entity:IsVehicle() and GAMEMODE.Config.vehiclecost) or GAMEMODE.Config.doorcost) * 0.666) + 0.5)
hook.Call("playerKeysSold", GAMEMODE, ply, trace.Entity, GiveMoneyBack)
ply:addMoney(GiveMoneyBack)
local bSuppress = hook.Call("hideSellDoorMessage", GAMEMODE, ply, trace.Entity)
if( !bSuppress ) then
DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("door_sold", GAMEMODE.Config.currency..(GiveMoneyBack)))
end
else
if trace.Entity:isKeysOwned() and not trace.Entity:isKeysAllowedToOwn(ply) then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("door_already_owned"))
return ""
end
local iCost = hook.Call("get".. (trace.Entity:IsVehicle() and "Vehicle" or "Door").."Cost", GAMEMODE, ply, trace.Entity);
if( !ply:canAfford( iCost ) ) then
DarkRP.notify( ply, 1, 4, trace.Entity:IsVehicle() and DarkRP.getPhrase("vehicle_cannot_afford") or DarkRP.getPhrase("door_cannot_afford"))
return "";
end
local bAllowed, strReason, bSuppress = hook.Call("playerBuy"..( trace.Entity:IsVehicle() and "Vehicle" or "Door"), GAMEMODE, ply, trace.Entity)
if( bAllowed == false ) then
if( strReason and strReason != "") then
DarkRP.notify( ply, 1, 4, strReason)
end
return "";
end
local bVehicle = trace.Entity:IsVehicle();
if bVehicle and (ply.Vehicles or 0) >= GAMEMODE.Config.maxvehicles and Owner ~= ply then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("limit", DarkRP.getPhrase("vehicle")))
return ""
end
if not bVehicle and (ply.OwnedNumz or 0) >= GAMEMODE.Config.maxdoors then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("limit", DarkRP.getPhrase("door")))
return ""
end
ply:addMoney(-iCost)
if( !bSuppress ) then
DarkRP.notify( ply, 0, 4, bVehicle and DarkRP.getPhrase("vehicle_bought", GAMEMODE.Config.currency, iCost) or DarkRP.getPhrase("door_bought", GAMEMODE.Config.currency, iCost))
end
trace.Entity:keysOwn(ply)
hook.Call("playerBought"..(bVehicle and "Vehicle" or "Door"), GAMEMODE, ply, trace.Entity, iCost);
end
return ""
end
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle")))
return ""
end
end
复制
已复制
复制
已复制
DarkRP.defineChatCommand("toggleown", OwnDoor)
复制
已复制
复制
已复制
function eMeta:removeDoorData()
local function UnOwnAll(ply, cmd, args)
net.Start("DarkRP_RemoveDoorData")
local amount = 0
net.WriteUInt(self:EntIndex(), 32)
for k,v in pairs(ents.GetAll()) do
net.Send(player.GetAll())
if v:isKeysOwnedBy(ply) and not IsValid(v.EntOwner) --[[SCars]]then
amount = amount + 1
v:Fire("unlock", "", 0)
v:keysUnOwn(ply)
local cost = (v:IsVehicle() and GAMEMODE.Config.vehiclecost or GAMEMODE.Config.doorcost) * 2/3 + 0.5
ply:addMoney(math.floor(cost))
ply:GetTable().Ownedz[v:EntIndex()] = nil
end
end
ply:GetTable().OwnedNumz = 0
DarkRP.notify(ply, 2, 4, DarkRP.getPhrase("sold_x_doors_for_y", amount, GAMEMODE.Config.currency, amount * math.floor(((GAMEMODE.Config.doorcost * 0.66666666666666)+0.5))))
return ""
end
end
复制
已复制
复制
已复制
DarkRP.defineChatCommand("unownalldoors", UnOwnAll)
复制
已复制
复制
已复制
/*---------------------------------------------------------------------------
Networking
---------------------------------------------------------------------------*/
local function sendDoorData(ply)
if ply:EntIndex() == 0 then return end
if ply.doorDataSent and ply.doorDataSent > (CurTime() - 1) then return end -- prevent spammers
复制
已复制
复制
已复制
local
res = {}
local
function SetDoorTitle(ply, args)
for k,v in pairs(ents.GetAll()) do
local trace = ply:GetEyeTrace()
if not IsValid(v) or not v.DoorData then continue end
复制
已复制
复制
已复制
res[v:EntIndex()] = v.DoorData
if not IsValid(trace.Entity) or not trace.Entity:isKeysOwnable() or ply:GetPos():Distance(trace.Entity:GetPos()) >= 110 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle")))
return ""
end
end
复制
已复制
复制
已复制
net.Start("DarkRP_AllDoorData")
if ply:IsSuperAdmin() then
net.WriteTable(res)
if trace.Entity:getKeysNonOwnable() or trace.Entity:getKeysDoorGroup() or not fn.Null(trace.Entity:getKeysDoorTeams() or {}) then
net.Send(ply)
trace.Entity:setKeysTitle(args)
DarkRP.storeDoorData(trace.Entity)
return ""
end
elseif trace.Entity:getKeysNonOwnable() then
DarkRP.notify(ply, 1, 6, DarkRP.getPhrase("need_admin", "/title"))
end
if not trace.Entity:isKeysOwnedBy(ply) then
DarkRP.notify(ply, 1, 6, DarkRP.getPhrase("door_need_to_own", "/title"))
return ""
end
trace.Entity:setKeysTitle(args)
return ""
end
end
复制
已复制
复制
已复制
concommand.Add("_sendAllDoorData
",
sendDoorData
)
DarkRP.defineChatCommand("title
",
SetDoorTitle
)
复制
已复制
复制
已复制
function
DarkRP.updateDoorData(door, member
)
local
function
RemoveDoorOwner(ply, args
)
if not IsValid(door) or not door.DoorData then error("Calling updateDoorData on a door that has no data!") end
local trace = ply:GetEyeTrace()
复制
已复制
复制
已复制
net.Start("DarkRP_UpdateDoorData")
if not IsValid(trace.Entity) or not trace.Entity:isKeysOwnable() or ply:GetPos():Distance(trace.Entity:GetPos()) >= 110 then
net.WriteUInt(door:EntIndex(), 32)
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle")))
net.WriteString(member)
return ""
net.WriteType(door.DoorData[member])
end
net.Send(player.GetAll())
target = DarkRP.findPlayer(args)
if trace.Entity:getKeysNonOwnable() then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("door_rem_owners_unownable"))
return ""
end
if not target then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(args)))
return ""
end
if not trace.Entity:isKeysOwnedBy(ply) then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("do_not_own_ent"))
return ""
end
local canDo = hook.Call("onAllowedToOwnRemoved", nil, ply, trace.Entity, target)
if canDo == false then return "" end
if trace.Entity:isKeysAllowedToOwn(target) then
trace.Entity:removeKeysAllowedToOwn(target)
end
if trace.Entity:isKeysOwnedBy(target) then
trace.Entity:removeKeysDoorOwner(target)
end
return ""
end
DarkRP.defineChatCommand("removeowner", RemoveDoorOwner)
DarkRP.defineChatCommand("ro", RemoveDoorOwner)
local function AddDoorOwner(ply, args)
local trace = ply:GetEyeTrace()
if not IsValid(trace.Entity) or not trace.Entity:isKeysOwnable() or ply:GetPos():Distance(trace.Entity:GetPos()) >= 110 then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle")))
return ""
end
target = DarkRP.findPlayer(args)
if trace.Entity:getKeysNonOwnable() then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("door_add_owners_unownable"))
return ""
end
if not target then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(args)))
return ""
end
if not trace.Entity:isKeysOwnedBy(ply) then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("do_not_own_ent"))
return ""
end
if trace.Entity:isKeysOwnedBy(target) or trace.Entity:isKeysAllowedToOwn(target) then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("rp_addowner_already_owns_door", ply:Nick()))
return ""
end
local canDo = hook.Call("onAllowedToOwnAdded", nil, ply, trace.Entity, target)
if canDo == false then return "" end
trace.Entity:addKeysAllowedToOwn(target)
return ""
end
end
复制
已复制
复制
已复制
DarkRP.defineChatCommand("addowner", AddDoorOwner)
DarkRP.defineChatCommand("ao", AddDoorOwner)
已保存差异
原始文本
打开文件
util.AddNetworkString("DarkRP_PlayerVar") util.AddNetworkString("DarkRP_UpdateDoorData") util.AddNetworkString("DarkRP_RemoveDoorData") util.AddNetworkString("DarkRP_AllDoorData") /*--------------------------------------------------------------------------- Interface functions ---------------------------------------------------------------------------*/ local eMeta = FindMetaTable("Entity") function eMeta:getDoorData() if not self:isKeysOwnable() then return {} end self.DoorData = self.DoorData or {} return self.DoorData end function eMeta:setKeysNonOwnable(ownable) self:getDoorData().nonOwnable = ownable DarkRP.updateDoorData(self, "nonOwnable") end function eMeta:setKeysTitle(title) self:getDoorData().title = title DarkRP.updateDoorData(self, "title") end function eMeta:setDoorGroup(group) self:getDoorData().groupOwn = group DarkRP.updateDoorData(self, "groupOwn") end function eMeta:addKeysDoorTeam(t) local doorData = self:getDoorData() doorData.teamOwn = doorData.teamOwn or {} doorData.teamOwn[t] = true DarkRP.updateDoorData(self, "teamOwn") end function eMeta:removeKeysDoorTeam(t) local doorData = self:getDoorData() doorData.teamOwn = doorData.teamOwn or {} doorData.teamOwn[t] = nil if fn.Null(doorData.teamOwn) then doorData.teamOwn = nil end DarkRP.updateDoorData(self, "teamOwn") end function eMeta:removeAllKeysDoorTeams() local doorData = self:getDoorData() doorData.teamOwn = nil DarkRP.updateDoorData(self, "teamOwn") end function eMeta:addKeysAllowedToOwn(ply) local doorData = self:getDoorData() doorData.allowedToOwn = doorData.allowedToOwn or {} doorData.allowedToOwn[ply:EntIndex()] = true DarkRP.updateDoorData(self, "allowedToOwn") end function eMeta:removeKeysAllowedToOwn(ply) local doorData = self:getDoorData() doorData.allowedToOwn = doorData.allowedToOwn or {} doorData.allowedToOwn[ply:EntIndex()] = nil if fn.Null(doorData.allowedToOwn) then doorData.allowedToOwn = nil end DarkRP.updateDoorData(self, "allowedToOwn") end function eMeta:removeAllKeysAllowedToOwn() local doorData = self:getDoorData() doorData.allowedToOwn = nil DarkRP.updateDoorData(self, "allowedToOwn") end function eMeta:addKeysDoorOwner(ply) local doorData = self:getDoorData() doorData.extraOwners = doorData.extraOwners or {} doorData.extraOwners[ply:EntIndex()] = true DarkRP.updateDoorData(self, "extraOwners") self:removeKeysAllowedToOwn(ply) end function eMeta:removeKeysDoorOwner(ply) local doorData = self:getDoorData() doorData.extraOwners = doorData.extraOwners or {} doorData.extraOwners[ply:EntIndex()] = nil if fn.Null(doorData.extraOwners) then doorData.extraOwners = nil end DarkRP.updateDoorData(self, "extraOwners") end function eMeta:removeAllKeysExtraOwners() local doorData = self:getDoorData() doorData.extraOwners = nil DarkRP.updateDoorData(self, "extraOwners") end function eMeta:removeDoorData() net.Start("DarkRP_RemoveDoorData") net.WriteUInt(self:EntIndex(), 32) net.Send(player.GetAll()) end /*--------------------------------------------------------------------------- Networking ---------------------------------------------------------------------------*/ local function sendDoorData(ply) if ply:EntIndex() == 0 then return end if ply.doorDataSent and ply.doorDataSent > (CurTime() - 1) then return end -- prevent spammers local res = {} for k,v in pairs(ents.GetAll()) do if not IsValid(v) or not v.DoorData then continue end res[v:EntIndex()] = v.DoorData end net.Start("DarkRP_AllDoorData") net.WriteTable(res) net.Send(ply) end concommand.Add("_sendAllDoorData", sendDoorData) function DarkRP.updateDoorData(door, member) if not IsValid(door) or not door.DoorData then error("Calling updateDoorData on a door that has no data!") end net.Start("DarkRP_UpdateDoorData") net.WriteUInt(door:EntIndex(), 32) net.WriteString(member) net.WriteType(door.DoorData[member]) net.Send(player.GetAll()) end
更改后文本
打开文件
/*--------------------------------------------------------------------------- Functions ---------------------------------------------------------------------------*/ function meta:keysLock() self:Fire("lock", "", 0) if isfunction(self.Lock) then self:Lock(true) end -- SCars if IsValid(self.EntOwner) and self.EntOwner ~= self then return self.EntOwner:keysLock() end -- SCars hook.Call("onKeysLocked", nil, self) end function meta:keysUnLock() self:Fire("unlock", "", 0) if isfunction(self.UnLock) then self:UnLock(true) end -- SCars if IsValid(self.EntOwner) and self.EntOwner ~= self then return self.EntOwner:keysUnLock() end -- SCars hook.Call("onKeysUnlocked", nil, self) end function meta:keysOwn(ply) if self:isKeysAllowedToOwn(ply) then self:addKeysDoorOwner(ply) return end local Owner = self:CPPIGetOwner() -- Increase vehicle count if self:IsVehicle() then if IsValid(ply) then ply.Vehicles = ply.Vehicles or 0 ply.Vehicles = ply.Vehicles + 1 end -- Decrease vehicle count of the original owner if IsValid(Owner) and Owner ~= ply then Owner.Vehicles = Owner.Vehicles or 1 Owner.Vehicles = Owner.Vehicles - 1 end end if self:IsVehicle() then self:CPPISetOwner(ply) end if not self:isKeysOwned() and not self:isKeysOwnedBy(ply) then local doorData = self:getDoorData() doorData.owner = ply DarkRP.updateDoorData(self, "owner") end if ply:GetTable().OwnedNumz == 0 then timer.Create(ply:UniqueID() .. "propertytax", 270, 0, function() ply.doPropertyTax(ply) end) end ply:GetTable().OwnedNumz = ply:GetTable().OwnedNumz + 1 ply:GetTable().Ownedz[self:EntIndex()] = self end function meta:keysUnOwn(ply) if not ply then ply = self:getDoorOwner() if not IsValid(ply) then return end end if self:isMasterOwner(ply) then local doorData = self:getDoorData() doorData.owner = nil DarkRP.updateDoorData(self, "owner") else self:removeKeysDoorOwner(ply) end ply:GetTable().Ownedz[self:EntIndex()] = nil ply:GetTable().OwnedNumz = math.Clamp(ply:GetTable().OwnedNumz - 1, 0, math.huge) end function pmeta:keysUnOwnAll() for k, v in pairs(ents.GetAll()) do if v:isKeysOwnable() and v:isKeysOwnedBy(self) == true then v:Fire("unlock", "", 0.6) end end if self:GetTable().Ownedz then for k, v in pairs(self.Ownedz) do if not v:isKeysOwnable() then self.Ownedz[k] = nil continue end v:keysUnOwn(self) self.Ownedz[v:EntIndex()] = nil end end for k, v in pairs(player.GetAll()) do if v.Ownedz then for n, m in pairs(v.Ownedz) do if IsValid(m) and m:isKeysAllowedToOwn(self) then m:removeKeysAllowedToOwn(self) end end end end self.OwnedNumz = 0 end function pmeta:doPropertyTax() if not GAMEMODE.Config.propertytax then return end if self:isCP() and GAMEMODE.Config.cit_propertytax then return end local numowned = self.OwnedNumz if not numowned or numowned <= 0 then return end local price = 10 local tax = price * numowned + math.random(-5, 5) if self:canAfford(tax) then if tax ~= 0 then self:addMoney(-tax) DarkRP.notify(self, 0, 5, DarkRP.getPhrase("property_tax", GAMEMODE.Config.currency .. tax)) end else DarkRP.notify(self, 1, 8, DarkRP.getPhrase("property_tax_cant_afford")) self:keysUnOwnAll() end end function pmeta:initiateTax() local taxtime = GAMEMODE.Config.wallettaxtime local uniqueid = self:UniqueID() -- so we can destroy the timer if the player leaves timer.Create("rp_tax_"..uniqueid, taxtime or 600, 0, function() if not IsValid(self) then timer.Destroy("rp_tax_"..uniqueid) return end if not GAMEMODE.Config.wallettax then return -- Don't remove the hook in case it's turned on afterwards. end local money = self:getDarkRPVar("money") local mintax = GAMEMODE.Config.wallettaxmin / 100 local maxtax = GAMEMODE.Config.wallettaxmax / 100 -- convert to decimals for percentage calculations local startMoney = GAMEMODE.Config.startingmoney if money < (startMoney * 2) then return -- Don't tax players if they have less than twice the starting amount end -- Variate the taxes between twice the starting money ($1000 by default) and 200 - 2 times the starting money (100.000 by default) local tax = (money - (startMoney * 2)) / (startMoney * 198) tax = math.Min(maxtax, mintax + (maxtax - mintax) * tax) self:addMoney(-tax * money) DarkRP.notify(self, 3, 7, DarkRP.getPhrase("taxday", math.Round(tax * 100, 3))) end) end /*--------------------------------------------------------------------------- Commands ---------------------------------------------------------------------------*/ local time = false local function SetDoorOwnable(ply) if time then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", "0.1", "/toggleownable")) return "" end time = true timer.Simple(0.1, function() time = false end) if not ply:hasDarkRPPrivilege("rp_doorManipulation") then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("no_privilege")) return "" end local trace = ply:GetEyeTrace() local ent = trace.Entity if not IsValid(ent) or (not ent:isDoor() and not ent:IsVehicle()) or ply:GetPos():Distance(ent:GetPos()) > 200 then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle"))) return end if IsValid(ent:getDoorOwner()) then ent:keysUnOwn(ent:getDoorOwner()) end ent:setKeysNonOwnable(not ent:getKeysNonOwnable()) ent:removeAllKeysExtraOwners() ent:removeAllKeysAllowedToOwn() ent:removeAllKeysDoorTeams() ent:setDoorGroup(nil) ent:setKeysTitle(nil) -- Save it for future map loads DarkRP.storeDoorData(ent) return "" end DarkRP.defineChatCommand("toggleownable", SetDoorOwnable) local time3 = false local function SetDoorGroupOwnable(ply, arg) if time3 then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", "0.1", "/togglegroupownable")) return "" end time3 = true timer.Simple(0.1, function() time3 = false end) local trace = ply:GetEyeTrace() if not ply:hasDarkRPPrivilege("rp_doorManipulation") then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("no_privilege")) return "" end local ent = trace.Entity if not IsValid(ent) or (not ent:isDoor() and not ent:IsVehicle()) or ply:GetPos():Distance(ent:GetPos()) > 200 then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle"))) return end if not RPExtraTeamDoors[arg] and arg ~= "" then DarkRP.notify(ply, 1, 10, DarkRP.getPhrase("door_group_doesnt_exist")) return "" end ent:keysUnOwn() ent:removeAllKeysDoorTeams() local group = arg ~= "" and arg or nil ent:setDoorGroup(group) -- Save it for future map loads DarkRP.storeDoorGroup(ent, group) DarkRP.storeTeamDoorOwnability(ent) DarkRP.notify(ply, 0, 8, DarkRP.getPhrase("door_group_set")) return "" end DarkRP.defineChatCommand("togglegroupownable", SetDoorGroupOwnable) local time4 = false local function SetDoorTeamOwnable(ply, arg) if time4 then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", "0.1", "/toggleteamownable")) return "" end time4 = true timer.Simple( 0.1, function() time4 = false end ) local trace = ply:GetEyeTrace() local ent = trace.Entity if not ply:hasDarkRPPrivilege("rp_doorManipulation") then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("no_privilege")) return "" end if not IsValid(ent) or (not ent:isDoor() and not ent:IsVehicle()) or ply:GetPos():Distance(ent:GetPos()) > 200 then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle"))) return "" end arg = tonumber(arg) if not RPExtraTeams[arg] and arg ~= nil then DarkRP.notify(ply, 1, 10, DarkRP.getPhrase("job_doesnt_exist")) return "" end if IsValid(ent:getDoorOwner()) then ent:keysUnOwn(ent:getDoorOwner()) end ent:setDoorGroup(nil) DarkRP.storeDoorGroup(ent, nil) local doorTeams = ent:getKeysDoorTeams() if not doorTeams or not doorTeams[arg] then ent:addKeysDoorTeam(arg) else ent:removeKeysDoorTeam(arg) end DarkRP.notify(ply, 0, 8, DarkRP.getPhrase("door_group_set")) DarkRP.storeTeamDoorOwnability(ent) ent:keysUnOwn() return "" end DarkRP.defineChatCommand("toggleteamownable", SetDoorTeamOwnable) local time2 = false local function OwnDoor(ply) if time2 then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("have_to_wait", "0.1", "/toggleown")) return "" end time2 = true timer.Simple(0.1, function() time2 = false end) local team = ply:Team() local trace = ply:GetEyeTrace() if IsValid(trace.Entity) and trace.Entity:isKeysOwnable() and ply:GetPos():Distance(trace.Entity:GetPos()) < 200 then local Owner = trace.Entity:CPPIGetOwner() if ply:isArrested() then DarkRP.notify(ply, 1, 5, DarkRP.getPhrase("door_unown_arrested")) return "" end if trace.Entity:getKeysNonOwnable() or trace.Entity:getKeysDoorGroup() or not fn.Null(trace.Entity:getKeysDoorTeams() or {}) then DarkRP.notify(ply, 1, 5, DarkRP.getPhrase("door_unownable")) return "" end if trace.Entity:isKeysOwnedBy(ply) then if trace.Entity:isMasterOwner(ply) then trace.Entity:removeAllKeysExtraOwners() trace.Entity:removeAllKeysAllowedToOwn() trace.Entity:Fire("unlock", "", 0) end trace.Entity:keysUnOwn(ply) trace.Entity:setKeysTitle(nil) local GiveMoneyBack = math.floor((((trace.Entity:IsVehicle() and GAMEMODE.Config.vehiclecost) or GAMEMODE.Config.doorcost) * 0.666) + 0.5) hook.Call("playerKeysSold", GAMEMODE, ply, trace.Entity, GiveMoneyBack) ply:addMoney(GiveMoneyBack) local bSuppress = hook.Call("hideSellDoorMessage", GAMEMODE, ply, trace.Entity) if( !bSuppress ) then DarkRP.notify(ply, 0, 4, DarkRP.getPhrase("door_sold", GAMEMODE.Config.currency..(GiveMoneyBack))) end else if trace.Entity:isKeysOwned() and not trace.Entity:isKeysAllowedToOwn(ply) then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("door_already_owned")) return "" end local iCost = hook.Call("get".. (trace.Entity:IsVehicle() and "Vehicle" or "Door").."Cost", GAMEMODE, ply, trace.Entity); if( !ply:canAfford( iCost ) ) then DarkRP.notify( ply, 1, 4, trace.Entity:IsVehicle() and DarkRP.getPhrase("vehicle_cannot_afford") or DarkRP.getPhrase("door_cannot_afford")) return ""; end local bAllowed, strReason, bSuppress = hook.Call("playerBuy"..( trace.Entity:IsVehicle() and "Vehicle" or "Door"), GAMEMODE, ply, trace.Entity) if( bAllowed == false ) then if( strReason and strReason != "") then DarkRP.notify( ply, 1, 4, strReason) end return ""; end local bVehicle = trace.Entity:IsVehicle(); if bVehicle and (ply.Vehicles or 0) >= GAMEMODE.Config.maxvehicles and Owner ~= ply then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("limit", DarkRP.getPhrase("vehicle"))) return "" end if not bVehicle and (ply.OwnedNumz or 0) >= GAMEMODE.Config.maxdoors then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("limit", DarkRP.getPhrase("door"))) return "" end ply:addMoney(-iCost) if( !bSuppress ) then DarkRP.notify( ply, 0, 4, bVehicle and DarkRP.getPhrase("vehicle_bought", GAMEMODE.Config.currency, iCost) or DarkRP.getPhrase("door_bought", GAMEMODE.Config.currency, iCost)) end trace.Entity:keysOwn(ply) hook.Call("playerBought"..(bVehicle and "Vehicle" or "Door"), GAMEMODE, ply, trace.Entity, iCost); end return "" end DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle"))) return "" end DarkRP.defineChatCommand("toggleown", OwnDoor) local function UnOwnAll(ply, cmd, args) local amount = 0 for k,v in pairs(ents.GetAll()) do if v:isKeysOwnedBy(ply) and not IsValid(v.EntOwner) --[[SCars]]then amount = amount + 1 v:Fire("unlock", "", 0) v:keysUnOwn(ply) local cost = (v:IsVehicle() and GAMEMODE.Config.vehiclecost or GAMEMODE.Config.doorcost) * 2/3 + 0.5 ply:addMoney(math.floor(cost)) ply:GetTable().Ownedz[v:EntIndex()] = nil end end ply:GetTable().OwnedNumz = 0 DarkRP.notify(ply, 2, 4, DarkRP.getPhrase("sold_x_doors_for_y", amount, GAMEMODE.Config.currency, amount * math.floor(((GAMEMODE.Config.doorcost * 0.66666666666666)+0.5)))) return "" end DarkRP.defineChatCommand("unownalldoors", UnOwnAll) local function SetDoorTitle(ply, args) local trace = ply:GetEyeTrace() if not IsValid(trace.Entity) or not trace.Entity:isKeysOwnable() or ply:GetPos():Distance(trace.Entity:GetPos()) >= 110 then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle"))) return "" end if ply:IsSuperAdmin() then if trace.Entity:getKeysNonOwnable() or trace.Entity:getKeysDoorGroup() or not fn.Null(trace.Entity:getKeysDoorTeams() or {}) then trace.Entity:setKeysTitle(args) DarkRP.storeDoorData(trace.Entity) return "" end elseif trace.Entity:getKeysNonOwnable() then DarkRP.notify(ply, 1, 6, DarkRP.getPhrase("need_admin", "/title")) end if not trace.Entity:isKeysOwnedBy(ply) then DarkRP.notify(ply, 1, 6, DarkRP.getPhrase("door_need_to_own", "/title")) return "" end trace.Entity:setKeysTitle(args) return "" end DarkRP.defineChatCommand("title", SetDoorTitle) local function RemoveDoorOwner(ply, args) local trace = ply:GetEyeTrace() if not IsValid(trace.Entity) or not trace.Entity:isKeysOwnable() or ply:GetPos():Distance(trace.Entity:GetPos()) >= 110 then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle"))) return "" end target = DarkRP.findPlayer(args) if trace.Entity:getKeysNonOwnable() then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("door_rem_owners_unownable")) return "" end if not target then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(args))) return "" end if not trace.Entity:isKeysOwnedBy(ply) then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("do_not_own_ent")) return "" end local canDo = hook.Call("onAllowedToOwnRemoved", nil, ply, trace.Entity, target) if canDo == false then return "" end if trace.Entity:isKeysAllowedToOwn(target) then trace.Entity:removeKeysAllowedToOwn(target) end if trace.Entity:isKeysOwnedBy(target) then trace.Entity:removeKeysDoorOwner(target) end return "" end DarkRP.defineChatCommand("removeowner", RemoveDoorOwner) DarkRP.defineChatCommand("ro", RemoveDoorOwner) local function AddDoorOwner(ply, args) local trace = ply:GetEyeTrace() if not IsValid(trace.Entity) or not trace.Entity:isKeysOwnable() or ply:GetPos():Distance(trace.Entity:GetPos()) >= 110 then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("must_be_looking_at", DarkRP.getPhrase("door_or_vehicle"))) return "" end target = DarkRP.findPlayer(args) if trace.Entity:getKeysNonOwnable() then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("door_add_owners_unownable")) return "" end if not target then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("could_not_find", tostring(args))) return "" end if not trace.Entity:isKeysOwnedBy(ply) then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("do_not_own_ent")) return "" end if trace.Entity:isKeysOwnedBy(target) or trace.Entity:isKeysAllowedToOwn(target) then DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("rp_addowner_already_owns_door", ply:Nick())) return "" end local canDo = hook.Call("onAllowedToOwnAdded", nil, ply, trace.Entity, target) if canDo == false then return "" end trace.Entity:addKeysAllowedToOwn(target) return "" end DarkRP.defineChatCommand("addowner", AddDoorOwner) DarkRP.defineChatCommand("ao", AddDoorOwner)
查找差异