Planimeter / hl2sb-src

Source code to Half-Life 2: Sandbox - A free and open-source sandbox Source engine modification.
MIT License
43 stars 9 forks source link

hl2sb lua error: attempt to index a number value #3

Closed steadyfield closed 1 year ago

steadyfield commented 1 year ago

give weapon_hl2mpbase_scriptedweapon, as the player shoots the weapon, in console there is an error message: attempt to index a number value so I opened the related SWEP lua files, and found that: local pPlayer = self:GetOwner(); calling any function of pPlayer, for example, pPlayer:DoMuzzleFlash(); or pPlayer:FireBullets( info ); will cause the an error message to be shown in console attempt to index a number value

I think the error is an issue with hl2sb's lua api, but idk how to fix it.

Dim1xs commented 1 year ago

if error from client, then try


if not _CLIENT then
--code
end
andrewmcwatters commented 1 year ago

Hi @steadyfield, weapon_hl2mpbase_scriptedweapon is intended to be inherited from for when you create your own scripted weapons.

Is there a stack trace you can share with us, or is the error one line only?

steadyfield commented 1 year ago

if error from client, then try

if not _CLIENT then
--code
end

Thanks, this is exactly the solution of the error message. The issue is solved.

steadyfield commented 1 year ago

Hi @steadyfield, weapon_hl2mpbase_scriptedweapon is intended to be inherited from for when you create your own scripted weapons.

Is there a stack trace you can share with us, or is the error one line only?

Thank you. As is pointed out by @Dim1xs , the solution is to add

if not _CLIENT then --code end

in SWEP:PrimaryAttack() and SWEP:SecondaryAttack() functions. Thanks anyway.