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

[Script] Door Control for Players, includes Locks and Traps

1391816960

Edited 1394160812
Matt
Pro
Completed my second script for game play, and wanted to open it up to ideas and suggestions for improvement. This script gives some control of doors to the players, relieving the GM of constantly swapping between layers, moving lines, and changing graphics for the simple action of opening and closing a door. The idea is to place a small token over the door image that players can target. With the token selected, they can run several different commands, such as OpenDoor or PickLock. Based on their attributes and the individual door settings, the door can automatically open, and all of the manipulation is handled via the script, freeing the GM to focus on the horde behind the door, waiting anxiously. There is a little bit of work to set up the doors image properly, but the payoff is worth the work... in my opinion at least. There is a lot to explain, although I'm hoping most of it is pretty self explanatory. Should anyone be interested in seeing how this works, I have a small campaign set up i used to build/test that I can invite you to look at the functionality. Player Commands !FindTraps: attempts to identify a trap. each player that can detect has only one chanced to find it. However, once one person has found it (by either a successful roll, or someone setting it off), all players should be able to detect it. Players are given a description without knowing if it were really successful. GM is whispered the roll results. Traps are directional. !RemoveTrap: attempts to remove a trap. can only be done against a trap that was identified (either by detection, or someone setting it off before). each player with the appropriate attribute has only one chance to disarm it; additional attempts by the same character are ignored. Players are given a description without knowing if it were really successful. GM is whispered the roll results. !PickLock: attempts to pick a locked door. Each player with the appropriate attribute has only one chance to unlock it; additional attempts by the same character are ignored. Players are given an accurate description of the results, and the GM is whispered the roll results. Locks are directional. !OpenDoor: Opens the door, and performing the walls and map manipulations automatically. Is prevented if the door is still locked or trapped. If an attempt to open is made on a trapped door, the trap is triggered, and a description of the trap effects is given to the players, and the door remains closed. !CloseDoor: Closes a door. Functions even if door is locked or trapped. Closing a door does not trigger the trap. ** GM can open or close a door regardless the lock/trap status, and without setting off the trap. !FindTraps, !RemoveTrap, and !PickLock commands by GM are ignored. Players may only attempt these commands if the character they're currently playing is within range of the door, as determined by the script variable statusDoors.interactRange. Players must set their 'AS' drop option to the character performing the commands. GM Commands !DoorsDeleteAllLinks: removes all links between doors, walls, and tokens. Moves these controls back to the objects layer. !DoorsResetUse: resets all doors to a 'never been seen' status. Player attempts to remove traps and unlock doors are reset, and traps are flagged as not been found. !DoorsLink: creates a link between a switch token, a door token, and a wall path. The switch must be named 'Switch' and the door must be named 'Door' when linking. After the link is established, these tokens may be given different names. The size and rotation and position of the switch will be remembered, and will be set back to this setting should a player change it. Locks default to unlocked, traps default to no trap, door defaults to visible (not secret), and active side is set to both. !DoorsAllOpen: opens all doors that have been linked on the current campaign page. !DoorsAllClose: closes all doors that have been linked on the current campaign page. !DoorsAllAlign: moves all switch tokens directly over their linked door token on the current campaign page. **this will overwrite any custom placement of tokens you may have set, use only if certain. Haven't implemented a way to reposition switches as of yet. !DoorsCount: gets a total count of all the doors, how many are locked, and how many are trapped. Also counts if there are any doors that do not load correctly. !SideID: displays in chat the current side shown for the selected object. Helpful in identifying the correct side of the rollable table token for your door closed and door open states. !ObjectList: attempts to log all selected items to the console output window The Switch Token I use the bars on the switch token to identify the settings for the door. This allows each linked door to have its own trap and lock settings. These values should be set after the link is established (the script defaults these values to 0, which is no lock and no trap). All the setting and their values are listed near the top of the script. (When establishing a link with the !DoorsLink command, the switch token must be named 'Switch' so that the script can distinguish between the switch token and the door token.) bar1_value: determines if the door is locked. 1 = locked 0 = unlocked bar1_max: sets the difficulty of the lock. Success rolls are based on a roll of d100. This value is added to the roll. So a value of -20 should reduce the player's chance of unlocking the door by 20%. bar2_value: determines the trap setting of the door. 0 = no trap 1 = trap is armed 2 = trap is armed, and will reset when triggered 3 = trap has been triggered 4 = trap has been disabled bar2_max: sets the difficulty of trap detection and removal. Success rolls are based on a roll of d100. This value is added to the roll. So a value of -20 should reduce the player's chance of finding or removing a trap by 20%. bar3_value: the side of a token to show for a closed door. bar3_max: the side of a token to show for an open door. aura1_radius: determines the visibility of the door. 0 = visible 1 = hidden 2 = revealed aura2_radius: determines the active side of the door. The north side of a door is determined by the top of the graphic with 0 rotation ie. the same side as the rotation handle. North becomes relative to the door graphic. If I rotate a graphic 90 degrees clockwise, then the north side of the door would be considered anything to the right of the door graphic. 0 = both sides 1 = north side 2 = south side gmnotes: the description of the trap to give players when a trap is triggered. Any instance of the word PC in the description will be replaced with the character's name. ** A note on secret doors. Currently, there is no way to determine who moved a token, so I cannot tell if the GM moves a player's token, or if it were done by the player. I had to make some assumptions on when to check for secret doors and when not. The logic is that if a token is tied to a character sheet and is controlled by someone other than "all", they get a roll regardless who actually moved the token. The Door Token I use a token for a rollable table to display my doors. Each type of door should have 2 entries in the table. For example, I have a "door reinforced single open" and a "door reinforced single closed" side in my table. Doesn't matter the weight value, but the order in the table is significant. The first item in the table is value 0. It is the position in this list that will be entered into the switch bar3_value and bar3_max settings. Getting all the doors to display accurately from the table takes some time to set up. Each image of the table must be exactly the same size in pixels, and the center of the door when closed must be the center of the image. I've found that a base image size of 280x280 works best for me, even though my standard door is usually 1 map unit in width when closed. This size allows me to use the same table for single doors or double doors, with enough room to have the doors open in both directions. Creating the rollable table with these images took a little time to set up properly. In this respect, this script is not a "copy/paste and off you go" type of script. ** It is important that door images open to the top or bottom of the graphic so that active side works properly. If the graphic opens to the top, north of the door will be the same side that the door opens towards. If the graphic opens to the bottom, north of the door will be opposite the door opens towards. Screen Shots Here are some screen shots. Forgive the crude background, this is a testing environment, not a gaming campaign. The small cog wheel is the Switch icon. Players would select this when entering one of their commands. Here is the chat log as a player tries to open a door. Here is the settings for a door switch (not the same door from the chat log screen shot). This door is locked (bar1_value) and has a -20% chance to unlock (bar1_max). The door is set with a trap that automatically resets when tripped (bar2_value), and has no modifier to find/remove chance (bar2_max). The door uses side 0 when open (bar3_value), and side 1 when closed (bar3_max). When the trap is triggered, the description given is in the GM Notes. Script Code //========== name spacing ========== state.DoorControls = state.DoorControls || {} var statusDoors = {}; //========== user customization ========== statusDoors.interactRange = 2; //max range in map units statusDoors.detectionRange = 2; //max range in map units statusDoors.DoorPathColor = "#FFFF00"; statusDoors.attribFindHidden = "FindHiddenDoors"; statusDoors.attribOpenLocks = "PickLocks"; statusDoors.attribFindTraps = "FindTraps"; statusDoors.attribRemoveTraps = "RemoveTraps"; statusDoors.hFlipOnOpen = true; // flip switch control horizontally when opened statusDoors.vFlipOnOpen = true; // flip switch control vetically when opened // usePercentageChecks determines how checks against skills are rolled // when true: attribute score + door modifier >= d100 equals success // when false: d20 + attribute score >= door modifier equals success statusDoors.usePercentageChecks = true; statusDoors.detectHiddenDC = 10; // ========== script constants - do not modify ========== statusDoors.lockStatus = "bar1_value"; statusDoors.lockQualityAdj = "bar1_max"; statusDoors.isUnlocked = "0"; statusDoors.isLocked = "1"; statusDoors.trapStatus = "bar2_value"; statusDoors.trapQualityAdj = "bar2_max"; statusDoors.trapNone = "0"; statusDoors.trapActive = "1"; statusDoors.trapResets = "2"; statusDoors.trapTriggered = "3"; statusDoors.trapDisabled = "4"; statusDoors.sideDoorOpen = "bar3_value"; statusDoors.sideDoorClosed = "bar3_max"; statusDoors.doorType = "aura1_radius"; statusDoors.doorTypeVisible = "0"; statusDoors.doorTypeHidden = "1"; statusDoors.doorTypeRevealed = "2"; statusDoors.doorSideActive = "aura2_radius"; statusDoors.doorSideBoth = "0"; statusDoors.doorSideNorth = "1"; statusDoors.doorSideSouth = "2"; //========== constructors ========== //define a door object function DungeonDoorControl() { var thisSwitch; var thisDoor; var thisWall; this.Load = function (SwitchID) { try { thisSwitch = getObj("graphic", SwitchID); if (thisSwitch == undefined) throw "Error loading Switch from id: " + SwitchID; thisDoor = getObj("graphic", state.DoorControls[SwitchID].DoorID); if (thisDoor == undefined) throw "Error loading Door from id: " + SwitchID; thisWall = getObj("path", state.DoorControls[SwitchID].PathID); if (thisWall == undefined) throw "Error loading Wall from id: " + SwitchID; return true; } catch (err) { log(err); return false; } } var SetMultiSide = function (side) { thisDoor.set({ currentSide: side, imgsrc: decodeURIComponent(thisDoor.get("sides").split("|")[side]).replace(/med\.png/g, "thumb.png"), }); } this.Open = function (pc) { //do nothing if door already open if (!this.IsClosed()) return; //trigger trap if armed and not GM if (!pc.IsGM() && SameSide(pc) &&( thisSwitch.get(statusDoors.trapStatus) == statusDoors.trapActive || thisSwitch.get(statusDoors.trapStatus) == statusDoors.trapResets)) { var trapNotes = decodeURIComponent(thisSwitch.get("gmnotes")).replace(/PC/g, pc.CharacterSheet().get("name")); sendChat("","/desc TRAP! " + trapNotes); //record the trap was found state.DoorControls[thisSwitch.get("_id")].TrapFound = true; //flag trap as triggered if not resetting if (thisSwitch.get(statusDoors.trapStatus) == statusDoors.trapActive) thisSwitch.set(statusDoors.trapStatus, statusDoors.trapTriggered); return; } //do not open if locked and not GM if(!pc.IsGM() && SameSide(pc) && thisSwitch.get(statusDoors.lockStatus) == statusDoors.isLocked) { //sendChat("","/desc This door appears to be locked."); pc.Announce("cannot open the door because it is locked."); return; } //set the door controls for open state thisWall.set("layer","gmlayer"); thisSwitch.set({ fliph: statusDoors.hFlipOnOpen, flipv: statusDoors.vFlipOnOpen, }); SetMultiSide(thisSwitch.get(statusDoors.sideDoorOpen)); if (!pc.IsGM()) pc.Announce("opens the door."); } this.Close = function (pc) { //do nothing if door already closed if (this.IsClosed()) return; //set the door controls for closed state thisWall.set("layer", "walls"); thisSwitch.set({ fliph: false, flipv: false, }); SetMultiSide(thisSwitch.get(statusDoors.sideDoorClosed)); if (!pc.IsGM()) pc.Announce("closes the door."); } this.PickLock = function(pc) { //do nothing if door is open or is GM if (!this.IsClosed() || pc.IsGM()) return; //do nothing if door is not locked if (thisSwitch.get(statusDoors.lockStatus) != statusDoors.isLocked || !SameSide(pc)) { pc.Whisper(null, "The door does not appear to be locked."); return; } //do nothing if character can't pick locks if(!pc.HasSkill(statusDoors.attribOpenLocks)) { pc.Announce("does not possess the skill to unlock this door."); return; } //check if character has attempted to unlock this lock before try { var prevAttempt = state.DoorControls[thisSwitch.get("_id")].UnlockAttempts[pc.CharacterSheet().get("_id")]; if (prevAttempt == undefined) throw "character has not seen this lock before"; //respond based on first attempt if (prevAttempt) { pc.Announce("is familiar with this lock, and quickly unlocks it again."); thisSwitch.set(statusDoors.lockStatus, statusDoors.isUnlocked); } else { pc.Announce("continues to fail at picking this lock"); } return; } catch (err) { } //roll the dice var charSkill = pc.SkillLevel(); var lockAdjust = (isNaN(thisSwitch.get(statusDoors.lockQualityAdj))) ? 0 : parseInt(thisSwitch.get(statusDoors.lockQualityAdj)); if (statusDoors.usePercentageChecks) { var rollResult = randomInteger(100); var actionSuccess = (Math.min(charSkill + lockAdjust, 95) >= rollResult) ? true : false; sendChat("Doors", "/w GM PICK LOCK: " + charSkill + "% chance with " + lockAdjust + "% lock modifier versus a roll of " + rollResult + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); } else { var rollResult = randomInteger(20); var actionSuccess = (rollResult + charSkill >= lockAdjust) ? true : false; sendChat("Doors", "/w GM PICK LOCK: d20 roll of " + rollResult + " plus skill " + charSkill + " vs DC " + lockAdjust + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); } //record the results state.DoorControls[thisSwitch.get("_id")].UnlockAttempts[pc.CharacterSheet().get("_id")] = actionSuccess; //announce the results to the party if (actionSuccess) { pc.Announce("has successfully unlocked the door."); thisSwitch.set(statusDoors.lockStatus, statusDoors.isUnlocked); } else { pc.Announce("does not possess the skill to unlock this door."); } } this.FindTraps = function(pc) { //do nothing if GM if (pc.IsGM()) return; //do nothing if character can't find traps, there is no trap, or on the wrong side if (!pc.HasSkill(statusDoors.attribFindTraps) || thisSwitch.get(statusDoors.trapStatus) == statusDoors.trapNone || !SameSide(pc)) { pc.Announce("is confident there are no active traps on this side of the door."); return; } //no need to check if trap has already been found if (state.DoorControls[thisSwitch.get("_id")].TrapFound == true) { pc.Announce("believes a trap has already been found."); return; } //check if this character as attempted to find traps before on this door try { var prevAttempt = state.DoorControls[thisSwitch.get("_id")].TrapFinding[pc.CharacterSheet().get("_id")]; if (prevAttempt == undefined) throw "character has not seen this trap before" //respond based on previous search if (prevAttempt) { pc.Announce("is familiar with this trap, and quickly identifies it."); } else { pc.Announce("is confident there are no active traps on this side of the door."); } return; } catch (err) { } //roll the dice var charSkill = pc.SkillLevel(); var trapAdjust = (isNaN(thisSwitch.get(statusDoors.trapQualityAdj))) ? 0 : parseInt(thisSwitch.get(statusDoors.trapQualityAdj)); if (statusDoors.usePercentageChecks) { var rollResult = randomInteger(100); var actionSuccess = (Math.min(charSkill + trapAdjust, 95) >= rollResult) ? true : false; sendChat("Doors", "/w GM FIND TRAPS: " + charSkill + "% chance with " + trapAdjust + "% trap modifier versus a roll of " + rollResult + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); } else { var rollResult = randomInteger(20); var actionSuccess = (rollResult + charSkill >= trapAdjust) ? true : false; sendChat("Doors", "/w GM FIND TRAPS: d20 roll of " + rollResult + " plus skill " + charSkill + " vs DC " + trapAdjust + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); } //record the character's results state.DoorControls[thisSwitch.get("_id")].TrapFinding[pc.CharacterSheet().get("_id")] = actionSuccess; //announce the results to the party if (actionSuccess) { pc.Announce("believes there is a trap on this door."); state.DoorControls[thisSwitch.get("_id")].TrapFound = true; } else { pc.Announce("is confident there are no active traps on this side of the door."); } } this.RemoveTrap = function(pc) { //do nothing if GM if (pc.IsGM()) return; //verify trap has been found if (state.DoorControls[thisSwitch.get("_id")].TrapFound != true) { pc.Whisper(null, "No one has found a trap to remove."); return; } if (!SameSide(pc)) { pc.Whisper(null, "I am on the wrong side of the door to disarm this trap."); return; } //do nothing if character can't remove traps if (!pc.HasSkill(statusDoors.attribRemoveTraps)) { pc.Announce("is confident there are no active traps on this door."); return; } //check if this character as attempted to remove trap before on this door try { var prevAttempt = state.DoorControls[thisSwitch.get("_id")].TrapDisarming[pc.CharacterSheet().get("_id")]; if (prevAttempt == undefined) throw "character has not tried removing this trap before" //respond based on previous search if (prevAttempt) { switch(thisSwitch.get(statusDoors.trapStatus)) { case statusDoors.trapDisabled: pc.Announce("believes this trap has already been disarmed."); break; case statusDoors.trapTriggered: pc.Announce("believes this trap has already been triggered."); break; default: pc.Announce("is familiar with this trap, and disarms it without a problem."); thisSwitch.set(statusDoors.trapStatus, statusDoors.trapDisabled); break; } } else { //always fail if first attempt was failed pc.Announce("believes any trap present has been disabled."); } return; } catch (err) { } //do not count as an attempt if trap is not active if (thisSwitch.get(statusDoors.trapStatus) != statusDoors.trapActive && thisSwitch.get(statusDoors.trapStatus) != statusDoors.trapResets) { pc.Announce("believes any trap present has been disabled."); return; } //roll the dice var charSkill = pc.SkillLevel(); var trapAdjust = (isNaN(thisSwitch.get(statusDoors.trapQualityAdj))) ? 0 : parseInt(thisSwitch.get(statusDoors.trapQualityAdj)); if (statusDoors.usePercentageChecks) { var rollResult = randomInteger(100); var actionSuccess = (Math.min(charSkill + trapAdjust, 95) >= rollResult) ? true : false; sendChat("Doors", "/w GM REMOVE TRAP: " + charSkill + "% chance with " + trapAdjust + "% trap modifier versus a roll of " + rollResult + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); } else { var rollResult = randomInteger(20); var actionSuccess = (rollResult + charSkill >= trapAdjust) ? true : false; sendChat("Doors", "/w GM REMOVE TRAP: d20 roll of " + rollResult + " plus skill " + charSkill + " vs DC " + trapAdjust + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); } //record the character's results state.DoorControls[thisSwitch.get("_id")].TrapDisarming[pc.CharacterSheet().get("_id")] = actionSuccess; //disarm trap if attempt was successful if (actionSuccess) { thisSwitch.set(statusDoors.trapStatus, statusDoors.trapDisabled); } //announce pseudo-results to the party pc.Announce("believes any trap present has been disabled."); } var SameSide = function(pc) { //true if set to both sides if (thisSwitch.get(statusDoors.doorSideActive) == statusDoors.doorSideBoth) return true; //determine angle to door based on rotation var a = (Math.atan2(pc.MapToken().get("top") - thisDoor.get("top"), thisDoor.get("left") - pc.MapToken().get("left")) * 180 / Math.PI + 180 + thisDoor.get("rotation")) % 360; var isNorth = (a >= 0 && a <=180) ? true : false; //return true if same side if (isNorth && thisSwitch.get(statusDoors.doorSideActive) == statusDoors.doorSideNorth) return true; if (!isNorth && thisSwitch.get(statusDoors.doorSideActive) == statusDoors.doorSideSouth) return true; return false; } this.DetectSecret = function(pc) { if (IsPathInRange(pc)) { //roll the dice var charSkill = pc.SkillLevel(); if (statusDoors.usePercentageChecks) { var rollResult = randomInteger(100); var actionSuccess = (charSkill >= rollResult) ? true : false; sendChat("Doors", "/w GM DETECTION (" + pc.CharacterSheet().get("name") + "): " + charSkill + "% chance vs roll of " + rollResult + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); } else { var rollResult = randomInteger(20); var actionSuccess = (rollResult + charSkill >= statusDoors.detectHiddenDC) ? true : false; sendChat("Doors", "/w GM DETECTION: d20 roll of " + rollResult + " plus skill " + charSkill + " vs DC " + statusDoors.detectHiddenDC + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); } //reveal door if detected if (actionSuccess) { thisSwitch.set({ layer: "objects", aura1_radius: statusDoors.doorTypeRevealed, }); pc.Announce("has discovered a hidden door."); sendPing(thisDoor.get("left"), thisDoor.get("top"), thisDoor.get("_pageid"), null, false); } } } var IsPathInRange = function (pc) { //split lastmove into array var lastmove = pc.MapToken().get("lastmove").split(","); var P1 = {X: pc.MapToken().get("left"), Y: pc.MapToken().get("top")}; var P2 = {X: 0, Y: 0}; var P3 = {X: thisDoor.get("left"), Y: thisDoor.get("top")}; var dX = 0; var dY = 0; var u = 0; var d = 0; //loop for each move segment, stop if ever true for (var i = lastmove.length; i > 0; i -=2) { //read the next point P2 = {X: parseInt(lastmove[i-2]), Y: parseInt(lastmove[i-1])}; log("Segment (" + P1.X + "," + P1.Y + ") and (" + P2.X + "," + P2.Y + ") to point (" + P3.X + "," + P3.Y + ")"); //set up delta values dX = P2.X - P1.X; dY = P2.Y - P1.Y; u = ((P3.X - P1.X) * dX + (P3.Y - P1.Y) * dY) / (Math.pow(dX, 2) + Math.pow(dY, 2)); //limit resuts to the move segment u = ( u > 1) ? 1 : (u < 0) ? 0 : u; log( " u factor: " + u.toFixed(2)); //calculate distance between segment and point d = Math.sqrt(Math.pow(((P1.X + u * dX) - P3.X),2) + Math.pow(((P1.Y + u * dY) - P3.Y),2)); log(" distance: " + d.toFixed(2)); if ( d <= statusDoors.detectionRange * 70) return true; //move P2 to P1 P1 = {X: P2.X, Y: P2.Y}; } return false; } this.IsClosed = function() { return (thisWall.get("layer") == "walls") ? true : false; } this.OnPage = function() { try { return thisSwitch.get("_pageid") } catch (err) { return undefined; }; } this.Icon = function() { return thisDoor; } this.Control = function() { return thisSwitch; } this.IsLocked = function() { return (thisSwitch.get(statusDoors.lockStatus) == statusDoors.isLocked) ? true : false; } this.IsTrapped = function() { return (thisSwitch.get(statusDoors.trapStatus) == statusDoors.trapActive || thisSwitch.get(statusDoors.trapStatus) == statusDoors.trapResets) ? true : false; } this.IsHidden = function() { return (thisSwitch.get(statusDoors.doorType) == statusDoors.doorTypeHidden) ? true : false; } } //define a player object function PlayerControl() { var thisAs; var thisCharacter; var thisToken; var roleGM = false; var thisAttrib; this.Load = function (msgWho, pageID) { //set the current speaker thisAs = msgWho; //find a character sheet thisCharacter = findObjs({ _type: "character", name: msgWho, })[0]; //determing if running as GM roleGM = (msgWho.indexOf("(GM)") != -1) ? true : false; //find a token on map if not GM if (thisCharacter) { thisToken = findObjs({ _type: "graphic", _pageid: pageID, represents: thisCharacter.get("_id"), })[0]; } //clear any previous attributes thisAttrib = undefined; } this.Whisper = function(SendAs, SendMsg) { sendChat((SendAs == null ? thisAs : SendAs), "/w " + thisAs.split(" ")[0] + " " + SendMsg); } this.Announce = function(SendMsg) { sendChat("character|" + thisCharacter.get("_id"), "/em " + SendMsg); } this.InRange = function(obj) { var distance = Math.sqrt(Math.pow(thisToken.get("top") - obj.get("top"),2) + Math.pow(thisToken.get("left") - obj.get("left"),2)); return (distance > statusDoors.interactRange * 70) ? false : true; } this.HasSkill = function(attribName) { thisAttrib = findObjs({ _type: "attribute", _characterid: thisCharacter.get("_id"), name: attribName, })[0]; try{ if (isNaN(thisAttrib.get("current")) || thisAttrib.get("current") <= 0) throw "character attribute <= 0 or NaN"; return true; } catch (err) { return false; } } this.SkillLevel = function() { try { return (isNaN(thisAttrib.get("current"))) ? 0 : parseInt(thisAttrib.get("current")); } catch (err) { return 0; } } this.IsGM = function() { return roleGM; } this.CharacterSheet = function() { return thisCharacter; } this.MapToken = function() { return thisToken; } this.OnPage = function() { return thisToken.get("_pageid"); } } //========== events ========== on("chat:message", function (msg) { //handle only player commands var cmdNames = ["!OpenDoor", "!CloseDoor", "!PickLock", "!RemoveTrap", "!FindTraps"]; if (msg.type != "api" || cmdNames.indexOf(msg.content) == -1) return; //selection must be a single item try { if (msg.selected.length != 1) throw "multiple items selected"; } catch (err) { return; } //load the player var pc = new PlayerControl(); pc.Load(msg.who, getObj(msg.selected[0]["_type"], msg.selected[0]["_id"]).get("_pageid")); //do nothing if not playing as a Character or GM if (!pc.CharacterSheet() && !pc.IsGM()) { pc.Whisper("GM","Please set your 'AS' drop option to a character first."); return; } //load the door control var door = new DungeonDoorControl(); if (!door.Load(msg.selected[0]["_id"])) return; if (!pc.IsGM()) { //verify character has token on the map if (pc.MapToken() == undefined) { pc.Whisper(null, "I don't have a token on this map."); return; } //verify character token is close enough to the door if (!pc.InRange(door.Icon())) { pc.Whisper(null, "I am too far from the door to do that."); return; } } switch(msg.content) { case "!OpenDoor": door.Open(pc); break; case "!CloseDoor": door.Close(pc); break; case "!PickLock": door.PickLock(pc); break; case "!RemoveTrap": door.RemoveTrap(pc); break; case "!FindTraps": door.FindTraps(pc); break; } }); //player chat commands on("chat:message", function (msg) { //handle only GM commands var cmdNames = ["!ObjectList","!DoorsLink","!DoorsResetUse","!DoorsAllOpen","!DoorsAllClose","!DoorsAlign","!DoorsCount","!DoorsDeleteAllLinks","!SideID","!DoorsTableUpdate"]; if (msg.type != "api" || msg.who.indexOf(" (GM)") == -1 || cmdNames.indexOf(msg.content) == -1) return; var pc = new PlayerControl(); pc.Load(msg.who, null); switch(msg.content.split(" ")[0]) { case "!DoorsLink": //make sure three items are selected try { if (msg.selected.length != 3) throw "invalid selection"; } catch (err) { sendChat("Doors", "/w GM Select a graphic named 'Switch', a graphic named 'Door' and a path to use as a wall."); return; } //set up count variables var linkSet = {}; linkSet.SwitchID = []; linkSet.PathID = []; linkSet.DoorID = []; //identify each type of selected _.each(msg.selected, function(obj) { try { var o = getObj(obj["_type"], obj["_id"]); if (o.get("_type") == "graphic" && o.get("name") == "Switch") { linkSet.SwitchID.push(o); } else if (o.get("_type") == "graphic" && o.get("name") == "Door") { linkSet.DoorID.push(o); } else if (o.get("_type") == "path") { linkSet.PathID.push(o); } } catch (err) { } }); //verify only one of each type role in selection if (linkSet.SwitchID.length != 1 || linkSet.DoorID.length != 1 || linkSet.PathID.length != 1) { sendChat("Doors", "/w GM Select a graphic named 'Switch', a graphic named 'Door' and a path to use as a wall."); return; } //add the selected as a door AddSwitchControl(linkSet.SwitchID[0], linkSet.DoorID[0], linkSet.PathID[0]); break; case "!DoorsResetUse": _.each(state.DoorControls, function(obj) { obj.UnlockAttempts = {}; obj.TrapFinding = {}; obj.TrapDisarming = {}; obj.TrapFound = false; }); sendChat("Doors","/w GM All doors have been reset to 'never been seen' status."); break; case "!ObjectList": _.each(msg.selected, function(obj) { try { log(getObj(obj["_type"], obj["_id"])); } catch (err) { } }); break; case "!DoorsAllOpen": var door = new DungeonDoorControl(); _.each(state.DoorControls, function(obj) { door.Load(obj.SwitchID); if (door.OnPage() == Campaign().get("playerpageid")) door.Open(pc); }); break; case "!DoorsAllClose": var door = new DungeonDoorControl(); _.each(state.DoorControls, function(obj) { door.Load(obj.SwitchID); if (door.OnPage() == Campaign().get("playerpageid")) door.Close(pc); }); break; case "!DoorsAlign": var door = new DungeonDoorControl(); _.each(state.DoorControls, function(obj) { door.Load(obj.SwitchID); if(door.OnPage() == Campaign().get("playerpageid")) { obj.Left = door.Icon().get("left"); obj.Top = door.Icon().get("top"); obj.Rotation = door.Icon().get("rotation"); obj.Width = parseInt(door.Icon().get("width") / 4); obj.Height = parseInt(door.Icon().get("height") / 4); door.Control().set({ left: obj.Left, top: obj.Top, rotation: obj.Rotation, width: obj.Width, height: obj.Height, }); } }); break; case "!DoorsCount": var iDoors = 0; var iLocks = 0; var iTraps = 0; var iHidden = 0; var iErrors = 0; var door = new DungeonDoorControl(); _.each(state.DoorControls, function(obj) { if (door.Load(obj.SwitchID)) { iDoors++; if (door.IsHidden()) iHidden++; if (door.IsLocked()) iLocks++; if (door.IsTrapped()) iTraps++; } else { iErrors++; } }); sendChat("Doors","/w GM Doors:" + iDoors + ", Locked:" + iLocks + ", Trapped:" + iTraps + ", Hidden:" + iHidden); if (iErrors > 0) sendChat("","/w GM There were " + iErrors + " doors that did not load properly."); break; case "!DoorsDeleteAllLinks": _.each(state.DoorControls, function(obj) { getObj("graphic", obj.SwitchID).set("layer","objects"); getObj("graphic", obj.DoorID).set("layer","objects"); getObj("path", obj.PathID).set("layer","objects"); }); state.DoorControls = {}; sendChat("Doors","/w GM All door links have been deleted from state. No doors will function until relinked with !DoorsLink command."); break; case "!SideID": try { if (msg.selected.length != 1) throw "selection error"; var obj = getObj(msg.selected[0]["_type"], msg.selected[0]["_id"]); sendChat("Doors", "/w GM SIDEID: obj [" + obj.get("name") + "] is set to side: " + obj.get("currentSide")); } catch (err) { sendChat ("SIDE", err); } break; case "!DoorsTableUpdate": //make sure we have one door image selected if (!msg.selected || msg.selected.length != 1) { sendChat("Doors","/w GM Select a single door graphic"); return; } var newDoor = getObj("graphic", msg.selected[0]["_id"]); if (newDoor.get("name") != "Door") { sendChat("Doors","/w GM Selected door must be named 'Door'."); return; } //update all doors' 'sides' to selected door's 'sides' var iErrors = 0; _.each(state.DoorControls, function(obj) { try { thisDoor = getObj("graphic", obj.DoorID); thisDoor.set({ imgsrc: decodeURIComponent(newDoor.get("sides").split("|")[thisDoor.get("currentSide")]).replace(/med\.png/g, "thumb.png"), sides: newDoor.get("sides"), }); } catch (err) { iErrors++; log("Error updating door " + obj.DoorID); } }); //display results of update if (iErrors == 0) { sendChat("Doors","GM Table images updated sucessfully."); } else { sendChat("Doors","Table images updated, but " + iErrors + " error(s) occured."); } break; } }); //GM chat commands on("change:graphic", function(obj) { //only reset a valid switch var o = state.DoorControls[obj.get("_id")]; if (!o) return; //keep the switch in place try { obj.set({ top: o.Top, left: o.Left, rotation: o.Rotation, width: o.Width, height: o.Height, layer: (obj.get(statusDoors.doorType) == statusDoors.doorTypeHidden) ? "gmlayer" : "objects", aura1_color: "transparent", aura2_color: "transparent", lastmove: "", statusmarkers: "", }); } catch (err) { } }); //prevents switch movement on("destroy:graphic", function(obj) { try { var o = state.DoorControls[obj.get("_id")]; if (!o) return ; //move door back to objects layer try { getObj("graphic", o.DoorID).set("layer","objects"); } catch (err) { } //move wall back to objects layer try { getObj("path", o.PathID).set("layer","objects"); } catch (err) { } //remove data from state delete state.DoorControls[obj.get("_id")]; sendChat("Doors","/w GM A door control has been deleted. Associated controls have been moved to the objects layer."); } catch (err) { log (err); } }); //remove link in state when switch deleted on("change:graphic", function(obj) { //do nothing if not a character if(obj.get("represents") == "" || state.DoorControls[obj.get("_id")]) return; //check controlledby for character var pcSheet = getObj("character", obj.get("represents")); if (pcSheet.get("controlledby").replace("all","") == "") return; //load the player var pc = new PlayerControl() pc.Load(pcSheet.get("name"), obj.get("_pageid")); //dm cannot detect secret doors if(pc.IsGM()) return; //no proximity check needed if no skill if (!pc.HasSkill(statusDoors.attribFindHidden)) return; //find all secret doors on the same page as the token var secretSwitches = findObjs({ _type: "graphic", _pageid: pc.OnPage(), aura1_radius: statusDoors.doorTypeHidden, }); //check detection for each hidden door var door = new DungeonDoorControl(); _.each(secretSwitches, function(secretSwitch) { if (door.Load(secretSwitch.get("_id"))) door.DetectSecret(pc); }); }); //check movement for proximity to secret doors //========== functions ========== var AddSwitchControl = function(thisSwitch, thisDoor, thisPath) { //use the switch as a reference ID in state var thisID = thisSwitch.get("_id"); //pair items in state data state.DoorControls[thisID] = ({ SwitchID: thisID, PathID: thisPath.get("_id"), DoorID: thisDoor.get("_id"), Left: thisSwitch.get("left"), Top: thisSwitch.get("top"), Rotation: thisSwitch.get("rotation"), Width: thisSwitch.get("width"), Height: thisSwitch.get("height"), }); //set additional state variables state.DoorControls[thisID].UnlockAttempts = {}; state.DoorControls[thisID].TrapFinding = {}; state.DoorControls[thisID].TrapDisarming = {}; state.DoorControls[thisID].TrapFound = false; //set default values for locks as traps thisSwitch.set({ bar1_value: statusDoors.isUnlocked, bar1_max: "0", bar2_value: statusDoors.trapNone, bar2_max: "0", aura1_radius: statusDoors.doorTypeVisible, aura1_color: "transparent", aura2_radius: statusDoors.doorSideBoth, aura2_color: "transparent", gmnotes: "PC has triggered a trap.", }); //format the switch to default role settings thisSwitch.set({ layer: "objects", isdrawing: true, showplayers_name: false, showplayers_bar1: false, showplayers_bar2: false, showplayers_bar3: false, showplayers_aura1: false, showplayers_aura2: false, playersedit_name: false, playersedit_bar1: false, playersedit_bar2: false, playersedit_bar3: false, playersedit_aura1: false, playersedit_aura2: false, controlledby: "all", }); //move the door graphic to the map layer thisDoor.set({ layer: "map", }) //move the lighting path to the walls layer thisPath.set({ layer: "walls", stroke: statusDoors.DoorPathColor, stroke_width: 5, fill: "transparent", }); try { var door = new DungeonDoorControl(); if (!door.Load(thisID)) throw "could not load new door"; sendChat("Doors","/w GM Door has been successfully linked. ID:" + thisID); } catch (err) { sendChat ("Doors", "/w GM ERROR: " + err); } } //adds trio as a door control //========== non-essential ========== on("chat:message", function(msg) { cmdName = "!CleanUp"; if (msg.type != "api" || msg.content.indexOf(cmdName) == -1) return; _.each(findObjs({ _type: "graphic", name: "Switch"}), function(o) { o.set({ layer: "gmlayer", width: 140, height: 140, top: 70, left: 70, }); }); _.each(findObjs({ _type: "graphic", name: "Door"}), function(o) { o.set({ layer: "gmlayer", width: 140, height: 140, top: 70, left: 70, }); }); _.each(findObjs({ _type: "path", stroke: statusDoors.DoorPathColor, stroke_width: 5, fill: "transparent"}), function(o) { o.set({ layer: "gmlayer", top: 70, left: 70, }); }); });
1391824216
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Aura.... You can't always see the bars if you are a player. but you can see the aura. Grey unknown... Green unlocked or something. just a thought... But this really good stuff and a good idea.
1391824585

Edited 1391825202
Matt
Pro
I used the bars because I don't want the players to know the status of the door visually. This forces them to actively be checking. Also allows me to lock the door behind them without them knowing, or reset a trap they thought was disabled. Enemies can be tricky that way. :) Although maybe I can add in where the players can mark the door with an aura, so they can flag a door as they see fit. Only problem with that is if they come to the other side of a door, and don't realize it's the same door, the aura would give it away. Will have to think on this, but I like it. My original thought on the auras was to use this as a timer.. maybe for the door to re-lock, or the trap to reset. Haven't added that in yet, so now i have to think which would be a better use of the auras. Do appreciate the feedback.
1391828331

Edited 1391828425
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
The bars might be the best idea... was just thinking out loud. Do players have to have control to target a token? A door could always start out "grey" (unknown) and "yellow" if checked for traps (you don't really know if you found it perhaps) "red" if the trap sprung and "green" if safely unlocked.... over time... or player distance.... they doors "forget": and go back to grey. You could even use aura shape for the closest door (square shape for the nearest door and therefore assumed to be the target)..... that way just player movement does all the targeting (upper left door wins in a tie for distance or something.) Then you don't need to be able to target at all..... and the script should be able to handle any token named "door" the same... and manage everything by player proximity.
Think outloud all you wish... I appreciate any insight at all. Yes, players have to have control of the door switch token. Part of the script keeps them from moving or resizing the switch. When the !DoorsLink command is run, the switch is formatted to limit player's visibility. I'm still toying with the aura idea. The issue is that when an aura is applied, it's a 360 degree aura. So if they come up to the same door from the other side, but don't realize it's the same door, the aura would already inform them of the status, thus robbing me, the DM, the joys of them possibly falling prey to the same trap twice. The issue with letting a script decide is inevitably i'll run into an issue where the script targeted the wrong door by proximity, and a player complain that this wasn't the door intended. Virtual dice are thrown at me, and details of the unintentional targeted door are revealed. Though I may use proximity as a trap mechanic... Hmmm... maybe the aura could be used for proximity distance to trigger. Doors and Switches can be renamed after they are linked... this way the GM can label the doors or switches if needed. The script only looks for 'Door' and 'Switch' when linking because both are graphic objects, and I needed a way to tell them apart.
I've gone through and started adding these doors/switches my current campaign. Thought I'd share one section containing several rows of jail cells. Was curious how long the setup time for doors would take. This jail section has about 80+ doors, from start to finish took about 20 min to add my doors and link them all together. Not too bad, considering the time I'll save when they get here, and I don't have to switch to the lighting layer to open/close any cell, rolls for locks, tracking which were locked, etc. I am working on directional traps and locks. This way, I can have doors that PCs can move through in one direction freely, but locks and/or traps when they go back the other way. My group likes to close doors behind them, so this might be an easy way to lock themselves in a not-so-friendly room.
Would you be able to post a screenshot of your rollable table for the images? You mentioned you use them for the doors, but I'm not understanding how they come into play here.
Sure. Here's the first few items in my table. The first two images show a simple wooden door, one in a closed state, and one in an open state. These are the first two images in my table, so in my switch token, I would set bar3_value to 1 for my open state, and bar3_max to 0 for my closed state. Had I wanted a reinforced door, I would have chosen 5 as my open state, and 4 as my closed state. Remember that the list begins numbering at 0. The images for the doors took some time to set up. For me, I found a base image size of 280x280 pixels was best to work with. I made the center of my image the center of my door when closed. By doing this, I could easily change a door style by choosing a different side of my token without worrying about distorting image or having to realign anything in my map. Also makes it easy to choose which way the door will open by rotating, and which side of the door was hinged by flipping horizontally. Below are two sets of images. The black X shows the boundries of the image, center of door in center of image, and doors are always opening to the north.
1392074350
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Thinking a good door tile should pivot at the hinged these should be 2 by 2 grid... The hinged is just static against the wall..... now you can use rotate for the door... now you can even do "peek" as a command.
I like the idea of the hinge on the edge of the door, but I think I'll add it as part of the door image in the table. Thanks! Not sure I understand the 'peek', unless you mean allowing the players to rotate the door (an in effect, rotating the dynamic lighting path)?
1392076105
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Oh you know how those thieves are... sneaking up to the door.... picking the lock.... and then just opening the door a crack wide so they can peek in. With rotate you can open the door any number of degrees.
I'll spring-load all my doors so it'll be difficult to just peek. Not sure about the rotation of the doors as a 'peek' method with what I already have set up, kinda goes against the structure. But I like the idea of peeking. Maybe I could not 'open' the door when peeking, but reduce the width of the lighting wall to 90%. Should allow some visibility while still working on top of the structure already in place. Only issue is with double doors. With a single door, it would allow light in at a point you'd expect. But with double doors you'd think they'd be peeking in the middle, not at the edge. I'll have to think on this a bit...
1392078355
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
So thinking about this with the dungeon generator (that is where my thinking is coming from.) The "gear" in your screenshot is really what the players interact with and not the door correct? If that is true you can have token action for each "gear" so targeting the "gear" brings up the token action bar with: SearchForTraps RemoveTrap PickLock OpenDoor CrackDoor
Thanks for the screenshot and explanation Matt. That actually cleared up everything that I was wondering. I also love that Stephen is jumping in on this because his dungeon generation script is exactly what I was thinking about this scripting for. I'm going to have to give this a try!
Correct. The gear is my switch. It stays on the objects layer. When linked with !DoorsLink, the door icon is moved to the map layer, and the path is moved to the walls layer. So the only object players can interact with is the switch. Here are the settings each switch follows by default (minus the bar values). I could rename the switch if I needed a label to display, but that can only be done after the link is established. I do rotate the switch to the same rotation as the door. This allows the PC a visual of which way the door will open. I set all my doors to open to the top, which is where the rotation handle is located. So if you are on the side of the door with the rotation handle, you know the door will open towards you. I like the idea of using token action bars for the player commands. There's already checks in place to make sure the player has a valid switch selected before doing anything, so if they try to !PickLocks on their own token, no harm done.
Oh, I like that idea of making token actions for switches. Currently I have it set up so there's a lever or a button next to a door to activate it opening. All I need to do is make a character sheet for the switch and associate the token, give it the macros of "open" "pick lock" etc.. This is just getting more and more awesome as it goes!
1392085651
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
You are already checking player proximity to the door. Make the "switch" visible only when the player is near enough to activate it. (Or maybe not...this is already 610 lines of code... I am bad about "adding" too much.)
1392087862

Edited 1392265273
Matt
Pro
Edit: I have since found the follow text to be inaccurate. Can be managed from a single character sheet, just do not leave the bars linked to an attribute. Apologies for the incorrect info. There may be issues with using a character sheet as the script uses 'represents' as a key search. I will need to verify this will not cause an issue. Correct me if I'm wrong, but you can't use a character sheet with the switch token (at least not in this particular setup). Because each door has its own value for being locked and/or trapped, along with its own attribute modifier, you can't associated it with a character sheet and have each door function uniquely. If you change an associated switch to make one door locked, it updates the character sheet, and thus updates all doors associated with that sheet, effectively locking all of your doors. Each macro should be a global macro with access to all and use as token. Functions as intended, but the macro bar will show for every token - even non-door tokens. Not sure about the proximity idea. I could check for characters within range of all my doors, and any in range the switch would move to the objects layer, otherwise stay hidden on GM layer. However, if as GM I want to open/close a door or change a lock/trap status, i'm back to swapping layers to make these changes. But that does spawn a new idea. (gotta love collaboration)... I was looking for a function for the auras - seems a waste to have two unused fields. :) aura1 I had decided to make a directional indicator, as to say the door is only locked/trapped from one side and not the other. And that left aura2 all alone. But what about secret/hidden doors.... Could use the lastmove along with aura2 to see if a player came close enough to detect a secret door, and if so, roll against their attribute. Success reveals the token, failure keeps the token hidden. Looks as if 610 lines of code isn't enough...
1392160752

Edited 1392545752
Matt
Pro
I have added in the ability to detect secret doors. This uses the "aura1_radius" value. A value of 0 would be a normal door, and the switch would be on the objects layer. A value of 1 would be a hidden door. The switch is moved to the gmlayer automatically so the players cannot see nor interact with the switch. When a player walks within range of a hidden door, a secret roll is made against the character's attribute score. No changes are made, and no notifications to the party if the roll fails. Multiple walk-bys are each checked as long as the door remains hidden. Success moves the door switch to the objects layer, and pings the map where the door was revealed. The visual of the door is still controlled by the door rollable table token, so could add in specific tokens for hidden door types when open and closed, and control it by the values within bar3_value (open) and bar3_max (closed), The check distance is set by the statusDoors.detectionRange variable, which is independent of the statusDoors.interactRange. Currently is set for 2 map units. Finally, the range check is using each waypoint segment in the character's move. However, if the character walks past the same door twice in a single move, only one check is made. In the screen shots, the first hall doesn't reveal the switch (i'm using a cog wheel). When the token was moved within range and a successful check made, the switch becomes visible, and function as any other door. One catch - I cannot tell who is moving the token. So the check will occur even if the DM moves a token that represents a character. Up to 748 lines...
I notice you make mention to the character's attribute scores.. are you using Thievery for the lockpicking and disabling of traps and Perception for discovery... or is it left open to any attribute that a GM may choose?
1392165256

Edited 1392165550
Matt
Pro
There are four attributes that are used in this script... so far. They can be changed near the top of the code to any attribute the GM wishes to use by modifying these lines: statusDoors.attribFindHidden = "FindHiddenDoors"; statusDoors.attribOpenLocks = "PickLocks"; statusDoors.attribFindTraps = "FindTraps"; statusDoors.attribRemoveTraps = "RemoveTraps"; So if you wanted to use Perception for discovery and Thievery for Lockpicking, you could modify these lines to read: statusDoors.attribFindHidden = "Perception"; statusDoors.attribOpenLocks = "Thievery"; statusDoors.attribFindTraps = "Perception"; statusDoors.attribRemoveTraps = "Thievery"; Should a character not possess the attributes listed on these four lines, any roll against that attribute would fail automatically.
ah, I see. Thank you. I've been having my players use a macro of [[d20+?{modifier}]] for their skill checks.. but that's mainly because I didn't want to have a character sheet with extensive attributes (even though they are simple to generate via API now). Shouldn't be difficult to add in 2 more attributes though. Thank you Matt for getting my lazy butt into gear haha
I have completely re-written the coding for this script for a couple different reasons. 1) trying a different approach to the code design. 2) cut down on repetition of code within the different commands. 3) there were a couple of snags when trying to use a character sheet for the switch control. The changes I've made will work with the state data from the previous version, so there should be no impact on previous setups. I copied this script from my testing campaign to my live campaign, and all 300+ doors loaded successfully. (granted, if I want to use a character sheet for my switch tokens, I'll need to re-link them, but the doors function just as they did before). I have separated the player commands that open and close the door. There are now two separate commands: !OpenDoor and !CloseDoor. This keeps two players from trying to open the door at relatively the same time, which has caused the door to open then close. Character Sheets can now be used for a switch, allowing the macros to be tied to the character sheet and set as a token action, instead of using global macros. Added in directional use of the doors using aura2_radius. By default, this is set to 0, meaning that if the door is locked, it is locked on both sides. Same goes for any trap. Setting aura2_radius to 1, the north side of the door becomes the locked/trapped side, or the 'active side'. Setting aura2_radius to 2, the south side become the 'active side'. All commands function as normal when the player's token is on the same side as the active side. However, should a player issue a command on the opposite side, the door will function as if not locked and not trapped without affecting the actual status of the lock/trap. For example: Door is locked and trapped on side A. Player approaches door from side B. Player checks for traps on side B, doesn't find any. Player tries to open door from side B, door opens. Player steps through, and closes the door. Moments later, the player comes back to door from side A. Player attempts to open door from side A, trap is triggered. Player tries again to open door from side A, door is locked. Player picks lock and tries to open door from side A, door opens. As always, I'm open to suggestions and/or feedback - either as in how the script works or should work, or as in the coding techniques and approach I use.
When I mentioned before about using character sheets to represent the switch, I didn't realize you could use a global macro for it (which I am doing now, using the previous form of the code). I hope that I didn't send you back through the coding labyrinth because of that. Is there a way to, since there is now character sheet connectivity, when a trap is triggered use an ability stored on the sheet? Say, using your example... when the player triggers the trap trying to reopen the door have it use a trap attack macro? I know that there may be a bit of difficulty with this idea because I use a combat mitigation script that takes care of all damage, rolls, crits, statuses, resistance, and so on and that relies on the command !power. I was thinking that if the macro was already set up in the character sheet, there may be a way for the API to read that ability and trigger it when the trap is triggered. Do you think that is doable?
Sounds easy enough, if i'm understanding your request. The effect would be: Player tries to open a trapped door Trap is triggered GMNotes are displayed as a /desc Ability from 'switch' character sheet is executed GM rolls in fits of laughter So the script will look for a particular ability, and if present, execute. It would be left up to the GM as to the scripting of the actual ability. Correct?
yes, exactly. Especially the last bullet. I wasn't sure how it would work where the macro triggered by the API called on another script with a chat command. I didn't know if there would be an issue with it not working (I've tried including macros that included other abilities with the power within other macros without much success). Would you like an example macro of one I'd use, or to see the other script?
I would like to see, just as a check-safe. Only issue I can foresee is if your macro requires a target, because at the time, the swich token would still be selected.
Well, the macro would require a target. That I do know. Here is the aforementioned script, and an example macro would be: power -a [[1d20]] -d [[2d6+3]] -v AC -t @{target|token_id} -h "Target is stunned (save ends)" -e "Target takes 5 ongoing damage" @{selected|token_id} "Some Attack" Can you see any way around using targeting to utilize a macro for this?
Am I to assume that @{target|token_id} would be the character that tripped the trap?
That would be correct.
actually, shouldn't be a problem. would just need to modify the macro slightly. I'll see what I can do...
ooh, that's awesome. Thank you!
I've added a new line near the top of the code. This should be the same name as the ability on the switch control. statusDoors.abilityOnTrap = "TrapTriggered"; In the Switch ability, replace any instance where you'd normally want the token id with TOKENID. In your example, it would be written as this: power -a [[1d20]] -d [[2d6+3]] -v AC -t TOKENID -h "Target is stunned (save ends)" -e "Target takes 5 ongoing damage" @{selected|token_id} "Some Attack" The script will replace TOKENID with the token_id that opened the door. Not familiar with what all the !power command does, nor its command switches. Wasn't sure if the @{selected|token_id} should also be the player's token, or another token, so it's left alone in the above macro. However, if it's also the player's token, it too can be replaced with TOKENID. I've been able to run the switch abilities as a player with some commands, but can't test with your !power command. When you get a chance, try it and let me know if successful.
Ok, I'll give that a shot now. The @{selected|token_id} is the token using the power (so the switch). I think that since you have to select the switch, that should be ok.
Hm, it looks like it triggers ok, but it doesn't really matter that the script is replacing the selected target with TOKENID.. When it triggers the ability it's not interacting with the other script at all.
k, will see what can be done. patience... :)
That was a quick reply lol. Thanks for all the work you're doing on this. :)
I stand corrected. Apologies. I've not found a way to send a different api command to be executed via chat window. Also haven't found a way to alter the player's select so the ability could just be executed. Only method I found was with another function, but this would mean possibly a new function for each macro that required an api command. Not very portable that way, so I've decided to leave this functionality out. Should I (or someone more knowledgable than myself) find a method more agreeable, I'll add it back in.
1392536246

Edited 1392542374
Matt
Pro
I did make a few modifications to the script as I was working on the ability idea, mostly subtle. Announcements made by the pc are done as an /emote instead of a /description. Also changed some value types, which cut down on some conversion statements. And when you delete a switch graphic, the door graphic and wall path are automatically moved to the objects layer as well, which makes it easier to re-link or delete if needed (i got tired of swapping layers). None of these changes will have any impact on previous state data, so should be good to go... 846 lines.
Well, we can't have everything? Right? :) Thanks for trying at least. I can always use a regular macro using inline rolls and then use a direct damage macro that utilizes the other script. There's always a workaround. Also, you're a trooper man.. that's a pretty long code. I only know the most basic elements of this, and only because I've been struggling to teach myself (really I've just been a what-if guy in this situation), and I can say that seems like it would be really time consuming. This is an amazing script and very useful, so thank you for all the work you put into it.
Corrected a calculation in the detection of secret doors.
Was just implementing this for a starter campaign and was wondering: You had mentioned that all checks were based on a d100 roll with the difficulty subtracted from it and the player's skill added to it... what is the success target?
The player's attribute is the baseline for success. The baseline is adjusted by the door's '_max' values. The goal is to roll under or equal to the adjusted baseline. Using 'Thievery' as an example to unlock a door... If your character has 'Thievery' set to a current value of 40, then your character has a baseline 40% chance to successfully unlock a door. Any roll on the d100 that is 40 or less would indicate success, and the door would 'unlock'. For each door, you can modify the success rate by entering a value in 'bar1_max'. DoorA has a 'bar1_max' value of -20 and DoorB has a 'bar1_max' value of 10. These modifications are added to your character's baseline chance before comparing to the d100 roll. So for DoorA, you would only have a 20% chance of success, while DoorB would yield a 50% chance of success. The same concept is used for finding and removing traps. Find Hidden Doors works just a bit different. This mechanic works on the assumption that the player isn't actively checking, but merely walking by the door. There is no adjustment for this check and is simply a d100 roll against the attribute, again the goal to be to roll under or equal to the attribute score. In my games at least, active checks must be announced as an action by the player and are made with a different degree of success than a casual walk-by.
ok, that explains a bit better than I was assuming. I was running off of the assumption that the number in the Thievery and Perception attributes were their modifier for a skill check. I could probably do a little math and find out what percentage of my normal DC for lock picking and noticing doors is and just use that as a percentage. That way it would be a little more accurate to the character.. I guess that means I'm off to face my old nemesis.. (math)
I think trying to do it your way, I would have to change the way the calculations are done - each door would have its own DC value. With a little effort, i believe i could make this work for both of us. Is the basic formula: d20 + Thievery >= DC value of door?
1393274725
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Matt you don't rotate created object do you? And how are you moving the paths on the walls layer? I get a firebase error when I try to rotate created objects. Any thoughts?
In this particular script, I do not create objects nor move items on the walls layer. The only rotation I perform is on the 'switch' control, and this is set to a fixed value based on the rotation of the 'switch' at the time the link is set. This is to keep the switch in the same orientation in the event a player accidentally tries to rotate it. I also do not move items on the walls layer. The door path is moved from the walls layer to the GM layer, but the position remains the same. I've not encountered any firebase errors (yet) but will see if I can replicate it.
1393275594
Stephen S.
Pro
Marketplace Creator
Sheet Author
API Scripter
Matt said: I've not encountered any firebase errors (yet) but will see if I can replicate it. Its easy to replicate the error.... just run anything I have made it seems =P
Matt said: I think trying to do it your way, I would have to change the way the calculations are done - each door would have its own DC value. With a little effort, i believe i could make this work for both of us. Is the basic formula: d20 + Thievery >= DC value of door? Yeah, that's exactly the formula I use. I was also wondering.. is there a simple line I can put into the script somewhere so that when a switch is activated (like.. when the door opens) it either rotates the switch token 180* or flips it? I had originally thought about flipping it, but I'm not sure how flipping horizontally and vertically work when the token is rotated, and since the token isn't always left at the same rotation I wasn't sure how it would work out. Essentially, the idea I was thinking is that of a lever with either an up/down or a left/right thing.. so say the lever in the regular orientation for the door being closed is up, and when you activate it, you pull it down so the door opens.. same idea for the left to right.. is that doable? (I know it's all just aesthetics.. so it's not high priority.. just something I'm curious about lol)
Flipping the icon would be doable, too. I'll see if I can get both of these added in.
Awesome, thank you :)