【问题标题】:lua - garry's mod - attempt to call global 'Player' (a table value)lua - garry's mod - 尝试调用全局“玩家”(表值)
【发布时间】:2021-02-26 08:10:18
【问题描述】:

尝试启动 Garry 的 Mod 服务器时出现错误:

[错误] gamemodes/darkrp/gamemode/modules/base/sv_gamemode_functions.lua:227: 尝试调用全局“玩家”(一个表值)

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

sv_gamemode_functions.lua:217-230

函数 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

请帮忙。

【问题讨论】:

    标签: lua garrys-mod


    【解决方案1】:

    改变这一行

    local owner = ent.Getowning_ent and ent:Getowning_ent() or Player(ent.SID or 0)
    

    local owner = ent :GetOwner()
    

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

    【讨论】:

      【解决方案2】:

      问题不在于这部分代码。 某些东西用表覆盖了Player 全局变量。

      您需要找出发生这种情况的原因。

      如果修复后播放器无法正常工作,请尝试Entity(ent.SID or 0),可能是 EntityIndex 而不是 UserID。

      Entity:GetOwner(正如 Doyousketch2 所建议的那样)对您没有帮助,因为它用于养育子女而不是所有权。

      【讨论】:

      • 你在想ent:getParent() wiki.facepunch.com/gmod/Entity:GetParent
      • @Doyousketch2 > 此功能通常用于禁用其所有者发射的射弹的物理交互,但也可用于在完全不涉及物理交互的情况下正常拥有。重力枪即使所有者无法与实体发生碰撞,也可以捡起实体,而物理枪则不会。 wiki.facepunch.com/gmod/Entity:SetOwner
      • 您指出了此脚本中未使用的函数。这里有什么相关性?
      • @Doyousketch2 但是您的回答提到此功能是正确的决定,我们不将此功能用于所有权
      • 我已经修复了这个错误,@Doyousketch2 的回答是正确的
      猜你喜欢
      • 1970-01-01
      • 2015-04-09
      • 2016-08-11
      • 2013-03-28
      • 2021-04-26
      • 2013-12-15
      • 1970-01-01
      • 2020-07-31
      • 2018-07-11
      相关资源
      最近更新 更多