Garry's Mod Wiki

Updating Scripts From GMod 12 to GMod 13

“Why your scripts are now broken”

Several changes to the Lua API were made in the transition between GMod 12 to GMod 13. This page is an attempt to highlight them. It was originally created in the form of a Google Document created by Garry. The old method of doing things is listed on the left, while the new is on the right side.

Changes

  • The PANEL:Paint hook now receives a width and height parameter. This shouldn't affect much in itself - but if you're calling a derma.SkinHook you will need to pass the width and height along, as it needs these values too now. You could start doing this now in your code without any negative effects.
Old New
  • Entity:SetColor and Entity:GetColor now deal with Colors only. Not with single variables. This is something that is always mentioned - and since we're breaking stuff anyway now seems to be a good time to make the change. SetColor will set the color to purple if the passed variable isn't a Color.
Old New
  • KeyValuesToTable and TableToKeyValues are now in the util library.
Old New
  • SetMaterialOverride, cam.StartMaterialOverride (which did the same thing) are removed and replaced with render.MaterialOverride.
Old New
  • IMaterial:SetMaterialTexture is now IMaterial:SetTexture

  • DMultiChoice is replaced by DComboBox. When I originally made them they were named the wrong way around. DMultiChoice is now removed. This is because DListView was basically recreating all the functionality of DMultiChoice. DListView has extra settings to remove colums and headers - which make it exactly like the old DComboBox. Complicated eh?

SetEditable(boolean) doesn't exist on DComboBox
  • DSysButton was removed. This panel used the Marlett font to create icons such as the "close" button for windows. This isn't needed anymore since we're using GWEN skins. Plus it didn't work properly on Mac anyway.

  • Datastream module is removed. Datastream was less than optimal when it came to networking stuff. We now have the new net - which doesn't work in exactly the same way, but is much more optimized to do this stuff. You should use the net library instead of datastream.

  • DBevel is removed. This panel was purely decorational - so it shouldn't be hard for you to replace.

  • utilx no longer exists. Please replace all ocurances of utilx in your code to the util.

  • entity.Classname. Caps is now enforced properly. Use entity.ClassName instead. (N is upper case)

  • TOOL:RenderToolScreen is now TOOL:DrawToolScreen

Old New
  • file.Find now returns two tables - files and folders. The second argument is the search path.
    • "LUA" searches the lua files (in /lua/, in your gamemodes, in all the addons). This replaces file.FindInLua.
    • "GAME" searches all the mounted content (main folder, addons, mounted games etc).
    • "MOD" searches only the garrysmod folder.
    • "DATA" searches in the data folder. Type "path" in the console to see the paths.
Old New
file.Find("models/model.mdl")

|

file.Find("models/model.mdl", "GAME")

| |

file.FindDir("exampledir")

|

file.Find("example", "DATA")

(2nd return) | |

file.Read("settings/users.txt", true)

|

file.Read("settings/users.txt", "GAME")

| |

file.Read("example.txt")

|

file.Read("example.txt", "DATA")

| |

file.Exists("example.txt")

|

file.Exists("example.txt", "DATA")

| |

file.Exists("models/models.mdl", true)

|

file.Exists("models/models.mdl", "GAME")

|

Old New
  • DColorMixer.RGBBar is now DColorMixer.RGB. GMod 13 uses Grocel's DColorMixer.

  • STool language phrases changed.

Old New
  • The http has changed
Old New
  • timer calls no longer take varargs to pass to callback.
Old New
  • Angle functions have been unified. Before some were Set/GetAngles and some were Set/GetAngle. Now they're all Set/GetAngles()
Old New
Old New
  • math duplicate functions removed (Deg2Rad, Rad2Deg)
Old New
  • server_settings module removed, use cvars instead.

  • Renamed Material:[Get|Set]Material to Material:[Get|Set]** (ie, :SetVector instead of :SetMaterialVector)

  • Moved some functions into the game.

Old New
isDedicatedServer()

|

| |

|

| |

|

|

Old New
Old New
  • Entity Colour Alpha Changes. In previous version of GMod setting the Alpha of an entity would also change its render mode. In 13 this behaviour was stopped - as it interfered with other things (like entities showing as invisible in some maps). This means that in 13 you need to change the render mode too - if you want your entity to show as transparent.
Old New
attacker, inflictor, amount

have been removed as they're available by querying the passed damageinfo.

Old New
  • The bitwise operators have been removed. I know the old way was nicer - but we took a vote - sorry!
Old New
  • ValidEntity has been removed. Use IsValid instead.
Old New

Page Links


Special Pages


Wikis

?

Render Time: 69ms

DB GetPage 4
Generate Html 34
SaveChanges (1) 9
Render Body 0
Render Sidebar 19