Developer
Overview
ML Planting exposes server and client exports for querying plant data, plus server-side handler hooks in server/handlers.lua (shipped unescrowed) for plant lifecycle events.
Server Exports
lua
1local plantType = exports.ml_planting:GetPlantTypeConfig(typeId)
2local allTypes = exports.ml_planting:GetAllPlantTypes()
3local categories = exports.ml_planting:GetCategories()
4local category = exports.ml_planting:GetCategoryConfig(categoryId)GetPlantTypeConfig(typeId): Returns the plant type definition tableGetAllPlantTypes(): Returns all plant type definitionsGetCategories(): Returns all categoriesGetCategoryConfig(categoryId): Returns a specific category config
Client Exports
lua
1local zoneId = exports.ml_planting:IsInGrowZone(coords)
2local plants = exports.ml_planting:GetNearbyPlants(distance)
3local entity = exports.ml_planting:GetPlantEntity(plantId)IsInGrowZone(coords): Returns the zone id if the coordinates are inside a growth zone,nilotherwiseGetNearbyPlants(distance): Returns the streamed plants within the given distance of the playerGetPlantEntity(plantId): Returns the local prop entity handle of a streamed plant
Server Event Handlers
Located in server/handlers.lua. Override to hook into plant lifecycle events.
server/handlers.lua
1function Handlers.OnPlantCreated(source, plantData)
2end
3
4function Handlers.OnPlantWatered(source, plant, item, amount)
5end
6
7function Handlers.OnPlantFertilized(source, plant, item, amount)
8end
9
10function Handlers.OnPlantHarvested(source, plant, rewards)
11end
12
13function Handlers.OnPlantDestroyed(source, plant)
14end
15
16function Handlers.CanPlant(source, seed, coords)
17 return true -- return false to block
18end
19
20function Handlers.CanHarvest(source, plant)
21 return true -- return false to block
22end
23
24function Handlers.ModifyHarvestRewards(source, plant, rewards)
25 return rewards -- modify and return
26endserver/handlers.lua
1function Handlers.OnPlantHarvested(source, plant, rewards)
2 exports['my_logging']:LogAction(source, 'harvested', plant.seed)
3endserver/handlers.lua
1function Handlers.CanHarvest(source, plant)
2 local job = Bridge.GetJob(source)
3 if job and job.name == 'police' then
4 return false
5 end
6 return true
7end