Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Call of Cthulhu Firearm Initiative in Turn Tracker: Is AddCustomTurn viable?

1689469295

Edited 1689470594
Hi all! I'm trying to get a separate initiative slotted into the turn tracker for character firearms in Call of Cthulhu. If you're unfamiliar, when a character has a gun out in CoC, they effectively can choose to fire it or not on the drawn gun's own initiative which is the character's dexterity value +50. Characters also have their own initiative to do anything else, which is their dexterity value. However, any macro I've used to add this "gun initiative" into the tracker has simply replaced that token's regular turn tracker initiative (their dex) with the new value, instead of creating a separate entry. For example:  [[@{selected|dexterity} + 50 &{tracker}} ]] This is of course due to how turn tracker functions with one token = one turn. But it  isn't great as it means constantly rejiggering the running order between characters' initiatives and their gun initiatives when creating a separate turn tracker entry would be far better. Now I stumbled across the AddCustomTurn API and added it to the game thinking I could use that to create my player and NPC's custom gun initiatives. Sadly, I cannot for the life of me figure out how to create a macro to run ACT that will do what I want and... Create a custom turn in the tracker Have that turn's initiative value be based upon a selected token's Dexterity+50 Have that turn be named after the token's character (for ease of use as GM) with something like: [Name] Firearm Initiative Is this possible with AddCustomTurn,? O r am I barking up the wrong tree? If so there a better API to do what I'm trying to do? P.S As a sidenote, if someone knows a good cheat to sort the turn tracker rather than having to click through the turn tracker menu, I would appreciate it!
1689485509
The Aaron
Roll20 Production Team
API Scripter
I've written some scripts in the past for duplicating turns, I think I could whip you out a draw/holster script that would add a second turn in the turn order and let you remove it.  For sorting, GroupInitiative has such a function, though that's probably overkill if that's all you need. I can add sorting to the script above easily as well.  I'll see about turning something out in the morning. 
What Character Sheet are you using? The official one by Roll20 has the option to add ones DEX Value to the tracker and I think it also has the option to do so +50 when ready to fire a gun... Boosty said: Hi all! I'm trying to get a separate initiative slotted into the turn tracker for character firearms in Call of Cthulhu. If you're unfamiliar, when a character has a gun out in CoC, they effectively can choose to fire it or not on the drawn gun's own initiative which is the character's dexterity value +50. Characters also have their own initiative to do anything else, which is their dexterity value. However, any macro I've used to add this "gun initiative" into the tracker has simply replaced that token's regular turn tracker initiative (their dex) with the new value, instead of creating a separate entry. For example:  [[@{selected|dexterity} + 50 &{tracker}} ]] This is of course due to how turn tracker functions with one token = one turn. But it  isn't great as it means constantly rejiggering the running order between characters' initiatives and their gun initiatives when creating a separate turn tracker entry would be far better. Now I stumbled across the AddCustomTurn API and added it to the game thinking I could use that to create my player and NPC's custom gun initiatives. Sadly, I cannot for the life of me figure out how to create a macro to run ACT that will do what I want and... Create a custom turn in the tracker Have that turn's initiative value be based upon a selected token's Dexterity+50 Have that turn be named after the token's character (for ease of use as GM) with something like: [Name] Firearm Initiative Is this possible with AddCustomTurn,? O r am I barking up the wrong tree? If so there a better API to do what I'm trying to do? P.S As a sidenote, if someone knows a good cheat to sort the turn tracker rather than having to click through the turn tracker menu, I would appreciate it!
Heya! Using the official sheet. It does have an option for initiative but not gun initiative as far as I can see. And it would still likely just override the original initiative in the turn tracker rather than create a separate entry. TheMarkus1204 said: What Character Sheet are you using? The official one by Roll20 has the option to add ones DEX Value to the tracker and I think it also has the option to do so +50 when ready to fire a gun...
1689513349

Edited 1689519554
Hi Aaron! Thank you kindly for responding. Been enjoying adding a bunch of your APIs. Appreciate your response and any help you can offer, I don't want to be wasting your time so don't stress about it too much! But it would be a great help to have both the PC and guns with their own initiatives. Working without that caused a lot of grumbling with the last game I ran! Oh and RE: Sorting - Checked out GroupInitiative and you're awesome that it has such a function ,  So have added it. I was eyeing it anyway! Got it to work with Cthulhu static dex initiative by setting the roller to Constant By Stat and making Dexterity a Bonus Group. The Aaron said: I've written some scripts in the past for duplicating turns, I think I could whip you out a draw/holster script that would add a second turn in the turn order and let you remove it.  For sorting, GroupInitiative has such a function, though that's probably overkill if that's all you need. I can add sorting to the script above easily as well.  I'll see about turning something out in the morning. 
1689524900
The Aaron
Roll20 Production Team
API Scripter
Ok, give this a try. Commands are: !ch-draw  -- add a turn for selected tokens at Dexterity + 50 !ch-holster -- remove the gun turn for the selected tokens. !ch-toggle -- Add the turn for tokens that don't have one, remove it for tokens that do. It's set up assuming the attribute is named "Dexterity", that you want to add 50, and that the turn order is sorted in ascending order.  You can change those assumptions on the first 4 lines of the code.  Let me know if that works for you! Script: on('ready',()=>{ const DEXATTR = 'Dexterity'; const INITADD = 50; const ASCENDING = true; const CMDREGEX = /^!ch-(draw|holster|toggle)(\b\s|$)/i; const getTurnArray = () => ( '' === Campaign().get('turnorder') ? [] : JSON.parse(Campaign().get('turnorder'))); const setTurnArray = (ta) => Campaign().set({turnorder: JSON.stringify(ta)}); const findInsert = ASCENDING ? ( (a,v)=>a.findIndex(e=>e.pr>v) ) : ( (a,v)=>a.findIndex(e=>e.pr<v) ); const ManipulateInitiative = (token,action) => { let attr = findObjs({type:'attribute',name:DEXATTR,characterid:token.get('represents')}, {caseInsensitive: true})[0]; if(attr) { let v = INITADD + parseFloat(attr.get('current')); let ta = getTurnArray(); let idx = ta.findIndex(e => e.id === token.id && e.pr === v); if( 'toggle' === action){ if(-1 === idx) { action = 'draw'; } else { action = 'holster'; } } switch(action){ case 'draw': { if(-1 === idx ) { let bIdx = findInsert(ta,v); ta = [...ta.slice(0,bIdx),{id: token.id, pr: v, _pageid: token.get('pageid')},...ta.slice(bIdx)]; setTurnArray(ta); } } break; case 'holster': { if(-1 !== idx) { ta = [...ta.slice(0,idx),...ta.slice(idx+1)]; setTurnArray(ta); } } break; } } }; on('chat:message',msg=>{ if('api'===msg.type && CMDREGEX.test(msg.content)){ let parts = msg.content.match(CMDREGEX); const takeAction = (t) => ManipulateInitiative(t,parts[1].toLowerCase()); (msg.selected || []) .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) .forEach(takeAction) ; } }); });
1689542736

Edited 1689555589
Wow! It's got two kinks but this is very useful and definitely an overwhelming positive addition to my games thank you! There's only one oddity (which I can definitely live with just to have this!) and seems to be how it bumps up against !group-init You HAVE to add the normal turns first with !group-init before you hit the !ch-draw or the !ch-toggle command if you want the regular turns and firearm turns listed. If you go the other way and add gun turns first, it adds the gun turns fine but then refuses to add any normal turns for that token at all until you remove that token's gun initiative. This is really okay though since a character is always going to have a normal turn, so remembering to always do that first is no problem. But the good news! !group-init's sort function still works! I can definitely use this. Thank you! The Aaron said: Ok, give this a try. Commands are: !ch-draw  -- add a turn for selected tokens at Dexterity + 50 !ch-holster -- remove the gun turn for the selected tokens. !ch-toggle -- Add the turn for tokens that don't have one, remove it for tokens that do. It's set up assuming the attribute is named "Dexterity", that you want to add 50, and that the turn order is sorted in ascending order.  You can change those assumptions on the first 4 lines of the code.  Let me know if that works for you! Script: on('ready',()=>{ const DEXATTR = 'Dexterity'; const INITADD = 50; const ASCENDING = true; const CMDREGEX = /^!ch-(draw|holster|toggle)(\b\s|$)/i; const getTurnArray = () => ( '' === Campaign().get('turnorder') ? [] : JSON.parse(Campaign().get('turnorder'))); const setTurnArray = (ta) => Campaign().set({turnorder: JSON.stringify(ta)}); const findInsert = ASCENDING ? ( (a,v)=>a.findIndex(e=>e.pr>v) ) : ( (a,v)=>a.findIndex(e=>e.pr<v) ); const ManipulateInitiative = (token,action) => { let attr = findObjs({type:'attribute',name:DEXATTR,characterid:token.get('represents')}, {caseInsensitive: true})[0]; if(attr) { let v = INITADD + parseFloat(attr.get('current')); let ta = getTurnArray(); let idx = ta.findIndex(e => e.id === token.id && e.pr === v); if( 'toggle' === action){ if(-1 === idx) { action = 'draw'; } else { action = 'holster'; } } switch(action){ case 'draw': { if(-1 === idx ) { let bIdx = findInsert(ta,v); ta = [...ta.slice(0,bIdx),{id: token.id, pr: v, _pageid: token.get('pageid')},...ta.slice(bIdx)]; setTurnArray(ta); } } break; case 'holster': { if(-1 !== idx) { ta = [...ta.slice(0,idx),...ta.slice(idx+1)]; setTurnArray(ta); } } break; } } }; on('chat:message',msg=>{ if('api'===msg.type && CMDREGEX.test(msg.content)){ let parts = msg.content.match(CMDREGEX); const takeAction = (t) => ManipulateInitiative(t,parts[1].toLowerCase()); (msg.selected || []) .map(o=>getObj('graphic',o._id)) .filter(g=>undefined !== g) .forEach(takeAction) ; } }); });
1689576595
The Aaron
Roll20 Production Team
API Scripter
I might suggest setting GroupInitiative to Replace Rolls. Then at least you don't have to manually remove the gun rolls. If there is a way to know who should have gun turns, wouldn't be too hard to make this script automatically add them in when GroupInitiative is run. Another option would be to have it remove the turns and add them back whenever GroupInitiative runs.