How i can override a existing lua function?

hello for create the auto kill animal pasture i need to override this function
function WaitForPastureVacancy:pasture_check()
local pasture_component = self._args.pasture:get_component(‘stonehearth:shepherd_pasture’)
if pasture_component and
pasture_component:get_num_animals() < pasture_component:get_min_animals() then
return true
return false

but i dont find how to do that in the forum or in the current mod.
i dont see mixinto for lua.

i dont know how i can listen this event.

can you explain me ?


I may be wrong but aren’t mixintos for JSONs only? I thought LUA functions can’t be “patched”.

yes i think but how listen ? :slight_smile:

i see that : in the manifest
"controllers": {
“class:jeweler”: “file(jobs/jeweler/jeweler.lua)”

You could add your own AI actions to the shepherding_ai_pack.json with a mixinto. Then copy your desired functions to your own actions, that way you have total control (but make sure to name everything different from the file you copied it from).
Not all the AI actions are the same, some of them execute compound actions, some of them wait on events before calling other actions, some of them execute a specific task, so be careful when fiddling with this.

AI can be tricky. We need better tutorials for it (and for campaigns). It’s one of the most complex things to mod.

Using overrides with existing Lua files sometimes produces unwanted behaviors, or even bugs. And might break between updates if the file you’re overriding gets modified by the devs.

sorry i use now : Quests, Event trigger Tutorial needed

I would think that instead of overriding an existing function, you would add another one to the list for the shepherds for the harvesting of animals once the max or a certain population is reached. You would have to add a way for the player to chose max or the number, and also the amount to be harvested.

@Relyss Is there a way to exclude certain animals from a harvest, such as Bluebell?

here in mod i dont override a existing lua function.
i tested to create a new listen of event.