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:
-
Entity
ply
The player who requested aid. -
Entity
transceiver
The radio that was used. -
String
pkg
Name of the package. Get package info withJMOD_CONFIG.RadioSpecs.AvailablePackages[pkg]
.
Returns:
-
Boolean
override
Iffalse
, the radio request is denied. -
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:
-
Entity
ply
The player who requested aid. -
Entity
transceiver
The radio that was used. -
String
message
The player's message.
Returns:
-
Boolean
override
Iftrue
, the radio request is accepted. -
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:
-
Entity
ply
The player who requested aid. -
Entity
transceiver
The radio that was used. -
String
pkg
Name of the package. Get package info withJMOD_CONFIG.RadioSpecs.AvailablePackages[pkg]
. -
Number
time
The amount of time this request was going to take. -
Vector
pos
The position this request was going to drop at.
Returns:
-
Number
newTime
The new time to override with. -
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:
-
Number
stationID
All info about the station, the last caller and it's package can be obtained withJMod.EZ_RADIO_STATIONS[stationID]
-
Vector
dropPos
The vector to drop the package
Returns:
- 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:
-
Entity
ply
The player who tried to craft. -
Entity
workbench
The workbench that was used. -
String
itemName
Name of the item. Get recipe info withJMOD_CONFIG.Recipes[itemName]
.
Returns:
-
Boolean
override
Iffalse
, the object will not be built. -
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:
-
Entity
ply
The player who tried to craft. -
Entity
kit
The Build Kit used by the player. -
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:
-
Boolean
override
Iffalse
, the object will not be crafted. -
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:
-
Entity
ent
The field hospital entity. -
Entity
ply
The player about to be healed.
Returns:
- Boolean / Number
override
Iffalse
, 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:
-
Entity
ply
The player using the medkit. -
Entity
ent
The entity about to be healed. This can be the player themself, an NPC, or a different player. -
Weapon
kit
The medkit used by the player.
Returns:
- 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:
- Table
config
JMod_SalvageResults(ent, results, mat, mdl, specialized)
Description
This is run when something checks the salvage yield of an entity
Arguments:
-
Entity
ent
The entity to check -
Table
results
The current results that will be returned -
String
mat
The physics material of the entity -
String
mdl
The model name of the entity -
Bool
specialized
Whether or not this has specialized results depending on different factors
Returns:
-
Boolean / Table
FinalResults
If false gives no results, or replace the results with your own -
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:
- 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:
-
Entity
prop
Prop that is attempted to be destroyed or loosened -
Entity
blaster
Entity that is doing the destroying, if you want to know the player responsible useJMod.GetEZowner(blaster)
-
Number
power
Power of the explosion -
Number
range
Range of the explosion, measured in HU -
Bool
ignoreVisChecks
If the blast is ignoring visibility (can destroy through walls)
Returns:
- 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:
-
Entity
door
Door that is attempted to be destroyed or loosened -
Entity
blaster
Entity that is doing the destroying, if you want to know the player responsible useJMod.GetEZowner(blaster)
-
Number
power
Power of the destruction -
Number
range
Range of the explosion, measured in HU -
Bool
ignoreVisChecks
If the blast is ignoring visibility (can destroy through walls)
Returns:
- 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:
-
Entity
attacker
The attacking ent, usually a turret or a mine -
Entity
target
The target, can be anything really -
Bool
vehiclesOnly
Whether this attacker is only concerned about vehicles, like the AT-Mine -
Bool
peaceWasNeverAnOption
Whether this attacker is going to default to attack
Returns:
- Boolean
override
Returntrue
orfalse
here to dictate whether or not to attack