5E Product Walkthrough Playlist
Page 2 of 2 First 12
  1. #11
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    26,684
    Blog Entries
    1
    Please do share your code!


    FG Con 6 – April 17-19th 2015 - register at www.fg-con.com for all the latest info.

  2. #12
    It's not completed (with no guarantee it can be completed) and I'm not Lua expert by any stretch of imagination but following shows my way of thinking:

    Helper functions:
    Code:
    function serializeTable(val)
        local tmp = ""
        for k, v in pairs(val) do
            tmp =  tmp .. v.result .. "," .. v.type .. ";"
        end
    
        return tmp
    end
    
    function deserializeTable(val)
        local result = {}
        for k,i in string.gmatch(val, "(%w+),(%w+)") do
            local vvv = {}
            vvv.result = k
            vvv.type = i
            table.insert(result, vvv)
        end
        return result
    end
    
    
    function getReRoll(aDice, iRoll)
        local rRoll = {}
        rRoll.aDice = aDice
        rRoll.nMod = iRoll.nMod 
        rRoll.sType = iRoll.sType
        rRoll.bSecret = iRoll.bSecret 
        rRoll.nStrain = iRoll.nStrain
        rRoll.sDesc = iRoll.sDesc
        rRoll.rPreviousResult = serializeTable(iRoll.aDice)
        return rRoll
    end
    ResultHandler:
    Code:
    function onResult(rSource, rTarget, rRoll)
    
    	local isMaxResult = function(rDie)
    		if tonumber(rDie.type:match("^d(%d+)")) == rDie.result then
    			return rDie.result
    		else
    			return 0
    		end
    	end
    	
        explode = {}
    	for i,die in ipairs(rRoll.aDice) do
    		local reroll = isMaxResult(die)
    		if reroll>0 then
                table.insert(explode, die.type)
    		end
    	end
    
        if rRoll.rPreviousResult then
            prev = deserializeTable(rRoll.rPreviousResult)
            for i,roll in ipairs(prev) do
                table.insert(rRoll.aDice, 1, roll)
            end
        end
        if table.getn(explode) > 0 then
            ActionsManager.performAction(draginfo, rActor, getReRoll(explode, rRoll));        
            return false;
        end;
    	
      local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
      local nTotal = ActionsManager.total(rRoll);
    
      Comm.deliverChatMessage(rMessage);
    end
    Basically, it delivers message to chat only if no dice exploded. If exploding dice exist, it serializes aDice table to string, stores it in custom attribute and rolls again with only exploding dice - when it gets to this point again and previous roll result exists, the method deserializes it to aDice table.

    What is not done is handling of draginfo (I'm not sure - is it lost?) and rActor. I simply had no time to analyze this so it might be a case that it cannot be done. :/ Fantasy Grounds surprised me like that more than once.

  3. #13
    Oberoten's Avatar
    Join Date
    May 2006
    Location
    Älvsbyn, Sweden
    Posts
    2,620
    One last question, where and how would I add in a target value for a roll?
    For your Ars Magica needs :
    https://fgrepository.com




    Atque in perpetuum frater, Ave atque vale.

  4. #14
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    Quote Originally Posted by Oberoten View Post
    One last question, where and how would I add in a target value for a roll?
    Have a look at the 3.5e action ability roll. My post in #3 shows a 20 being set as the target of the roll and then my post in #7 shows the rRoll.nTarget value being used to signal success or failure.
    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)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Character Create Playlist

Log in

Log in