【问题标题】:What's wrong with my gun?我的枪怎么了?
【发布时间】:2014-05-11 03:42:58
【问题描述】:

我得到的错误是 [错误] 插件/军械库站包/lua/weapons/money_test.lua:31:尝试调用字段“创建”(零值) 1. 未知 - 插件/军械库包/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 错误。

【问题讨论】:

标签: lua garrys-mod


【解决方案1】:

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

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

【讨论】:

  • 现在它说无法将 dt 索引为 nil 值并且不再丢钱
  • 嗯.. 除了那个文件之外,您没有任何 init/cl_init 文件吗? (我假设它是一个共享文件?)
猜你喜欢
  • 2012-09-05
  • 2017-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多