Developer

3 min readUpdated 2 weeks ago

Overview

Other resources read the loot setup through server exports. The loot flow is changed in open/handlers_server.lua and open/handlers_client.lua, which stay unencrypted. Every handler returns the default value, so change only the ones you need.

Server Exports

lua
1local config = exports['ml_lootprops']:GetPropConfig(propHash)
2local category = exports['ml_lootprops']:GetCategory('animals')
3local props = exports['ml_lootprops']:GetAllProps()
4local categories = exports['ml_lootprops']:GetAllCategories()
  • GetPropConfig(propHash): settings of a configured model, or nil
  • GetCategory(categoryId): settings of a category, or nil
  • GetAllProps(): list of configured models as { hash, model }
  • GetAllCategories(): list of categories as { id, label }

Server Handlers

Located in open/handlers_server.lua.

Loot Flow

open/handlers_server.lua
1Handlers.OnBeforeClaim = function(source, propHash, coords, config)
2    return true
3end
4
5Handlers.OnAfterClaim = function(source, propHash, coords, items, config)
6end
7
8Handlers.ModifyLoot = function(source, propHash, fixedLoots, probabilityLoots, config)
9    return fixedLoots, probabilityLoots
10end
11
12Handlers.GetLootMultiplier = function(source, propHash, config)
13    return 1.0
14end
15
16Handlers.GetBonusLoot = function(source, propHash, config)
17    return nil
18end
  • OnBeforeClaim: runs before the items are given. Return false to stop the claim
  • OnAfterClaim: runs after the items are given. items lists them
  • ModifyLoot: edits the guaranteed and chance tables before the roll
  • GetLootMultiplier: multiplies item amounts. 2.0 doubles them
  • GetBonusLoot: extra items on top, as { { name = 'item', amount = 1 } }

Cooldowns

open/handlers_server.lua
1Handlers.GetCooldownOverride = function(source, propHash, baseCooldown, config)
2    return nil
3end
4
5Handlers.CanBypassCooldown = function(source, propHash)
6    return false
7end
  • GetCooldownOverride: return seconds to replace the personal cooldown
  • CanBypassCooldown: return true to let the player skip the cooldown

Access

open/handlers_server.lua
1Handlers.CanPlayerLoot = function(source, propHash, config)
2    return true, nil
3end
4
5Handlers.CanPlayerLootInArea = function(source, coords)
6    return true, nil
7end
  • CanPlayerLoot: return false, 'reason' to refuse a model to that player
  • CanPlayerLootInArea: same check by position, for territories or event areas

Dispatch

open/handlers_server.lua
1Handlers.ShouldTriggerDispatch = function(source, propHash, config)
2    return nil
3end
  • ShouldTriggerDispatch: true or false forces the alert, nil keeps the configured chance

Client Handlers

Located in open/handlers_client.lua.

Interaction

open/handlers_client.lua
1Handlers.CanInteractWithProp = function(propHash, entity, coords)
2    return true
3end
4
5Handlers.GetCustomTargetLabel = function(propHash, entity, config)
6    return nil
7end
8
9Handlers.GetCustomTargetIcon = function(propHash, entity, config)
10    return nil
11end
12
13Handlers.GetCustomTargetDistance = function(propHash, entity, config)
14    return nil
15end
16
17Handlers.AddCustomTargetOptions = function(propHash, entity, config)
18    return {}
19end
  • CanInteractWithProp: return false to hide the option on that object
  • GetCustomTargetLabel, GetCustomTargetIcon: return a string to replace the label or icon, such as 'fas fa-skull'
  • GetCustomTargetDistance: return a number to replace the interaction range
  • AddCustomTargetOptions: extra target options on the same object

Looting

open/handlers_client.lua
1Handlers.CanLootProp = function(propHash, entity, config)
2    return true, nil
3end
4
5Handlers.OnBeforeLoot = function(propHash, entity, config)
6end
7
8Handlers.OnAfterProgress = function(propHash, entity, config)
9    return true
10end
11
12Handlers.OnLootFailed = function(propHash, entity, reason)
13end
  • CanLootProp: return false, 'reason' to stop the loot after the player interacts
  • OnBeforeLoot: runs before the progress bar
  • OnAfterProgress: runs when the progress bar ends. Return false to cancel the claim
  • OnLootFailed: runs when a loot fails, for example a failed minigame

Object Tracking

open/handlers_client.lua
1Handlers.OnPropDetected = function(entity, propHash, coords)
2end
3
4Handlers.OnPropLost = function(entity, propHash)
5end
  • OnPropDetected: a configured object comes within about 20 meters of the player
  • OnPropLost: a tracked object leaves that range

Examples

open/handlers_server.lua
1Handlers.GetLootMultiplier = function(source, propHash, config)
2    local day = os.date('*t').wday
3    if day == 1 or day == 7 then return 2.0 end
4    return 1.0
5end
open/handlers_server.lua
1Handlers.CanBypassCooldown = function(source, propHash)
2    local job = Bridge.GetJob(source)
3    return job and job.name == 'vip'
4end
open/handlers_server.lua
1local eventActive = false
2
3Handlers.CanPlayerLoot = function(source, propHash, config)
4    if eventActive then
5        return false, 'Looting is closed during the event'
6    end
7    return true
8end