PDA

View Full Version : Beginner Question on Functions



jackkerouac
May 25th, 2020, 21:52
Okay, so I am fairly new to working in LUA and definitely in programming with Fantasy Grounds. I want to make a simple change to a function within the CoreRPG ruleset function addEffect. The original funtion:


function addEffect(sUser, sIdentity, nodeCT, rNewEffect, bShowMsg)
...
end

does its thing. I want to make effects placed to be GM only. I realize you can do this from within FGC, but I want to do it just to learn. From what I understand, the code I wish to add would look like:


rNewEffect.nGMOnly = 1;

This seems to do what I want, but I am modifying the CoreRPG ruleset directly, which I don't want to do.

SO, the question is, how to I hijack this function to add my own code? Is there a tutorial about doing this?

I would really appreciate a point in the right direction, thanks!

Trenloe
May 25th, 2020, 22:59
addEffect has a couple of places where you can call custom functions: fCustomOnEffectAddStart or fCustomOnEffectAddEnd. Both of these pass rNewEffect so you can add/change the contents of that LUA table.

These custom functions are set using EffectManager.setCustomOnEffectAddStart(function) or EffectManager.setCustomOnEffectAddEnd(function)

Look in the 5E ruleset, scripts\manager_effect_5e.lua for an example of setCustomOnEffectAddStart.

jackkerouac
May 25th, 2020, 23:25
Thank you!

Amazing. It reduced my code from copying an entire function to the following:


function onInit()
EffectManager.setCustomOnEffectAddStart(customAddE ffect);
end

function customAddEffect(rNewEffect)
-- ALWAYS add effects as GM Only
rNewEffect.nGMOnly = 1;
end

I really appreciate it!

Any idea where I find these types of functions? Is it just a matter of going through the ruleset code or are they documented somewhere?

Trenloe
May 25th, 2020, 23:54
Any idea where I find these types of functions? Is it just a matter of going through the ruleset code or are they documented somewhere?
Pretty much a case of going through the ruleset code and seeing if there’s any custom functions. Most global script packages in CoreRPG will have at least a couple.