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

Custom Traps v1

1598380389

Edited 1598539650
*** CURRENTLY ONLY SUPPORTS 5e *** Hey all, I recently got the API after playing on here for years. I started by writing my own script for custom traps that allow the GM to put JSON into the gmnotes of tokens named "trap" and the game will create trap objects and look for interactions with them and players. I intend to add more to the JSON object definition like descriptions and names for specific traps etc. Anyway, I imagine there are similar scripts out there but as a software person I wanted to play with it myself a bit first. I'm just looking for any feedback on this, whether it'll be feasible with 4-5 players, if people wanna test it out, etc.&nbsp; Link to Gist:&nbsp; <a href="https://gist.github.com/newellewen/5de4f84ed12097b9133155dee309373f" rel="nofollow">https://gist.github.com/newellewen/5de4f84ed12097b9133155dee309373f</a>
1598538408
timmaugh
Forum Champion
API Scripter
Hey, Philip... that looks interesting, but it does look very system-specific (having _save_roll hard-coded). Is this something that could be abstracted for other systems to use, too? Maybe have a default system schema that behaves as you have it coded, but give the user the opportunity to select a different schema as their default to match the system they are playing? You could get input from players of other systems what that might look like with a little more description of what the character interactions might look like, then have a way to load those in later? Just a thought...
That's a really good point, I was just kind of getting my feet wet and wanted to make something fun for my D&amp;D 5e games. But it's fun to think about how to apply them to other systems. Personally, I would probably create another file that has all the appropriate string values for rolls from different character sheets and systems, which can be switched out as needed. The more fun thing to consider here is how to switch out the game/roll logic for different games? I don't like the idea of having a bunch of branching logic within the same script to handle which system you're using, so I'd probably want to find a way to make some actual modules that can be loaded by some controller as necessary.&nbsp;
1598542295

Edited 1598542394
timmaugh
Forum Champion
API Scripter
I use a registration process in my InsertArg script... I have an object of internal functions: availFuncs = { &nbsp; &nbsp; getabils: getabils, &nbsp; &nbsp; getattrs: getattrs }; So I can check the object for the function name (the key) and throw my arguments at the actual function (stored as the value). I don't want to expose this object directly, but I provide a way for other scripters to register their function to my object: &nbsp; &nbsp; const registerRule = (...r) =&gt; {&nbsp; &nbsp; // pass in a list of functions to get them registered to the availFuncs library &nbsp; &nbsp; &nbsp; &nbsp; r.forEach(f =&gt; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (f.name) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (availFuncs[f.name]) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log(`IA Function Registration: Name collision detected for ${f.name}. Last one loaded will win.`); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delete availHelp[f.name]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; availFuncs[f.name] = f; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }; I expose that registerRule as RegisterRule in the public interface of my script, so if you wrote a function to add to the InsertArg library you could then call: ia.RegisterRule(PhilipPhunction); ...in an on('ready') event handler, and my script would be able to use it. Your PhilipPhunction could be in its own file and in its own namespace, but that way you could register it to let InsertArg know to use it. For your implementation, the user would have a number of "schema" registered (or not... maybe they chose the set up a la carte style), so I would give them a config screen (or help handout) with buttons that let them set a variable in state to drive which schema is the default for their game.