STAR TREK 2d20
Page 3 of 4 First 1234 Last
  1. #21
    Another simple question: does Comm.registerSlashHandler() allow one to add new slash commands? I found several lines of code like:

    Comm.registerSlashHandler("r", processReply);

    But my attempts to add a new command by simply switch "r" with something else, but leaving the rest unchanged have been unsuccessful.

  2. #22

  3. #23
    I should have been clearer. Below is what I tried to do, but /step3 doesn't do the same thing as /r

    Code:
    -- Initialization
    function onInit()
    	
    	Comm.registerSlashHandler("step3", processReply);
    
    	
    end

  4. #24
    Quote Originally Posted by Quorlox View Post
    I should have been clearer. Below is what I tried to do, but /step3 doesn't do the same thing as /r

    Code:
    -- Initialization
    function onInit()
    	
    	Comm.registerSlashHandler("step3", processReply);
    
    	
    end
    the processReply function has to exist. when you are registering the slash command, you have to tell it what function to call when that command is issued. So somewhere you would need to have a function defined to handle it.

    Code:
    -- Initialization
    function onInit()
    	
    	Comm.registerSlashHandler("step3", processReply);
    
    	
    end
    
    function processReply(sCommand, sParams)
      do something;
    end
    For support with any of my extensions, visit my #mattekure-stuff channel on Rob2e's discord https://discord.gg/rob2e

  5. #25
    I have so much to learn.

    I really want step3 to do "/die 1d4e", and want to extend it to other stepX values which have a variety of dice combinations. Any recommendations for the best direction to head?

  6. #26
    Bumping this since I still haven't figured out how to roll dice. I have my slash handler working though.

  7. #27
    Okay, to roll a die AND do something afterwards, you can do the following: (This is for CoreRPG, it may be slightly different in other rulesets...)

    Code:
    -- Initialization
    function onInit()
    	Comm.registerSlashHandler("step3", processStep3);
    	--Register our new action
    	GameSystem.actions["step_handler"] = { bUseModStack = false };
    	--Register the result handler
    	ActionsManager.registerResultHandler("step_action", onRoll);
    end
    
    function processStep3(sCommand, sParams)
    	local rRoll = {};
    	-- Required
    	rRoll.sType = "step_action"; -- the type for the roll (Should match what is defined above!
    	rRoll.aDice = { "d4" }; -- die to roll, 2d4 would be { "d4", "d4" }
    	rRoll.nMod = 0; -- the modifier
    	rRoll.sDesc = "[Step Slash]";
    	
    	--Optional
    	rRoll.nTarget = 2; -- The target (DC) for the roll (Optional, and YOU must handle checking it later...)
    	rRoll.bSecret = true; -- True for secret GM roll, otherwise, false
    	ActionsManager.performAction(nil, nil, rRoll); --This can take parameters such as WHO rolled which can be used to look up info, WHO is being targetted to apply damage, etc...
    end
    
    function onRoll(rSource, rTarget, rRoll)
    	local rMessage = ActionsManager.createActionMessage(rSource, rRoll);
    	
    	local bSuccess = false;
    	
    	if rRoll.nTarget then
    		local nTotal = ActionsManager.total(rRoll);
    		local nTarget = tonumber(rRoll.nTarget) or 0;
    		rMessage.text = rMessage.text .. " (vs. DC " .. nTarget .. ")";
            if nTotal >= nTarget then
                rMessage.text = rMessage.text .. " [SUCCESS]";
                bSuccess = true;
            else
                rMessage.text = rMessage.text .. " [FAILURE]";
            end
    	end
    	--rMessage.icon = "ICON_NAME";
    	Comm.deliverChatMessage(rMessage);
    end
    If you only want to roll the dice, you do not need to register the action or the callback, and you would not need to define the callback. However, if you want to output text based upon the roll or do something else, you must register the callback.

    Trenloe posted a great explanation on rolling dice here -> https://www.fantasygrounds.com/forum...ns)-in-CoreRPG

  8. #28
    Thanks!

    I searched the forums repeatedly to try to find examples and the Trenloe post never came up; guess I didn't choose the correct search criteria.

  9. #29
    Quote Originally Posted by Quorlox View Post
    Thanks!

    I searched the forums repeatedly to try to find examples and the Trenloe post never came up; guess I didn't choose the correct search criteria.
    Use the "Site Search" button in the Forum toolbar, the magnifying glass is practically useless (as it basically just searches for the words you include as seperate search terms).

  10. #30
    Quote Originally Posted by bmos View Post
    Use the "Site Search" button in the Forum toolbar, the magnifying glass is practically useless (as it basically just searches for the words you include as seperate search terms).
    I was using the magnifying glass because that seemed to be a search function...

    A best practice question, I will have multiple steps (e.g. step3, step4, etc.) with different dice combinations; what is the best way to handle that in Lua? (I read that Lua doesn't have switch statements.)

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
  •  
FG Spreadshirt Swag

Log in

Log in