-
-
Save eivl/6047050 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Combat_Begins = Combat_Begins || {}; | |
| Combat_Begins.fourth_ed = false; //If using 4th edition, it takes 1/2 'Level' and adds it for initiative | |
| Combat_Begins.statName = "Dexterity"; //Stat to be added to roll | |
| Combat_Begins.Modifier = "Initmod"; | |
| Combat_Begins.rollValue = 20; //rolling 1d20, change if you roll 1dXX | |
| Combat_Begins.sendChat = false //true if you want you initiative rolls sent to chat | |
| on("chat:message", function(msg) { | |
| if (msg.type == "api" && msg.content.indexOf("!CombatBegins") !== -1) { | |
| //Start with an empty initiative | |
| if (Combat_Begins.sendChat == true) { | |
| sendChat("system", "/e rolls for initiative:") //DELETE THIS LINE ONCE IT WORKS PROPERLY | |
| } | |
| var turnorder = []; | |
| var pCharacters = findObjs({ | |
| _pageid: Campaign().get("playerpageid"), | |
| _type: "graphic", | |
| }, {caseInsensitive: true}); | |
| _.each(pCharacters, function(obj) { | |
| if (obj.get("represents") != "" && obj.get("bar1_value") > "0" ){ | |
| var currChar = getObj("character", obj.get("represents")); | |
| if(!currChar) return true; | |
| var statname = findObjs({ | |
| name: Combat_Begins.statName, | |
| _type: "attribute", | |
| _characterid: currChar.id, | |
| }, {caseInsensitive: true}); | |
| if (statname.length == 0 ) { | |
| var statmod = 0; | |
| } else { | |
| var statmod = Number(statname[0].get("current")) || 0; | |
| } | |
| var modifier = findObjs({ | |
| name: Combat_Begins.Modifier, | |
| _type: "attribute", | |
| _characterid: currChar.id, | |
| }, {caseInsensitive: true}); | |
| if (modifier.length == 0 ) { | |
| var mod = 0; | |
| } else { | |
| var mod = Number(modifier[0].get("current")) || 0; | |
| } | |
| var roll = (randomInteger(Combat_Begins.rollValue)); | |
| var init = (roll + mod + statmod) | |
| var init_statmod = (mod + statmod) | |
| if (Combat_Begins.sendChat == true) { | |
| sendChat(obj.get("name"), "rolled " + init + " (" + roll + " / 20, + " + statmod + " dex + " + mod + " misc)" ); | |
| }; | |
| turnorder.push({ | |
| id: obj.id, | |
| pr: init, | |
| }); | |
| } | |
| }); | |
| //sort turnorder by pr | |
| turnorder.sort(function(a,b) { | |
| first = a.pr; | |
| second = b.pr; | |
| return second - first; | |
| }); | |
| //Add a new lists to the turn order | |
| Campaign().set("turnorder", JSON.stringify(turnorder)); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment