Dungeons & Dragons 2024 Core Rulebooks Pre-Order
  1. #1

    help with a custom versus roll

    So I am trying to create a custom vs roll and having trouble following through some of the existing examples in 3.5e and 5e rulesets. Essentially what I am doing is taking in a power object that has a source and vs ability that rolls (ex: strength vs prowess). I am able to get the data for each value with bonuses, however, I am having trouble figuring how to add a target diceroll to add to its ability score for the check. Any help would be appreciated.

    Code:
    function rollPower(rSource, rTarget, rRoll)
    	Debug.chat("in rollHandlers.rollPower() - line 40");
    	local rMessage = ActionsManager.createActionMessage(rSource, rRoll);	
    	rMessage.text = "[POWER]" .. rMessage.text;
    	local nTotal = 0;
    		
    	if not rTarget then		
    		Debug.chat("in rollHandlers.rollPower() - line 46 - no target");
    		nTotal = nTotal + rRoll.nMod;        
            --  Create a message from the rSource and rRoll parameters using CoreRPGs createActionMessage function
    		
            rMessage.text = rMessage.text .. " | Raw Damage " .. nTotal;
            --  add extra info to the message - we only have the raw damage roll - we dont have any armor info
            Comm.deliverChatMessage(rMessage); 
             --  deliver the chat message
            return
            --  exit the function without executing any further steps
        end
        
        if rTarget then
    		Debug.chat("in rollHandlers.rollPower() - line 59 - has target");		
    		
    		local sSName = ActorManager.getCreatureNodeName(rSource);
    		local sTName = ActorManager.getCreatureNodeName(rTarget);
    		local nodePowerList = DB.getChild(sSName, "powerlist");		
    		local sSuccess = ""		
    		local nSVal = 0;
    		local nTotal = ActionsManager.total(rRoll);
    		
    		-- check for data
    		if nodePowerList then
    			-- get all the list items
    			local lPowers = nodePowerList.getChildren();
    			-- check for data then loop through
    			if lPowers then
    				-- get all the window objects and look for ours
    				for _,iPower in pairs(lPowers) do					
    					local rPower = iPower.getChildren();
    					-- if its the power we want, lets see how it went
    					if rPower.name.getValue() == rRoll.sDesc then 						
    						sSuccess, nSVal = resolvePowerTest(sSName, sTName, rPower, nTotal);
    					end
    				end
    			end
    		end
    		
    		-- build out the message some more
    		rMessage.text = rMessage.text .. " vs " ..rTarget.sName .. " | " .. sSuccess;
    		
    		Comm.deliverChatMessage(rMessage);
        end
    
    end
    
    function resolvePowerTest(rSource, rTarget, rPower, nTotal)
    	Debug.chat("in resolvePowerTest() - line 101");
    	local sSName = ActorManager.getCreatureNodeName(rSource);
    	local sTName = ActorManager.getCreatureNodeName(rTarget);
    	local sPSource = rPower.power_source.getValue();
    	local sPVs = rPower.power_vs.getValue();
            --
    	-- Trying to figure out how to add a roll for the target here to add to their ability score for a check	
            --
    	local nSourceStat = ActorManager2.getAbilityScore(rSource, sPSource);
    	local nTargetStat = ActorManager2.getAbilityScore(rTarget, sPVs);
    	Debug.chat(nTotal);
    	Debug.chat(nSourceStat);
    	Debug.chat(nTargetStat);
    	local nResult = nSourceStat - nTargetStat;
    	Debug.chat(nResult);
    	local sSuccess, nPTValue = testResult(nResult);
    	Debug.chat(sSuccess);
    	Debug.chat(nPTValue);
    	return sSuccess, nPTValue
    end
    
    function testResult(nResult)
    
    	if nResult <= -5 then
    		return "Massive Failure",-3;
    	elseif nResult >= -4 and nResult <= -3 then
    		return "Major Failure", -2;
    	elseif nResult >= -2 and nResult <= -1 then
    		return "Moderate Failure", -1;
    	elseif nResult == 0 then
    		return "Marginal Success", 0;
    	elseif nResult >= 1 and nResult <= 2 then
    		return "Moderate Success", 1;
    	elseif nResult >= 3 and nResult <= 4 then
    		return "Major Success", 2;
    	elseif nResult >= 5 then
    		return "Massive Success", 3;
    	end
    
    end
    Thanks in advance. I've already gone through the thread here https://www.fantasygrounds.com/forum...ns)-in-CoreRPG, but still haven't had my AHA moment.

  2. #2
    I just cheated with math.random().

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
  •  
GI JOE RPG Launch

Log in

Log in