5E Character Create Playlist
  1. #1

    Beginner Question on Functions

    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:

    Code:
    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:

    Code:
    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!

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    26,870
    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.
    FG Con 16 Fantasy Grounds Online RPG Convention - Postponed New date To Be Confirmed.
    Register at www.fg-con.com for all the latest info.

    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3
    Thank you!

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

    Code:
    function onInit()
    	EffectManager.setCustomOnEffectAddStart(customAddEffect);
    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?

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Newcastle, UK (for a bit)
    Posts
    26,870
    Quote Originally Posted by jackkerouac View Post
    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.
    FG Con 16 Fantasy Grounds Online RPG Convention - Postponed New date To Be Confirmed.
    Register at www.fg-con.com for all the latest info.

    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
FG Spreadshirt Swag

Log in

Log in