Some LUA Help.

Hi! Sorry for posting it here and looking like I completely ignored Garry’s locked and pinned post. But I couldn’t find the modding help anywhere in the forum. If it is there then could this thread be moved. Thanks!

Hi. I need help on some Lua functions that were changed in the GMOD 13 update. I’m looking specifically to convert some of my favorite SWEPs that unfortunately weren’t converted to GMOD 13.


[ERROR] addons/toybox sweps/lua/weapons/weapon_can/shared.lua:672: bad argument #1 to 'AddAngleVelocity' (Vector expected, got userdata)
  1. AddAngleVelocity - [C]:-1
   2. ThrowCan - addons/toybox sweps/lua/weapons/weapon_can/shared.lua:672
    3. HandleCustomAnimationEvent - addons/toybox sweps/lua/weapons/weapon_can/shared.lua:721
     4. SSAnimThink - addons/toybox sweps/lua/weapons/weapon_can/shared.lua:806
      5. unknown - addons/toybox sweps/lua/weapons/weapon_can/shared.lua:766



[ERROR] addons/toybox sweps/lua/weapons/weapon_anoth_laser/shared.lua:1074: bad argument #2 to 'CreateFont' (table expected, got number)
  1. CreateFont - [C]:-1
   2. unknown - addons/toybox sweps/lua/weapons/weapon_anoth_laser/shared.lua:1074


[ERROR] addons/toybox sweps/lua/weapons/weapon_eats/shared.lua:42: bad argument #2 to 'Exists' (string expected, got boolean)
  1. Exists - [C]:-1
   2. unknown - addons/toybox sweps/lua/weapons/weapon_eats/shared.lua:42


[ERROR] addons/toybox sweps/lua/weapons/weapon_sauger/shared.lua:410: attempt to call global 'GetWorldEntity' (a nil value)
  1. unknown - addons/toybox sweps/lua/weapons/weapon_sauger/shared.lua:410


[ERROR] addons/toybox sweps/lua/weapons/weapon_real_ar-15/shared.lua:91: bad argument #1 to 'SetFOV' (number expected, got nil)
  1. SetFOV - [C]:-1
   2. unknown - addons/toybox sweps/lua/weapons/weapon_real_ar-15/shared.lua:91
    3. SelectWeapon - [C]:-1
     4. unknown - gamemodes/sandbox/gamemode/commands.lua:701
      5. unknown - lua/includes/modules/concommand.lua:69

[ERROR] addons/toybox sweps/lua/weapons/weapon_real_ar-15/shared.lua:118: bad argument #1 to 'DefaultReload' (number expected, got no value)
  1. DefaultReload - [C]:-1
   2. unknown - addons/toybox sweps/lua/weapons/weapon_real_ar-15/shared.lua:118

(The AR-15 actually works it’s just this error when reloading and scoping)


[ERROR] addons/toybox sweps/lua/weapons/weapon_fun_laser/shared.lua:320: attempt to call global 'WorldSound' (a nil value)
  1. unknown - addons/toybox sweps/lua/weapons/weapon_fun_laser/shared.lua:320


[ERROR] addons/toybox sweps/lua/weapons/weapon_kantan/shared.lua:187: attempt to index local 'self' (a nil value)
  1. unknown - addons/toybox sweps/lua/weapons/weapon_kantan/shared.lua:187

Timer Failed! [Simple][@addons/toybox sweps/lua/weapons/weapon_kantan/shared.lua (line 181)]

[ERROR] addons/toybox sweps/lua/weapons/weapon_kantan/shared.lua:229: attempt to index local 'self' (a nil value)
  1. unknown - addons/toybox sweps/lua/weapons/weapon_kantan/shared.lua:229

Timer Failed! [Simple][@addons/toybox sweps/lua/weapons/weapon_kantan/shared.lua (line 173)]


[ERROR] addons/toybox sweps/lua/weapons/weapon_ran_npc/shared.lua:533: attempt to index field 'TNpc' (a nil value)
  1. MenuRebuildNpcList - addons/toybox sweps/lua/weapons/weapon_ran_npc/shared.lua:533
   2. MenuOpen - addons/toybox sweps/lua/weapons/weapon_ran_npc/shared.lua:577
    3. Function - addons/toybox sweps/lua/weapons/weapon_ran_npc/shared.lua:570
     4. unknown - lua/includes/modules/usermessage.lua:87


[ERROR] addons/toybox sweps/lua/weapons/weapon_super_g/shared.lua:356: bad argument #1 to 'GetDTBool' (number expected, got string)
  1. GetDTBool - [C]:-1
   2. Function - addons/toybox sweps/lua/weapons/weapon_super_g/shared.lua:356
    3. unknown - lua/includes/modules/usermessage.lua:87

[ERROR] addons/toybox sweps/lua/weapons/weapon_super_g/shared.lua:578: bad argument #2 to 'ChangePitch' (number expected, got no value)
  1. ChangePitch - [C]:-1
   2. unknown - addons/toybox sweps/lua/weapons/weapon_super_g/shared.lua:578

I’m sorry for posting a lot of lua errors but It’s gmod 12, what more could you expect ? XD

Here’s a thread that has resources of what changed from GMod 12 to 13: http://forum.facepunch.com/showthread.php?t=1337945

Thank you for the reply. I have already seen those pages and they didn’t help much with the SWEPs I’m converting currently.

Hard to fix these without seeing the actual Lua files, or at least the lines that the errors are on. Can you share the lua files?

http://s16.postimg.org/75q5oqh05/Untitled.png

This is the lua for the Can Nade.

http://s7.postimg.org/dad16voe3/Untitled.png

Lua for the Laser Gun.

http://s22.postimg.org/q68q11k9d/Untitled.png

Lua for Eat SWEP

http://s18.postimg.org/wh8bpubrt/Untitled.png

Lua for Scav JR

More screenshots will be up soon. When I can find the toybox files buried under gigabytes of gmod addons…


can:GetPhysicsObject():AddAngleVelocity( 600, math.random(-1200,1200), 0 )

  1. I can’t see the whole line, but you need to convert it to the new format for fonts.


local hasTF2 = file.Exists("sound/vo/SandwichEat09.wav", "GAME")

You can also find if the client has TF2 by using IsMounted, although, it seems file.Exists is better in the context that it’s used in.

  1. What is GetWorldEntity() defined as?

Thank you very much!

http://s28.postimg.org/obvcu9vx9/Untitled.png

Updated screenshot of the Laser Gun

When you say defined as… Do you mean to say what it’s supposed to do?
It’s supposed to make objects disappear with right click (as in sucking them in) and shooting them out with left click.

http://s1.postimg.org/ts50kfyxb/Untitled.png

Screenshot showing both errors on the AR-15

http://s12.postimg.org/ahqfgbby5/Untitled.png

Screenshot on the Shock Rifle

http://s27.postimg.org/oo0p6j3g3/Untitled.png

Screenshot on Katana

http://s29.postimg.org/5y7xrevgn/Untitled.png

Screenshot on NPC gun.

http://s3.postimg.org/u5am2titf/Untitled.png

Screenshot on Punt Cannon

The first error on the AR-15, I’m not exactly sure what’s wrong, I think it requires the FOV as a number rather than self.Fov

The second error on the AR-15
http://gmodwiki.net/Lua/Classes/Weapon/DefaultReload
It requires an ID inside the brackets.

For the shock rifle, WorldSound doesn’t exist. Try



sound.Play( "ut2k4/shockrifle/explosion.wav", self:GetPos() )


Try changing both lines on the Katana to



self:GetEyeTrace()


if that doesn’t work, do



LocalPlayer():GetEyeTrace()


As for the two last ones, I’m not sure on the NPC gun, and where is the error exactly on the last one?

The npc gun error is the TNPC
Punt cannon has two errors
GetDTBool
and
ChangePitch

You could try changing Tnpc to NPC but I’m not sure if that will fix it.

On the punt cannon:

Change “ent” to Entity so it’s Entity:GetDTBool

On the change pitch, change it to



if SERVER then self.ChargeSound:ChangePitch(100+self.dt.Charge/1.7, 0);end


On the katana fix. Both of them seemingly fix the error (according to the console) but the effect is still there, both attacks don’t harm anything.

The can nade still bugs out when you throw it. And the secondary function (to drink it and gain health) doesn’t display an error but it just does not work.

Also the model of the can nade doesn’t appear.
I could link the files so you can try it for yourself?