1

我得到的错误是[ERROR] addons/armory station pack/lua/weapons/money_test.lua:31:尝试调用字段'Create'(一个零值)1.未知-addons/armory station pack/lua/weapons/ money_test.lua:31

我的枪支密码在这里。

SWEP.PrintName      = "Money Test"
SWEP.Author     = "( Justin Yates )"
SWEP.Instructions   = "Left click to make it rain."

SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.Primary.ClipSize   = -1
SWEP.Primary.DefaultClip  = -1
SWEP.Primary.Automatic    = false
SWEP.Primary.Ammo   = "none"

SWEP.Secondary.ClipSize   = -1
SWEP.Secondary.DefaultClip  = -1
SWEP.Secondary.Automatic  = false
SWEP.Secondary.Ammo   = "none"

SWEP.Weight     = 2
SWEP.AutoSwitchTo   = false
SWEP.AutoSwitchFrom   = false

SWEP.Slot     = 1
SWEP.SlotPos      = 2
SWEP.DrawAmmo     = true
SWEP.DrawCrosshair    = true

SWEP.ViewModel      = "models/weapons/v_pistol.mdl"
SWEP.WorldModel     = "models/weapons/v_hands.mdl"

function SWEP:PrimaryAttack()
  local money = ents.Create("spawned_money")
  money:SetPos(self:GetPos())
  money.dt.amount = 500
  money:Spawn()
  money:Activate()
end

它确实有效,但会向控制台发送 lua 错误。

4

1 回答 1

0

如果我理解你的描述是正确的。您在客户端收到此错误。

ents.Create()是一个服务器端功能。要创建客户端实体,您需要ents.CreateClientProp().

阅读我的 GMod(已经有一段时间了,因为我编写了 GMod Lua ..)试试这个:

function SWEP:PrimaryAttack()
  if SERVER then
    local money = ents.Create("spawned_money")
    money:SetPos(self:GetPos())
    money.dt.amount = 500
    money:Spawn()
    money:Activate()
  end
end
于 2014-05-10T18:53:09.390 回答