Lua Hooks - Jackarunda/gmod GitHub Wiki

NOTE: For any hooks that control if something can be crafted or ordered, it is recommended to avoid using too much conditions as they can act strangely such as returning a certain message as a second argument in the center of your screen no matter what item is chosen. If a particular item has a lot of conditions, try packing them into one local variable and then using that variable as a condition.

Shared

JMod_CanRadioRequest(ply, transceiver, pkg)

Description

This hook is called when a player requests a package with the Aid Radio. Use it to add restrictions to packages under certain conditions.

Arguments:

  1. Entity ply The player who requested aid.

  2. Entity transceiver The radio that was used.

  3. String pkg Name of the package. Get package info with JMOD_CONFIG.RadioSpecs.AvailablePackages[pkg].

Returns:

  1. Boolean override If false, the radio request is denied.

  2. String msg Message given the the player if the request is denied. (Make it tacticool!)

Example:

hook.Add("JMod_CanRadioRequest", "MyRadioHook", function(ply, radio, pkg)
    if pkg == "antimatter" and not JMod.IsAdmin(ply) then
        return false, "negative, only admins can call this."
    end
end)

This code snippet restricts antimatter to admins only.

Server


JMod_CustomRadioRequest(ply, transceiver, pkg)

Description

This hook is called when the radio doesn't have any other response to the request, you can use this hook for things like custom airstrikes.

Arguments:

  1. Entity ply The player who requested aid.

  2. Entity transceiver The radio that was used.

  3. String message The player's message.

Returns:

  1. Boolean override If true, the radio request is accepted.

  2. String msg Response to the player's request

Note:

This is an advanced hook to use


JMod_RadioDelivery(ply, transceiver, pkg, time, pos)

Description

This hook is called after a package has been confirmed. You can modify how long it takes or where it is dropped here.

Arguments:

  1. Entity ply The player who requested aid.

  2. Entity transceiver The radio that was used.

  3. String pkg Name of the package. Get package info with JMOD_CONFIG.RadioSpecs.AvailablePackages[pkg].

  4. Number time The amount of time this request was going to take.

  5. Vector pos The position this request was going to drop at.

Returns:

  1. Number newTime The new time to override with.

  2. Vector newPos The new position to override with.

Example:

hook.Add("JMod_RadioDelivery", "MyDeliveryHook", function(ply, radio, pkg, time, pos)
    if JMod.IsAdmin(ply) then
        return math.ceil(time * 0.5), nil
    end
end)

This code snippet makes deliveries twice as fast for admins.


JMod_OnRadioDeliver(stationID, dropPos)

Description

This hook is called when a package is about to be delivered, you can override the method of delivery here

Arguments:

  1. Number stationID All info about the station, the last caller and it's package can be obtained with JMod.EZ_RADIO_STATIONS[stationID]

  2. Vector dropPos The vector to drop the package

Returns:

  1. Bool alternateDelivery Set this to true to cancel the default delivery method, this is important if you don't want two packages showing up at once

Note: This is a rather advanced hook and should only be used if you know what you are doing. Ask for help in the discord if you need advice


JMod_CanWorkbenchBuild(ply, workbench, itemName)

Description

This hook is called when a player tries to craft an entity in the workbench.

Arguments:

  1. Entity ply The player who tried to craft.

  2. Entity workbench The workbench that was used.

  3. String itemName Name of the item. Get recipe info with JMOD_CONFIG.Recipes[itemName].

Returns:

  1. Boolean override If false, the object will not be built.

  2. String msg Message given the the player if the object is not built.


JMod_CanKitBuild(ply, kit, itemName)

Description

This hook is called when a player tries to craft an entity in the workbench.

Arguments:

  1. Entity ply The player who tried to craft.

  2. Entity kit The Build Kit used by the player.

  3. Table info A table containing info about the craftable object. It is in the format of {id, printName, cost, offset}, where cost is a key-value table containing the resource type and amount, and offset is the multiplier of height the object is spawned at.

Note that in addition to the objects in JMOD_CONFIG.Blueprints, this also contains two actions, ez nail and package.

Returns:

  1. Boolean override If false, the object will not be crafted.

  2. String msg Message given the the player if the object is not crafted.

Example:

hook.Add("JMod_CanKitBuild", "MyKitHook", function(ply, kit, info)
    print(ply:GetName() .. " tried to make " .. info[1] .. "! Its cost is:")
    PrintTable(info[3])
end)

If you tried to make a sentry, this would print:

8Z tried to make EZ Sentry! Its cost is:
parts = 200
power = 100
ammo = 300
advparts = 20

JMod_FieldHospitalHeal(ent, ply)

Description

This hook is called when a field hospital is about to heal the player.

Arguments:

  1. Entity ent The field hospital entity.

  2. Entity ply The player about to be healed.

Returns:

  1. Boolean / Number override If false, the heal will abort. This won't kick the player out - the field hospital will still continue trying to heal the player, running this hook every time. If override is a number, the amount of health restored this tick will be set to this value (clamped by the player's max health).

JMod_MedkitHeal(ply, ent, kit)

Description

This hook is called when a field hospital is about to heal the player.

Arguments:

  1. Entity ply The player using the medkit.

  2. Entity ent The entity about to be healed. This can be the player themself, an NPC, or a different player.

  3. Weapon kit The medkit used by the player.

Returns:

  1. Boolean / Number override

If false, the heal will abort. If override is a number, the amount of health restored this tick will be set to this value (clamped by the entity's max health).


JMod_PostLuaConfigLoad(config)

Description

This hook is run as soon as the lua config is validated and loaded, you can insert or modify things to the JMod tables safely here

Arguments:

  1. Table config

JMod_SalvageResults(ent, results, mat, mdl, specialized)

Description

This is run when something checks the salvage yield of an entity

Arguments:

  1. Entity ent The entity to check

  2. Table results The current results that will be returned

  3. String mat The physics material of the entity

  4. String mdl The model name of the entity

  5. Bool specialized Whether or not this has specialized results depending on different factors

Returns:

  1. Boolean / Table FinalResults If false gives no results, or replace the results with your own

  2. String Message A message to append to the normal debug command


JMod_EZarmorSync(ply)

Description

This hook is run whenever JMod syncs armor data between players.

Arguments:

  1. Entity ply Player who is the subject of the sync

JMod_CanDestroyProp(prop, blaster, pos, power, range, ignoreVisChecks)

Description

Called when JMod is about to destroy/loosen an object, such as the blasting machine or TNT

Arguments:

  1. Entity prop Prop that is attempted to be destroyed or loosened

  2. Entity blaster Entity that is doing the destroying, if you want to know the player responsible use JMod.GetEZowner(blaster)

  3. Number power Power of the explosion

  4. Number range Range of the explosion, measured in HU

  5. Bool ignoreVisChecks If the blast is ignoring visibility (can destroy through walls)

Returns:

  1. Boolean / Number override Return false to stop all default loosening or destroying of the prop

JMod_CanDestroyDoor(door, blaster, pos, power, range, ignoreVisChecks)

Description

Called when JMod is about to destroy/loosen a door, such as an explosive or an axe

Arguments:

  1. Entity door Door that is attempted to be destroyed or loosened

  2. Entity blaster Entity that is doing the destroying, if you want to know the player responsible use JMod.GetEZowner(blaster)

  3. Number power Power of the destruction

  4. Number range Range of the explosion, measured in HU

  5. Bool ignoreVisChecks If the blast is ignoring visibility (can destroy through walls)

Returns:

  1. Boolean / Number override Return false to stop all default loosening or destroying of the door

JMod_ShouldAttack(attacker, target, vehiclesOnly, peaceWasNeverAnOption)

Description

This hook is ran when a 'smart' entity is about to attack another entity

Arguments:

  1. Entity attacker The attacking ent, usually a turret or a mine

  2. Entity target The target, can be anything really

  3. Bool vehiclesOnly Whether this attacker is only concerned about vehicles, like the AT-Mine

  4. Bool peaceWasNeverAnOption Whether this attacker is going to default to attack

Returns:

  1. Boolean override Return true or false here to dictate whether or not to attack