Lua Hooks - Jackarunda/gmod GitHub Wiki

Server

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.

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.

  1. Entity transceiver

The radio that was used.

  1. 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.

  1. 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 ply:IsAdmin() then
        return false, "negative, only admins can call this."
    end
end)

This code snippet restricts antimatter to admins only.


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.

  1. Entity transceiver

The radio that was used.

  1. String pkg

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

  1. Number time

The amount of time this request was going to take.

  1. Vector pos

The position this request was going to drop at.

Returns:

  1. Number newTime

The new time to override with.

  1. Vector newPos

The new position to override with.

Example:

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

This code snippet makes deliveries twice as fast for admins.


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.

  1. Entity workbench

The workbench that was used.

  1. 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.

  1. 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.

  1. Entity kit

The Build Kit used by the player.

  1. 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.

  1. 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.

  1. 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.

  1. Entity ent

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

  1. 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).

The functions below are upcoming.

JMod.AddNewRadioOutpost(tostring(teamID))

Description

This function is ran by developers to grant a team an additional outpost. Useful for radios working simultaneously on a team to speed up production.

Arguments:

Team teamID Specifies the team to add the outpost to.

JMod.RemoveRadioOutpost(tostring(teamID))

Description

This function is ran by developers to strip a team of an additional outpost. Useful for punishing a team for whatever reason, such as losing a control point, etc.

Arguments:

Team teamID Specifies the team to remove the outpost from.