Garry's Mod

Garry's Mod

117 ratings
[LUAmmer]
   
Award
Favorite
Favorited
Unfavorite
Content Type: Addon
Addon Type: Tool
Addon Tags: Build, Fun, Realism
File Size
Posted
Updated
17.358 KB
17 Feb @ 4:35pm
18 Jul @ 10:03am
10 Change Notes ( view )

Subscribe to download
[LUAmmer]

Description
Description:
A simple API that allows you to "inject" lua code into hammer maps. Fast and simple. Entries can be added using entity names, classes, or positions. Everything is fully networked. Great for adding extra functionality or applying fixes for engine entities.

----------------------------------------------------------------------
Some Of The Features:
  • LUAmmer.AddEntry(map, nameORclassORpos, func)
    Used to add LUAmmer entries. Entries get only added when the specified map gets loaded.

    map
    Entries will be loaded only if the specified map is loaded
    nameORclassORpos
    Name, class, or position of an entity that you wish to inject lua to
    func
    Pretty much an Initialize function, here you can apply your code. Mind that it i shared between the server and the clients

    Examples:
    1. Of using the entity's class:

      LUAmmer.AddEntry( "testroom2_extended", "npc_citizen", function(self) --Code end )

    2. Of using the entity's name:

      LUAmmer.AddEntry( "testroom2_extended", "thomas", function(self) --Code end )

    3. Of using the entity's position:

      LUAmmer.AddEntry( "testroom2_extended", "254 2001 -450", function(self) --Code end )

    4. Of using multiple identifiers:

      LUAmmer.AddEntry( "testroom2_extended", "thomas_1, thomas_2, thomas_3", function(self) --Code end )

  • LUAmmer.RemoveEntry(nameORclassORpos)
    Used to remove entries from the LUAmmer. Really should be used only when working on a map.

    nameORclassORpos
    Name of the entry that you wish to remove.

  • LUAmmer.CreateVar(ent, var, val)
    Used to create variables for entities that should be saved by duplication tools (Duplicator and Adv. Duplicator 2). Once set, it can only be changed via SetVar function

    ent
    Entity that you want to create a variable for
    var
    Name of your variable
    val
    Value of your variable

    Example:
    1. Of creating a variable "m_bCanBeUsed". Now it can be overridden with SetVar to false and it will load as such when loading a save:

      LUAmmer.CreateVar(self, "m_bCanBeUsed", true)

  • LUAmmer.SetVar(ent, var, val)
    Used to change/override saved variables

    ent
    Entity that you want to override a variable for
    var
    Name of your variable
    val
    Value of your variable

  • ENT:LUAmmerOutputHook(entOutput, func)
    Used to add functions to entity outputs (I/O)

    entOutput
    Name of an output (OnPlayerPickup for an example)
    func
    Function to run when output gets fired

    Example:
    1. Of using prop_physics's "OnPlayerPickup" output which runs when players pick it up by hand or via the gravity gun:

      prop:LUAmmerOutputHook("OnPlayerPickup", function(self, activator, caller) -- Code end)

  • ENT:LUAmmerRelatedEntity(name)
    Used to easily get a reference of entities related to our entity via name and ID. This function will search for the entity with the provided name and return the first match. If your entity doesn't have an ID ("tank_turret" and no digit at the and) or has no name at all, the function will look for an entity with an exact provided name.

    name
    Name of the entity (tank_turret for an example)

    Example:
    1. Of finding an entity related to ours. Our entity's name is "tank_turret1" in this example:

      local seat = self:LUAmmerRelatedEntity("tank_seat")
      Since our entity's name was "tank_turret1", function looked for an entity named "tank_seat1" and returned it (if found)

----------------------------------------------------------------------

CREDITS:
  • Me - Coding,
  • Valve - Not Half-Life 3.
Have Fun! :B1:

tags: testroom2 hl2beta beta
36 Comments
filz0  [author] 29 Jul @ 3:57am 
No injecting here, you just reference the choosen entities via there classes, names or position. You create sort of entries, LUAmmer then checks entities on spawn and if there is a reference for them. This allows you to make hammer entities run lua code, fix them using lua, add client sided code, make them work with Gmod save system or even script the entire map. Entries have to be created via a separated Lua file. For a reference you can checkout testroom2_extended.
Goose 29 Jul @ 2:48am 
Hey filz0, got a question about how this works?

I actually asked a question on the hammer subreddit similar to this.

I assume this is an ingame API that only injects code into either the Lua script files for gmod or does this somehow do it into the bsp in real time.

Does this code persist and somehow save itself into the bsp upon a session end?

And if it does persist does it then require 'packing' using VIDE and/or just a quick update of the maps add-on page
kotye55 18 Jul @ 10:29am 
Thanks.
filz0  [author] 18 Jul @ 10:03am 
It should be fine now.
filz0  [author] 18 Jul @ 9:28am 
Hmm, seems like the author has used the incorrect skybox texture. I'll see if I can do anything on my end.
kotye55 18 Jul @ 8:52am 
https://steamproxy.net/sharedfiles/filedetails/?id=2862069950 this map for some reason gets checkermark cubemaps when exiting the spawn room. is there any reason why this addon is causing that issue?
filz0  [author] 25 Jun @ 1:36pm 
@ArgyBargyGuy Nvm, I've found the issue in another addon. I'll fix it asap, this warning may be ignored.
filz0  [author] 25 Jun @ 1:29pm 
@ArgyBargyGuy Do you have many addons? Mind giving me the list?
filz0  [author] 25 Jun @ 1:29pm 
@ArgyBargyGuy This message was not sent by LUAmmer, there is no function or even a piece of code to make such a message. Somebody is trolling with you.