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

Starfinder Helm Controls Via Chat Buttons

1528348488

Edited 1528500262
Bast L.
API Scripter
Edit: You can instead select the file from the gist which says it uses unicode. Then you don't have to bother with images, or rollable table avatars. Pictures for both controls are in this thread. Note, I did not test on firefox, or on mac, as was suggested, due to laziness :) Current Bug: Don't enter the token and set the bars, or backspace over them. This is causing an issue. I'll try to figure out the problem (or bug people who know more than me). &nbsp;Fixed thanks to Scott's help. Hello. I noticed my players struggling with ship controls, especially turning after moving. So I made this thing. I've tested it a bit, but maybe it breaks somewhere. If you're using the version with images for buttons, on loading it up, it'll make a table. You'll need to find some images for turning, reversing, going forward, and sliding. I got the ones in the picture from google images. Once you have those uploaded (not searched for in game), set them as the avatar for the appropriate table item in HelmControlImages.&nbsp; If you're using the Unicode version, you don't have to bother with any of that, but I've only tested for chrome, on windows, on a single monitor. Things to note: This works for the SF HUD sheet. The template could be made generic, or altered, but you'll need to do that in script. Different sized monitors may display it weird. I only tested on mine. The grid size const in the script says 80. I did some testing with a position report function, and found the actual spacing to be 79.689, but it won't matter too much, unless you move a great deal, and never reposition. I wanted to use token status icons, but I got some really weird behavior out of them, and frustratedly put speed in the red bar. You will need to set your ship rotation offset. For a ship token that aims down on drop, I have -90. Place the offset in the blue value (bar 2), or just use the helm control button to set the rotation offset. edit: oh, and make a macro called Helm or something, and have the body be !HelmControls Here's the Gist:&nbsp; <a href="https://gist.github.com/Bastlifa/5dd6811680e0a7ba4" rel="nofollow">https://gist.github.com/Bastlifa/5dd6811680e0a7ba4</a>... And here's a picture: And an alternative Gist which requires a bit of fx setup, along with picture: <a href="https://gist.github.com/Bastlifa/c9c2dea3961031a5f" rel="nofollow">https://gist.github.com/Bastlifa/c9c2dea3961031a5f</a>...
He, that's really good!&nbsp;
Thanks. I was thinking of adding some buttons for stunts, but I wasn't sure how to roll from the sheet on a button in the macro, and also I'm lazy.
1528390862
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Instead of using images (and needing to load them), you could use&nbsp; unicode characters (make sure to test them in firefox vs. chrome and pc vs. mac). You can just copy the symbol into your code. Great job though!
1528391755

Edited 1528391767
Bast L.
API Scripter
Thanks. For some reason, I figured they would be emoticons, and went to the unicode emoticon list, but didn't see arrows. There was something odd whenever I try to use images as API command buttons: for the first image, it just shows part of the URL, and doesn't work. My workaround was to put the little notes thing in. The text there made the issue go away, but I'm not sure why it was there in the first place. Of course, just using characters would eliminate the issue as well. &#x21B0;
1528392179
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
If you want to use images for it (totally valid), take a look at my Roll20AM script. There's a function in there called makeImageButton that should be useful for you. You'll need some variables from the block scope (up at the top of the script) to make it work.
I updated the gist with an alternative chat macro using unicode. It's two files now, since the unicode version doesn't need all the img stuff, or the rollable table. Thanks for the suggestion:
1528393257
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
np, glad I could help :)
1528393915

Edited 1528395246
Bast L.
API Scripter
I do have a strange effect happening sometimes. I'm really not sure what's going on with it. It happened last night, but then stopped, so I thought it was some API server issue. However, it just happened again when I was trying to break my refueling button (soon to be in update). Sometimes, with the ship selected, when I try to use the forward button, the script gives an error: Error: Firebase.update failed: First argument contains NaN in property 'left' Error: Firebase.update failed: First argument contains NaN in property 'left' at Ba (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:9:186) at Ba (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:10:207) at Aa (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:8:462) at Ea (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:10:403) at J.update (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:146:318) at TrackedObj._doSave (/home/node/d20-api-server/api.js:850:27) at later (/home/node/d20-api-server/node_modules/underscore/underscore.js:888:31) at Timeout._onTimeout (/home/node/d20-api-server/node_modules/underscore/underscore.js:825:19) at ontimeout (timers.js:386:14) at tryOnTimeout (timers.js:250:5 I don't know how the selected ship could not have a numerical 'left' property, especially since it works most of the time. Perhaps it's some kind of issue with actually getting the left property before using it? The thing is, after it breaks, it won't work on that ship token. I have to drag out a new one.&nbsp; edit: updated with refuel button (for maxing speed again, assuming it doesn't change), and some checks for this error. I've not been able to break it again, but will check with Scott's suggestion.
1528394525

Edited 1528394765
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
It's saying that you are trying to set the left to NaN. In line 115, add log('newLeft:'+newLeft); log('left:'+left); Also, not related to your error, but you don't need the underscore before type and id.
So further testing has newLeft being NaN, while tokenLeft is a number. I also know when the issue arises: when I go into the token and backspace over the red bar (speed) values. The strange thing is, I even call a function beforehand which should set the red bar max and val to 0 if they're blank.
1528398679

Edited 1528398798
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Here's your problem (Line 45-50 of the unicode version): let shipToken = getObj(msg.selected[0]._type, msg.selected[0]._id); if (!shipToken.get("bar3_value")) {sendChat("", "Ship is out of movement"); return; }//This will only trigger if bar3_value is the number 0 (note not a string "0"), or truly doesn't exist let speed = shipToken.get("bar3_value"); if (speed &lt;= 0) {//This will only trigger if speed is a number or can be converted into a number. sendChat("", "Ship is out of movement"); }else{ I'd rewrite the function like so: on("chat:message", function (msg) { &nbsp; &nbsp; if (msg.type === "api" && msg.content === "!ShipForward") &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; if (!msg.selected) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('', "Please Select a Ship Token"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let shipToken = getObj('graphic', msg.selected[0]._id);//You only want graphics, but it is possible to have drawings selected too &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(shipToken){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let speed = shipToken.get("bar3_value")*1||0;//multiplying something by a number attempts to convert it to a number, if it can't convert it to a number, it returns NaN. The || would then convert that NaN into a 0. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (speed &lt;= 0){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("", "Ship is out of movement"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let tokenRotation = shipToken.get("rotation"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let rotationOffset; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!shipToken.get("bar2_value")) { rotationOffset = 0; }else{ rotationOffset = shipToken.get("bar2_value"); } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let tokenLeft = shipToken.get("left"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let tokenTop = shipToken.get("top"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let newLeft = tokenLeft - Math.cos(((Math.PI)/180)*(tokenRotation + rotationOffset))*gridSpacing; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let newTop = tokenTop - Math.sin(((Math.PI)/180)*(tokenRotation + rotationOffset))*gridSpacing; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shipToken.set("left", newLeft); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shipToken.set("top", newTop); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; speed--; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; shipToken.set("bar3_value", speed); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } }); I'd also highly recommend a few script wide changes: creating a namespace for your script (see any of my scripts, or The Aaron's - who I stole my pattern from - for an example of how that looks). Consolidate your message handling into a single function. The way you have it now, it triggers all of those on('changes:') for every message which is very inefficient
1528403242

Edited 1528403299
Bast L.
API Scripter
Thanks for the help. I haven't looked at namespaces, though I did clean up the event checking a bit, and just have it call functions based on the msg received.The bug fix seems to work fine. I tried my best to break it, but it's working. I had been checking isNaN during my bug hunt, but for some reason, it wasn't catching it. Anyways, your fix is in, and the gist is updated.&nbsp;
1528404070
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
glad it worked.