Thread: [Programming] Random Initiative
-
September 12th, 2019, 16:44 #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
-
September 12th, 2019, 16:59 #2
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.htmlPrivate 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!
-
September 13th, 2019, 03:24 #3
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
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
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 05:37.
-
September 13th, 2019, 14:35 #4Private 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!
-
September 13th, 2019, 14:46 #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
-
September 13th, 2019, 14:53 #6Private 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!
-
September 13th, 2019, 14:54 #7Private 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!
-
September 13th, 2019, 14:59 #8
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
-
September 13th, 2019, 15:05 #9
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.
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!
-
September 13th, 2019, 15:10 #10
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks