lua - garry's mod - 尝试调用全局变量 'Player' (一个表值)

当尝试启动 Garry's Mod 服务器时,我遇到了一个错误:

[ERROR] gamemodes/darkrp/gamemode/modules/base/sv_gamemode_functions.lua:227: 尝试调用全局变量 'Player' (一个表值)

  1. 未知 - gamemodes/darkrp/gamemode/modules/base/sv_gamemode_functions.lua:227

sv_gamemode_functions.lua:217-230

function GM:EntityRemoved(ent)

self.Sandbox.EntityRemoved(self, ent)
if ent:IsVehicle() then
    local found = ent:CPPIGetOwner()
    if IsValid(found) then
        found.Vehicles = found.Vehicles or 1
        found.Vehicles = found.Vehicles - 1
    end
end
local owner = ent.Getowning_ent and ent:Getowning_ent() or Player(ent.SID or 0)
if ent.DarkRPItem and IsValid(owner) then owner:removeCustomEntity(ent.DarkRPItem) end
if ent.isKeysOwnable and ent:isKeysOwnable() then ent:removeDoorData() end end

请帮忙解决。

点赞
用户3342050
用户3342050

将下面翻译成中文并且保留原本的 markdown 格式,

将这行修改为

local owner = ent :GetOwner()

https://wiki.facepunch.com/gmod/Entity:GetOwner

https://wiki.facepunch.com/gmod/Player:UserID

2020-11-14 16:39:26
用户8621712
用户8621712

这部分代码没问题。有些东西使用了一个表覆盖了 Player 全局变量。

你需要找出为什么会发生这种情况。

如果修复后 Player 仍不能正常工作,尝试使用 Entity(ent.SID or 0),也许这是一个 EntityIndex 而不是 UserID。

使用 Entity:GetOwner(如Doyousketch2建议)是无法帮助你的,因为它是用于父子关系而非所有权。

2020-11-14 17:05:32