1. #1

    [Programming] Random Initiative

    Hey guys! so for my Alien RPG ruleset, I almost have a random initiative button working in the combat tracker; I'm just not sure how to get it to be actually random.

    The way initiative works in the ARPG is you have 10 cards, everyone draws a card, some NPC's draw more than one (this can be simulated by dropping the entity in the combat tracker twice i suppose). So unlike with dice, we can't have repeating initiatives.

    Is there a way to perhaps rig this to Trenloe's Basic Card Extension? or how might i set it up so that a number can't be used again?

    this is what i've put into the CombatManager. nInitNum is set up that way just so i could see if it worked, i'm just not sure how to do the randomization with elimination of results.

    Code:
    function rollInit()
    	nInitNum = 0;
    	for _,v in pairs(getCombatantNodes()) do
    		nInitNum = nInitNum + 1;
    		DB.setValue(v, "initresult", "number", nInitNum);
    	end
    end
    “The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of the infinity, and it was not meant that we should voyage far.”
    ― H. P. Lovecraft, The Call of Cthulhu and Other Weird Stories

    “The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown”
    ― H.P. Lovecraft, Supernatural Horror in Literature

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,848
    Look at using a LUA table - with the 10 card values (assuming it's something like 1,2, 3, 4 ... 10?), then "shuffle" that LUA table and step through each entry in order assigning the value as the initiative.

    Info on "shuffling" a table here: https://docs.coronalabs.com/tutorial...ble/index.html

    FG Con 15 – Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
    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
    Quote Originally Posted by Trenloe View Post
    Look at using a LUA table - with the 10 card values (assuming it's something like 1,2, 3, 4 ... 10?), then "shuffle" that LUA table and step through each entry in order assigning the value as the initiative.

    Info on "shuffling" a table here: https://docs.coronalabs.com/tutorial...ble/index.html

    ok, so i've been messing around for a little while here. the math.randomseed( (os.time) ) bit is giving me errors that it can't call global math, and if i remove that completely, i instead get errors that it's failing to get global "type". It looks simple, but i'm clearly missing something.
    edit: got it!

    Code:
    function shuffleTable( t )
        if ( type(t) ~= "table" ) then
            print( "WARNING: shuffleTable() function expects a table" )
            return false
        end
     
        local j
     
        for i = #t, 2, -1 do
            j = math.random( i )
            t[i], t[j] = t[j], t[i]
        end
        return t
    end
     
    
    
    currentIndex = 1  -- Deck starts at top card (1)
     
    function drawCards( num, deck )
     
        local cardsDrawn = {}  -- Empty table to begin
     
        for i = currentIndex, num do
            cardsDrawn[#cardsDrawn+1] = deck[i]
        end
     
        currentIndex = currentIndex + num
        return cardsDrawn
    end
     
    
    function rollInit()
    	cardDeck = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
    	cardDeck = shuffleTable( cardDeck )
    	currentIndex = 1  -- Deck starts at top card (1)
    	for _,v in pairs(getCombatantNodes()) do
    		drawCards( 1, cardDeck );
    		DB.setValue(v, "initresult", "number", cardDeck[currentIndex]);
    	end
    end
    
    function rollInitFifteen()
    	cardDeck = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
    	cardDeck = shuffleTable( cardDeck )
    	currentIndex = 1  -- Deck starts at top card (1)
    	for _,v in pairs(getCombatantNodes()) do
    		drawCards( 1, cardDeck );
    		DB.setValue(v, "initresult", "number", cardDeck[currentIndex]);
    	end
    end
    
    function rollInitTwenty()
    	cardDeck = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }
    	cardDeck = shuffleTable( cardDeck )
    	currentIndex = 1  -- Deck starts at top card (1)
    	for _,v in pairs(getCombatantNodes()) do
    		drawCards( 1, cardDeck );
    		DB.setValue(v, "initresult", "number", cardDeck[currentIndex]);
    	end
    end
    edit: this almost works!
    Code:
    local cardDeck = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
    function shuffleTable( t )
        if ( type(t) ~= "table" ) then
            print( "WARNING: shuffleTable() function expects a table" )
            return false
        end
     
        local j
     
        for i = #t, 2, -1 do
            j = math.random( i )
            t[i], t[j] = t[j], t[i]
        end
        return t
    end
     
    
    
    local currentIndex = 1  -- Deck starts at top card (1)
     
    function drawCards( num, deck )
     
        local cardsDrawn = {}  -- Empty table to begin
     
        for i = currentIndex, num do
            cardsDrawn[#cardsDrawn+1] = deck[i]
        end
     
        currentIndex = currentIndex + num
        return cardsDrawn
    end
     
    
    function rollInit()
    	cardDeck = shuffleTable( cardDeck )
    	for _,v in pairs(getCombatantNodes()) do
    		local playerHand = drawCards( 1, cardDeck );
    		DB.setValue(v, "initresult", "number", dardsDrawn);
    	end
    end
    this is what i have:
    i have tried removing the quotation marks from around the numbers as well, but the code isn't getting far enough to know if that makes a difference.
    Code:
    local cardDeck = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }
    function shuffleTable( t )
        if ( type(t) ~= "table" ) then
            print( "WARNING: shuffleTable() function expects a table" )
            return false
        end
     
        local j
     
        for i = #t, 2, -1 do
            j = math.random( i )
            t[i], t[j] = t[j], t[i]
        end
        return t
    end
     
    cardDeck = shuffleTable( cardDeck )
    
    local currentIndex = 1  -- Deck starts at top card (1)
     
    function drawCards( num, deck )
     
        local cardsDrawn = {}  -- Empty table to begin
     
        for i = currentIndex, num do
            cardsDrawn[#cardsDrawn+1] = deck[i]
        end
     
        currentIndex = currentIndex + num
        return cardsDrawn
    end
     
    
    function rollInit()
    	for _,v in pairs(getCombatantNodes()) do
    		local playerHand = drawCards( 1, cardDeck );
    		DB.setValue(v, "initresult", "number", playerHand);
    	end
    end
    Last edited by pr6i6e6st; September 13th, 2019 at 06:37.
    “The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of the infinity, and it was not meant that we should voyage far.”
    ― H. P. Lovecraft, The Call of Cthulhu and Other Weird Stories

    “The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown”
    ― H.P. Lovecraft, Supernatural Horror in Literature

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,848
    Quote Originally Posted by pr6i6e6st View Post
    edit: got it!
    So, is everything OK or do you still have issues?

    You're also missing a lot of semi-colon line terminators in that code!

    FG Con 15 – Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
    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!

  5. #5
    It seems like it’s working fine. Only concern is something I’m not sure we can do, giving npcs multiple initiatives.

    And shoot, is that a problem? I didn’t realize I missed those
    “The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of the infinity, and it was not meant that we should voyage far.”
    ― H. P. Lovecraft, The Call of Cthulhu and Other Weird Stories

    “The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown”
    ― H.P. Lovecraft, Supernatural Horror in Literature

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,848
    Quote Originally Posted by pr6i6e6st View Post
    And shoot, is that a problem? I didn’t realize I missed those
    If it's working 100% correctly probably not. I'm not sure what the FG LUA interpreter expects and if it will process all code correctly without semi-colons.

    FG Con 15 – Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
    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!

  7. #7
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,848
    Quote Originally Posted by pr6i6e6st View Post
    Only concern is something I’m not sure we can do, giving npcs multiple initiatives.
    Does multiple initiatives for NPCs mean they go twice? Or that they select the best?

    FG Con 15 – Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
    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!

  8. #8
    Quote Originally Posted by Trenloe View Post
    Does multiple initiatives for NPCs mean they go twice? Or that they select the best?
    They get to go a number of times in a round based on their speed. So a xenomorph with a speed of two draws two initiative cards, 5 and 8, he gets to act on turn 5 and 8.

    Reminds me of lair/legendary actions in d&d which I don’t think there’s anything programmed specifically for
    “The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of the infinity, and it was not meant that we should voyage far.”
    ― H. P. Lovecraft, The Call of Cthulhu and Other Weird Stories

    “The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown”
    ― H.P. Lovecraft, Supernatural Horror in Literature

  9. #9
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,848
    There's nothing programmed for that in CoreRPG. Maybe consider "spawning" a dummy NPC record in the CT - either manually or via code, that is essentially a placeholder for the NPC's second turn in the round, but this would mess with auto targeting and effects.

    FG Con 15 – Fantasy Grounds Online RPG Convention - Nov. 8-10, 2019
    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!

  10. #10
    Quote Originally Posted by Trenloe View Post
    There's nothing programmed for that in CoreRPG. Maybe consider "spawning" a dummy NPC record in the CT - either manually or via code, that is essentially a placeholder for the NPC's second turn in the round, but this would mess with auto targeting and effects.
    Right, I think I’ll just leave that alone. If d&D5e ruleset gets something similar I might try ripping it apart, but like you said, probably just going to screw things up, easier just to add a dummy in game.
    “The most merciful thing in the world, I think, is the inability of the human mind to correlate all its contents. We live on a placid island of ignorance in the midst of black seas of the infinity, and it was not meant that we should voyage far.”
    ― H. P. Lovecraft, The Call of Cthulhu and Other Weird Stories

    “The oldest and strongest emotion of mankind is fear, and the oldest and strongest kind of fear is fear of the unknown”
    ― H.P. Lovecraft, Supernatural Horror in Literature

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 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
  •  

Log in

Log in