Developer

2 min readUpdated 2 weeks ago

Overview

ML Recoil exposes hooks in two escrow-ignored files, client/main_open.lua and server/server_open.lua, plus two client exports for a staff menu.

Client Hooks

Located in client/main_open.lua.

client/main_open.lua
1function OnWeaponEquipped(weaponHash, profile)
2    return true
3end
4
5function OnShotFired(weaponHash, totalMultiplier)
6end
7
8function OnAimStateChanged(weaponHash, isAiming)
9end
  • OnWeaponEquipped: runs when a weapon with a profile is equipped. Return false to skip recoil for it
  • OnShotFired: runs after every shot with the stance and progressive multiplier, without the skill rules. It also fires during drive-bys, when the camera kick is skipped
  • OnAimStateChanged: runs when the player starts or stops aiming

Server Hooks

Located in server/server_open.lua.

server/server_open.lua
1function OnBeforePublish(source, weaponName, profile)
2    return true
3end
4
5function OnProfilePublished(source, weaponName, profile)
6end
7
8function OnBeforeTestRange(source, weaponName)
9    return true
10end
  • OnBeforePublish: runs before a profile saved in the panel goes live. Return false to refuse it. Adding or resetting a weapon does not call it
  • OnProfilePublished: runs after a profile is saved and sent to every player. Adding or resetting a weapon does not call it
  • OnBeforeTestRange: runs before an admin enters the test range. Return false to refuse it

Client Exports

  • MLAdminOpen(): opens the admin panel, permission checked
  • MLAdminPanel(): label and icon of the panel, for a staff menu that lists admin tools

Examples

client/main_open.lua
1function OnShotFired(weaponHash, totalMultiplier)
2    exports.ml_skills:RequestXp('personal', 2, 'recoil_shot')
3end

Add a recoil_shot entry to Config.XpListeners of ml_skills with the same category and XP and no interval or condition. The shipped shooting listener already grants XP on its own.

client/main_open.lua
1function OnWeaponEquipped(weaponHash, profile)
2    if weaponHash == `WEAPON_REVOLVER` then return false end
3    return true
4end
server/server_open.lua
1function OnProfilePublished(source, weaponName, profile)
2    print(('%s updated %s'):format(GetPlayerName(source), weaponName))
3end