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

I guess I'm slow...

I just can't figure this out. &nbsp;I"m trying to use Matt's Door Script. (I know it's not new, but its new to me.). I have created the rollable table. I have created 'door' graphics, and uploaded them to my library as .png files. I then dragged the door images from my art library into the rollable table... I used a separate 'gear' icon to represent the switch. When I click the 'token' button for the rollable table - it places a door. If i rightclick it , i get the 'multi-sided' option and i can click 'door open' and 'door closed' All good so far.&nbsp; So then, I put the door in place, draw the line I want for the dynamic lighting layer, and put the switch in place. I edit the door token and name it 'door'. I edit the switch token and name it 'switch'. !LinkDoors Success!! I get a door on the map, but hte only 'interactable' part for players is the handle gear. &nbsp;The dynamic lighting line is moved the right layer, looks great. So then, I select the switch, and go !OpenDoor And.. the Dynamic lighting line is moved to GMINFO , so the lighting now floods through the open doorway - but..&nbsp; "ERROR: You cannot set the imgsrc or avatar of an object unless you use an image that is in your Roll20 Library. See the API documentation for more info." Depending on how much fiddling i'm doing with the switch, i also sometimes get "ERROR: Please use the 'thumb' size for imgsrc properties." And.. the door graphic doesn't change , and the Side-ID of the door also doesn't change.&nbsp; The image *is* in my library - its my own graphic which I uploaded. I'm using the original script from&nbsp; <a href="https://app.roll20.net/forum/post/636123/script-do" rel="nofollow">https://app.roll20.net/forum/post/636123/script-do</a>... I can't see what steps I've missed with this..
1494241222
The Aaron
Pro
API Scripter
Somehow, despite putting the images in your Library, you've created the Rollable Table with images from the Marketplace. &nbsp;You need to be certain that you are dragging images to the rollable table for your doors from your My Library section of the Art Library: After you do that, you should be fine. Regarding the "Please use the 'thumb' size for imgsrc properties" message, that has to do with the URL of the image being manipulated by the API. &nbsp;If that happens, try copy pasting the gear icon you're using, and use the pasted version. That should force it to have a thumb url instead of a max or original url. &nbsp;I think there I have a version of Matt's Door Script that fixes that and a few other minor issues... //=========== 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 = "Perc"; statusDoors.attribOpenLocks = "TT"; statusDoors.attribFindTraps = "FT"; statusDoors.attribRemoveTraps = "TT"; statusDoors.hFlipOnOpen = true; &nbsp;// flip switch control horizontally when opened statusDoors.vFlipOnOpen = true; &nbsp;// flip switch control vetically when opened // usePercentageChecks determines how checks against skills are rolled // when true: &nbsp;attribute score + door modifier &gt;= d100 equals success // when false: &nbsp;d20 + attribute score &gt;= door modifier equals success statusDoors.usePercentageChecks = false; 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"; // Clean image source: &nbsp;<a href="https://wiki.roll20.net/API:Cookbook#getCleanImgsrc" rel="nofollow">https://wiki.roll20.net/API:Cookbook#getCleanImgsrc</a> var getCleanImgsrc = function (imgsrc) { &nbsp; &nbsp;"use strict"; &nbsp; &nbsp;var parts = imgsrc.match(/(.*\/images\/.*)(thumb|max)(.*)$/); &nbsp; &nbsp;if(parts) { &nbsp; &nbsp; &nbsp; return parts[1]+'thumb'+parts[3]; &nbsp; &nbsp;} &nbsp; &nbsp;return; }; //=========== constructors ========== //define a door object function DungeonDoorControl() { &nbsp; &nbsp; "use strict"; &nbsp; &nbsp; var thisSwitch, &nbsp; &nbsp; &nbsp; &nbsp; thisDoor, &nbsp; &nbsp; &nbsp; &nbsp; thisWall; &nbsp; &nbsp; this.Load = function (SwitchID) { &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisSwitch = getObj("graphic", SwitchID); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (thisSwitch === undefined){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw "Error loading Switch from id: " + SwitchID; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisDoor = getObj("graphic", state.DoorControls[SwitchID].DoorID); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (thisDoor === undefined){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw "Error loading Door from id: " + SwitchID; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisWall = getObj("path", state.DoorControls[SwitchID].PathID); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (thisWall === undefined){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw "Error loading Wall from id: " + SwitchID; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true; &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log(err); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }; &nbsp; &nbsp; var SetMultiSide = function (side) { &nbsp; &nbsp; &nbsp; &nbsp; thisDoor.set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; currentSide: side, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //imgsrc: decodeURIComponent(thisDoor.get("sides").split("|")[side]).replace(/med\.png/g, "thumb.png"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgsrc: getCleanImgsrc(decodeURIComponent(thisDoor.get("sides").split("|")[side])), &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }; &nbsp; &nbsp; this.Open = function (pc) { &nbsp; &nbsp; &nbsp; &nbsp; //do nothing if door already open &nbsp; &nbsp; &nbsp; &nbsp; if (!this.IsClosed()) return; &nbsp; &nbsp; &nbsp; &nbsp; //trigger trap if armed and not GM &nbsp; &nbsp; &nbsp; &nbsp; if (!pc.IsGM() && SameSide(pc) &&( thisSwitch.get(statusDoors.trapStatus) === statusDoors.trapActive || thisSwitch.get(statusDoors.trapStatus) === statusDoors.trapResets)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var trapNotes = decodeURIComponent(thisSwitch.get("gmnotes")).replace(/PC/g, pc.CharacterSheet().get("name")); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("","/desc TRAP! &nbsp;" + trapNotes); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //record the trap was found &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; state.DoorControls[thisSwitch.get("_id")].TrapFound = true; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //flag trap as triggered if not resetting &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (thisSwitch.get(statusDoors.trapStatus) === statusDoors.trapActive) thisSwitch.set(statusDoors.trapStatus, statusDoors.trapTriggered); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //do not open if locked and not GM &nbsp; &nbsp; &nbsp; &nbsp; if(!pc.IsGM() && SameSide(pc) && thisSwitch.get(statusDoors.lockStatus) === statusDoors.isLocked) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //sendChat("","/desc This door appears to be locked."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("cannot open the door because it is locked."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //set the door controls for open state &nbsp; &nbsp; &nbsp; &nbsp; thisWall.set("layer","gmlayer"); &nbsp; &nbsp; &nbsp; &nbsp; thisSwitch.set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fliph: statusDoors.hFlipOnOpen, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flipv: statusDoors.vFlipOnOpen, &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; SetMultiSide(thisSwitch.get(statusDoors.sideDoorOpen)); &nbsp; &nbsp; &nbsp; &nbsp; if (!pc.IsGM()) pc.Announce("opens the door."); &nbsp; &nbsp; }; &nbsp; &nbsp; this.Close = function (pc) { &nbsp; &nbsp; &nbsp; &nbsp; //do nothing if door already closed &nbsp; &nbsp; &nbsp; &nbsp; if (this.IsClosed()) return; &nbsp; &nbsp; &nbsp; &nbsp; //set the door controls for closed state &nbsp; &nbsp; &nbsp; &nbsp; thisWall.set("layer", "walls"); &nbsp; &nbsp; &nbsp; &nbsp; thisSwitch.set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fliph: false, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; flipv: false, &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; SetMultiSide(thisSwitch.get(statusDoors.sideDoorClosed)); &nbsp; &nbsp; &nbsp; &nbsp; if (!pc.IsGM()) pc.Announce("closes the door."); &nbsp; &nbsp; }; &nbsp; &nbsp; this.PickLock = function(pc) { &nbsp; &nbsp; &nbsp; &nbsp; //do nothing if door is open or is GM &nbsp; &nbsp; &nbsp; &nbsp; if (!this.IsClosed() || pc.IsGM()) return; &nbsp; &nbsp; &nbsp; &nbsp; //do nothing if door is not locked &nbsp; &nbsp; &nbsp; &nbsp; if (thisSwitch.get(statusDoors.lockStatus) !== statusDoors.isLocked || !SameSide(pc)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Whisper(null, "The door does not appear to be locked."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //do nothing if character can't pick locks &nbsp; &nbsp; &nbsp; &nbsp; if(!pc.HasSkill(statusDoors.attribOpenLocks)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("does not possess the skill to unlock this door."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //check if character has attempted to unlock this lock before &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var prevAttempt = state.DoorControls[thisSwitch.get("_id")].UnlockAttempts[pc.CharacterSheet().get("_id")]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (prevAttempt === undefined) throw "character has not seen this lock before"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //respond based on first attempt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (prevAttempt) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("is familiar with this lock, and quickly unlocks it again."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisSwitch.set(statusDoors.lockStatus, statusDoors.isUnlocked); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("continues to fail at picking this lock"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { } &nbsp; &nbsp; &nbsp; &nbsp; //roll the dice &nbsp; &nbsp; &nbsp; &nbsp; var charSkill = pc.SkillLevel(); &nbsp; &nbsp; &nbsp; &nbsp; var lockAdjust = (isNaN(thisSwitch.get(statusDoors.lockQualityAdj))) ? 0 : parseInt(thisSwitch.get(statusDoors.lockQualityAdj)); &nbsp; &nbsp; &nbsp; &nbsp; if (statusDoors.usePercentageChecks) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var rollResult = randomInteger(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var actionSuccess = (Math.min(charSkill + lockAdjust, 95) &gt;= rollResult) ? true : false; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM PICK LOCK: " + charSkill + "% chance with " + lockAdjust + "% lock modifier versus a roll of " + rollResult + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var rollResult = randomInteger(20); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var actionSuccess = (rollResult + charSkill &gt;= lockAdjust) ? true : false; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM PICK LOCK: d20 roll of " + rollResult + " plus skill " + charSkill + " vs DC " + lockAdjust + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //record the results &nbsp; &nbsp; &nbsp; &nbsp; state.DoorControls[thisSwitch.get("_id")].UnlockAttempts[pc.CharacterSheet().get("_id")] = actionSuccess; &nbsp; &nbsp; &nbsp; &nbsp; //announce the results to the party &nbsp; &nbsp; &nbsp; &nbsp; if (actionSuccess) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("has successfully unlocked the door."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisSwitch.set(statusDoors.lockStatus, statusDoors.isUnlocked); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("does not possess the skill to unlock this door."); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }; &nbsp; &nbsp; this.FindTraps = function(pc) { &nbsp; &nbsp; &nbsp; &nbsp; //do nothing if GM &nbsp; &nbsp; &nbsp; &nbsp; if (pc.IsGM()) return; &nbsp; &nbsp; &nbsp; &nbsp; //do nothing if character can't find traps, there is no trap, or on the wrong side &nbsp; &nbsp; &nbsp; &nbsp; if (!pc.HasSkill(statusDoors.attribFindTraps) || thisSwitch.get(statusDoors.trapStatus) === statusDoors.trapNone || !SameSide(pc)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("is confident there are no active traps on this side of the door."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //no need to check if trap has already been found &nbsp; &nbsp; &nbsp; &nbsp; if (state.DoorControls[thisSwitch.get("_id")].TrapFound === true) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("believes a trap has already been found."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //check if this character as attempted to find traps before on this door &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var prevAttempt = state.DoorControls[thisSwitch.get("_id")].TrapFinding[pc.CharacterSheet().get("_id")]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (prevAttempt === undefined) throw "character has not seen this trap before" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //respond based on previous search &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (prevAttempt) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("is familiar with this trap, and quickly identifies it."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("is confident there are no active traps on this side of the door."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { } &nbsp; &nbsp; &nbsp; &nbsp; //roll the dice &nbsp; &nbsp; &nbsp; &nbsp; var charSkill = pc.SkillLevel(); &nbsp; &nbsp; &nbsp; &nbsp; var trapAdjust = (isNaN(thisSwitch.get(statusDoors.trapQualityAdj))) ? 0 : parseInt(thisSwitch.get(statusDoors.trapQualityAdj)); &nbsp; &nbsp; &nbsp; &nbsp; if (statusDoors.usePercentageChecks) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var rollResult = randomInteger(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var actionSuccess = (Math.min(charSkill + trapAdjust, 95) &gt;= rollResult) ? true : false; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM FIND TRAPS: " + charSkill + "% chance with " + trapAdjust + "% trap modifier versus a roll of " + rollResult + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var rollResult = randomInteger(20); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var actionSuccess = (rollResult + charSkill &gt;= trapAdjust) ? true : false; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM FIND TRAPS: d20 roll of " + rollResult + " plus skill " + charSkill + " vs DC " + trapAdjust + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //record the character's results &nbsp; &nbsp; &nbsp; &nbsp; state.DoorControls[thisSwitch.get("_id")].TrapFinding[pc.CharacterSheet().get("_id")] = actionSuccess; &nbsp; &nbsp; &nbsp; &nbsp; //announce the results to the party &nbsp; &nbsp; &nbsp; &nbsp; if (actionSuccess) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("believes there is a trap on this door."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; state.DoorControls[thisSwitch.get("_id")].TrapFound = true; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("is confident there are no active traps on this side of the door."); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }; &nbsp; &nbsp; this.RemoveTrap = function(pc) { &nbsp; &nbsp; &nbsp; &nbsp; //do nothing if GM &nbsp; &nbsp; &nbsp; &nbsp; if (pc.IsGM()) return; &nbsp; &nbsp; &nbsp; &nbsp; //verify trap has been found &nbsp; &nbsp; &nbsp; &nbsp; if (state.DoorControls[thisSwitch.get("_id")].TrapFound !== true) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Whisper(null, "No one has found a trap to remove."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; if (!SameSide(pc)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Whisper(null, "I am on the wrong side of the door to disarm this trap."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //do nothing if character can't remove traps &nbsp; &nbsp; &nbsp; &nbsp; if (!pc.HasSkill(statusDoors.attribRemoveTraps)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("is confident there are no active traps on this door."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //check if this character as attempted to remove trap before on this door &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var prevAttempt = state.DoorControls[thisSwitch.get("_id")].TrapDisarming[pc.CharacterSheet().get("_id")]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (prevAttempt === undefined) throw "character has not tried removing this trap before" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //respond based on previous search &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (prevAttempt) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch(thisSwitch.get(statusDoors.trapStatus)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case statusDoors.trapDisabled: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("believes this trap has already been disarmed."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case statusDoors.trapTriggered: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("believes this trap has already been triggered."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("is familiar with this trap, and disarms it without a problem."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisSwitch.set(statusDoors.trapStatus, statusDoors.trapDisabled); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //always fail if first attempt was failed &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("believes any trap present has been disabled."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { } &nbsp; &nbsp; &nbsp; &nbsp; //do not count as an attempt if trap is not active &nbsp; &nbsp; &nbsp; &nbsp; if (thisSwitch.get(statusDoors.trapStatus) !== statusDoors.trapActive && thisSwitch.get(statusDoors.trapStatus) !== statusDoors.trapResets) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("believes any trap present has been disabled."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //roll the dice &nbsp; &nbsp; &nbsp; &nbsp; var charSkill = pc.SkillLevel(); &nbsp; &nbsp; &nbsp; &nbsp; var trapAdjust = (isNaN(thisSwitch.get(statusDoors.trapQualityAdj))) ? 0 : parseInt(thisSwitch.get(statusDoors.trapQualityAdj)); &nbsp; &nbsp; &nbsp; &nbsp; if (statusDoors.usePercentageChecks) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var rollResult = randomInteger(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var actionSuccess = (Math.min(charSkill + trapAdjust, 95) &gt;= rollResult) ? true : false; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM REMOVE TRAP: " + charSkill + "% chance with " + trapAdjust + "% trap modifier versus a roll of " + rollResult + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var rollResult = randomInteger(20); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var actionSuccess = (rollResult + charSkill &gt;= trapAdjust) ? true : false; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM REMOVE TRAP: d20 roll of " + rollResult + " plus skill " + charSkill + " vs DC " + trapAdjust + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //record the character's results &nbsp; &nbsp; &nbsp; &nbsp; state.DoorControls[thisSwitch.get("_id")].TrapDisarming[pc.CharacterSheet().get("_id")] = actionSuccess; &nbsp; &nbsp; &nbsp; &nbsp; //disarm trap if attempt was successful &nbsp; &nbsp; &nbsp; &nbsp; if (actionSuccess) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisSwitch.set(statusDoors.trapStatus, statusDoors.trapDisabled); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //announce pseudo-results to the party &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("believes any trap present has been disabled."); &nbsp; &nbsp; }; &nbsp; &nbsp; var SameSide = function(pc) { &nbsp; &nbsp; &nbsp; &nbsp; //true if set to both sides &nbsp; &nbsp; &nbsp; &nbsp; if (thisSwitch.get(statusDoors.doorSideActive) === statusDoors.doorSideBoth) return true; &nbsp; &nbsp; &nbsp; &nbsp; //determine angle to door based on rotation &nbsp; &nbsp; &nbsp; &nbsp; 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; &nbsp; &nbsp; &nbsp; &nbsp; var isNorth = (a &gt;= 0 && a &lt;=180) ? true : false; &nbsp; &nbsp; &nbsp; &nbsp; //return true if same side &nbsp; &nbsp; &nbsp; &nbsp; if (isNorth && thisSwitch.get(statusDoors.doorSideActive) === statusDoors.doorSideNorth) return true; &nbsp; &nbsp; &nbsp; &nbsp; if (!isNorth && thisSwitch.get(statusDoors.doorSideActive) === statusDoors.doorSideSouth) return true; &nbsp; &nbsp; &nbsp; &nbsp; return false; &nbsp; &nbsp; }; &nbsp; &nbsp; this.DetectSecret = function(pc) { &nbsp; &nbsp; &nbsp; &nbsp; if (IsPathInRange(pc)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //roll the dice &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var charSkill = pc.SkillLevel(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (statusDoors.usePercentageChecks) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var rollResult = randomInteger(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var actionSuccess = (charSkill &gt;= rollResult) ? true : false; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM DETECTION (" + pc.CharacterSheet().get("name") + "): " + charSkill + "% chance vs roll of " + rollResult + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var rollResult = randomInteger(20); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var actionSuccess = (rollResult + charSkill &gt;= statusDoors.detectHiddenDC) ? true : false; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM DETECTION: d20 roll of " + rollResult + " plus skill " + charSkill + " vs DC " + statusDoors.detectHiddenDC + ": " + ((actionSuccess) ? "SUCCESS" : "FAILED")); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //reveal door if detected &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (actionSuccess) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisSwitch.set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer: "objects", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aura1_radius: statusDoors.doorTypeRevealed, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Announce("has discovered a hidden door."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendPing(thisDoor.get("left"), thisDoor.get("top"), thisDoor.get("_pageid"), null, false); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }; &nbsp; &nbsp; var IsPathInRange = function (pc) { &nbsp; &nbsp; &nbsp; &nbsp; //split lastmove into array &nbsp; &nbsp; &nbsp; &nbsp; var lastmove = pc.MapToken().get("lastmove").split(","); &nbsp; &nbsp; &nbsp; &nbsp; var P1 = {X: pc.MapToken().get("left"), Y: pc.MapToken().get("top")}; &nbsp; &nbsp; &nbsp; &nbsp; var P2 = {X: 0, Y: 0}; &nbsp; &nbsp; &nbsp; &nbsp; var P3 = {X: thisDoor.get("left"), Y: thisDoor.get("top")}; &nbsp; &nbsp; &nbsp; &nbsp; var dX = 0; &nbsp; &nbsp; &nbsp; &nbsp; var dY = 0; &nbsp; &nbsp; &nbsp; &nbsp; var u = 0; &nbsp; &nbsp; &nbsp; &nbsp; var d = 0; &nbsp; &nbsp; &nbsp; &nbsp; //loop for each move segment, stop if ever true &nbsp; &nbsp; &nbsp; &nbsp; for (var i = lastmove.length; i &gt; 0; i -=2) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //read the next point &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; P2 = {X: parseInt(lastmove[i-2]), Y: parseInt(lastmove[i-1])}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log("Segment (" + P1.X + "," + P1.Y + ") and (" + P2.X + "," + P2.Y + ") to point (" + P3.X + "," + P3.Y + ")"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //set up delta values &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dX = P2.X - P1.X; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dY = P2.Y - P1.Y; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u = ((P3.X - P1.X) * dX + (P3.Y - P1.Y) * dY) / (Math.pow(dX, 2) + Math.pow(dY, 2)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //limit resuts to the move segment &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u = ( u &gt; 1) ? 1 : (u &lt; 0) ? 0 : u; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log( " &nbsp;u factor: " + u.toFixed(2)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //calculate distance between segment and point &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d = Math.sqrt(Math.pow(((P1.X + u * dX) - P3.X),2) + Math.pow(((P1.Y + u * dY) - P3.Y),2)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log(" &nbsp;distance: " + d.toFixed(2)); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( d &lt;= statusDoors.detectionRange * 70) return true; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //move P2 to P1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; P1 = {X: P2.X, Y: P2.Y}; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; return false; &nbsp; &nbsp; }; &nbsp; &nbsp; this.IsClosed = function() { &nbsp; &nbsp; &nbsp; &nbsp; return (thisWall.get("layer") === "walls") ? true : false; &nbsp; &nbsp; }; &nbsp; &nbsp; this.OnPage = function() { &nbsp; &nbsp; &nbsp; &nbsp; try { return thisSwitch.get("_pageid") } catch (err) { return undefined; }; &nbsp; &nbsp; }; &nbsp; &nbsp; this.Icon = function() { &nbsp; &nbsp; &nbsp; &nbsp; return thisDoor; &nbsp; &nbsp; }; &nbsp; &nbsp; this.Control = function() { &nbsp; &nbsp; &nbsp; &nbsp; return thisSwitch; &nbsp; &nbsp; }; &nbsp; &nbsp; this.IsLocked = function() { &nbsp; &nbsp; &nbsp; &nbsp;return (thisSwitch.get(statusDoors.lockStatus) === &nbsp;statusDoors.isLocked) ? true : false; &nbsp; &nbsp; }; &nbsp; &nbsp; this.IsTrapped = function() { &nbsp; &nbsp; &nbsp; &nbsp; return (thisSwitch.get(statusDoors.trapStatus) === statusDoors.trapActive || thisSwitch.get(statusDoors.trapStatus) === statusDoors.trapResets) ? true : false; &nbsp; &nbsp; }; &nbsp; &nbsp; this.IsHidden = function() { &nbsp; &nbsp; &nbsp; &nbsp; return (thisSwitch.get(statusDoors.doorType) === statusDoors.doorTypeHidden) ? true : false; &nbsp; &nbsp; }; }; //define a player object function PlayerControl() { &nbsp; &nbsp; var thisAs; &nbsp; &nbsp; var thisCharacter; &nbsp; &nbsp; var thisToken; &nbsp; &nbsp; var roleGM = false; &nbsp; &nbsp; var thisAttrib; &nbsp; &nbsp; this.Load = function (msgWho, pageID, proximityObj) { &nbsp; &nbsp; &nbsp; &nbsp; //set the current speaker &nbsp; &nbsp; &nbsp; &nbsp; thisAs = msgWho; &nbsp; &nbsp; &nbsp; &nbsp; //find a character sheet &nbsp; &nbsp; &nbsp; &nbsp; thisCharacter = findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _type: "character", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: msgWho, &nbsp; &nbsp; &nbsp; &nbsp; })[0]; &nbsp; &nbsp; &nbsp; &nbsp; //determing if running as GM &nbsp; &nbsp; &nbsp; &nbsp; roleGM = (msgWho.indexOf("(GM)") !== -1) ? true : false; &nbsp; &nbsp; &nbsp; &nbsp; //find a token on map if not GM &nbsp; &nbsp; &nbsp; &nbsp; if (thisCharacter) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisToken = _.chain(findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: 'graphic', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageid: pageID, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; represents: thisCharacter.id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; })) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .reduce((m,o)=&gt;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let dist=0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(proximityObj){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dist = Math.pow(o.get("top") - proximityObj.get("top"),2) + Math.pow(o.get("left") - proximityObj.get("left"),2); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(dist&lt;m.dist){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m.pick=o; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return m; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },{pick: null, dist:100000}) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .value().pick; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //clear any previous attributes &nbsp; &nbsp; &nbsp; &nbsp; thisAttrib = undefined; &nbsp; &nbsp; } &nbsp; &nbsp; this.Whisper = function(SendAs, SendMsg) { &nbsp; &nbsp; &nbsp; &nbsp; sendChat((SendAs === null ? thisAs : SendAs), "/w " + thisAs.split(" ")[0] + " " + SendMsg); &nbsp; &nbsp; } &nbsp; &nbsp; this.Announce = function(SendMsg) { &nbsp; &nbsp; &nbsp; &nbsp; sendChat("character|" + thisCharacter.get("_id"), "/em " + SendMsg); &nbsp; &nbsp; } &nbsp; &nbsp; this.InRange = function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; var distance = Math.sqrt(Math.pow(thisToken.get("top") - obj.get("top"),2) + Math.pow(thisToken.get("left") - obj.get("left"),2)); &nbsp; &nbsp; &nbsp; &nbsp; return (distance &gt; statusDoors.interactRange * 70) ? false : true; &nbsp; &nbsp; } &nbsp; &nbsp; this.HasSkill = function(attribName) { &nbsp; &nbsp; &nbsp; &nbsp; thisAttrib = findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _type: "attribute", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _characterid: thisCharacter.get("_id"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: attribName, &nbsp; &nbsp; &nbsp; &nbsp; })[0]; &nbsp; &nbsp; &nbsp; &nbsp; try{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (isNaN(thisAttrib.get("current")) || thisAttrib.get("current") &lt;= 0) throw "character attribute &lt;= 0 or NaN"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true; &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { return false; } &nbsp; &nbsp; } &nbsp; &nbsp; this.SkillLevel = function() { &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return (isNaN(thisAttrib.get("current"))) ? 0 : parseInt(thisAttrib.get("current")); &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { return 0; } &nbsp; &nbsp; } &nbsp; &nbsp; this.IsGM = function() { &nbsp; &nbsp; &nbsp; &nbsp; return roleGM; &nbsp; &nbsp; } &nbsp; &nbsp; this.CharacterSheet = function() { &nbsp; &nbsp; &nbsp; &nbsp; return thisCharacter; &nbsp; &nbsp; } &nbsp; &nbsp; this.MapToken = function() { &nbsp; &nbsp; &nbsp; &nbsp; return thisToken; &nbsp; &nbsp; } &nbsp; &nbsp; this.OnPage = function() { &nbsp; &nbsp; &nbsp; &nbsp; return thisToken.get("_pageid"); &nbsp; &nbsp; } } //=========== events ========== on("chat:message", function (msg) { &nbsp; &nbsp; //handle only player commands &nbsp; &nbsp; var cmdNames = ["!OpenDoor", "!CloseDoor", "!PickLock", "!RemoveTrap", "!FindTraps"]; &nbsp; &nbsp; if (msg.type !== "api" || cmdNames.indexOf(msg.content) === -1) return; &nbsp; &nbsp; //selection must be a single item &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; if (msg.selected.length !== 1) throw "multiple items selected"; &nbsp; &nbsp; } catch (err) { return; } &nbsp; &nbsp; //load the door control &nbsp; &nbsp; var door = new DungeonDoorControl(); &nbsp; &nbsp; if (!door.Load(msg.selected[0]["_id"])) return; &nbsp; &nbsp; //load the player &nbsp; &nbsp; var pc = new PlayerControl(); &nbsp; &nbsp; pc.Load(msg.who, getObj(msg.selected[0]["_type"], msg.selected[0]["_id"]).get("_pageid"), door.Icon()); &nbsp; &nbsp; //do nothing if not playing as a Character or GM &nbsp; &nbsp; if (!pc.CharacterSheet() && !pc.IsGM()) { &nbsp; &nbsp; &nbsp; &nbsp; pc.Whisper("GM","Please set your 'AS' drop option to a character first."); &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; } &nbsp; &nbsp; if (!pc.IsGM()) { &nbsp; &nbsp; &nbsp; &nbsp; //verify character has token on the map &nbsp; &nbsp; &nbsp; &nbsp; if (pc.MapToken() === undefined) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Whisper(null, "I don't have a token on this map."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; //verify character token is close enough to the door &nbsp; &nbsp; &nbsp; &nbsp; if (!pc.InRange(door.Icon())) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pc.Whisper(null, "I am too far from the door to do that."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } &nbsp; &nbsp; switch(msg.content) { &nbsp; &nbsp; &nbsp; &nbsp; case "!OpenDoor": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; door.Open(pc); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!CloseDoor": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; door.Close(pc); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!PickLock": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; door.PickLock(pc); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!RemoveTrap": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; door.RemoveTrap(pc); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!FindTraps": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; door.FindTraps(pc); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; } }); &nbsp;//player chat commands on("chat:message", function (msg) { &nbsp; &nbsp; //handle only GM commands &nbsp; &nbsp; var cmdNames = ["!ObjectList","!DoorsLink","!DoorsResetUse","!DoorsAllOpen","!DoorsAllClose","!DoorsAlign","!DoorsCount","!DoorsDeleteAllLinks","!SideID","!DoorsTableUpdate"]; &nbsp; &nbsp; if (msg.type !== "api" || msg.who.indexOf(" (GM)") === -1 || cmdNames.indexOf(msg.content) === -1) return; &nbsp; &nbsp; var pc = new PlayerControl(); &nbsp; &nbsp; pc.Load(msg.who, null); &nbsp; &nbsp; switch(msg.content.split(" ")[0]) { &nbsp; &nbsp; &nbsp; &nbsp; case "!DoorsLink": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //make sure three items are selected &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (msg.selected.length !== 3) throw "invalid selection"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM Select a graphic named 'Switch', a graphic named 'Door' and a path to use as a wall."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //set up count variables &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var linkSet = {}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; linkSet.SwitchID = []; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; linkSet.PathID = []; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; linkSet.DoorID = []; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //identify each type of selected &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(msg.selected, function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var o = getObj(obj["_type"], obj["_id"]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (o.get("_type") === "graphic" && o.get("name") === "Switch") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; linkSet.SwitchID.push(o); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if (o.get("_type") === "graphic" && o.get("name") === "Door") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; linkSet.DoorID.push(o); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else if (o.get("_type") === "path") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; linkSet.PathID.push(o); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //verify only one of each type role in selection &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (linkSet.SwitchID.length !== 1 || linkSet.DoorID.length !== 1 || linkSet.PathID.length !== 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM Select a graphic named 'Switch', a graphic named 'Door' and a path to use as a wall."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //add the selected as a door &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddSwitchControl(linkSet.SwitchID[0], linkSet.DoorID[0], linkSet.PathID[0]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!DoorsResetUse": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(state.DoorControls, function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.UnlockAttempts = {}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.TrapFinding = {}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.TrapDisarming = {}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.TrapFound = false; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors","/w GM All doors have been reset to 'never been seen' status."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!ObjectList": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(msg.selected, function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log(getObj(obj["_type"], obj["_id"])); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!DoorsAllOpen": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var door = new DungeonDoorControl(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(state.DoorControls, function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;door.Load(obj.SwitchID); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (door.OnPage() === Campaign().get("playerpageid")) door.Open(pc); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!DoorsAllClose": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var door = new DungeonDoorControl(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(state.DoorControls, function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;door.Load(obj.SwitchID); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (door.OnPage() === Campaign().get("playerpageid")) door.Close(pc); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!DoorsAlign": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var door = new DungeonDoorControl(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(state.DoorControls, function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; door.Load(obj.SwitchID); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(door.OnPage() === Campaign().get("playerpageid")) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.Left = door.Icon().get("left"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.Top = door.Icon().get("top"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.Rotation = door.Icon().get("rotation"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.Width = parseInt(door.Icon().get("width") / 4); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;obj.Height = parseInt(door.Icon().get("height") / 4); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; door.Control().set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: obj.Left, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: obj.Top, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rotation: obj.Rotation, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: obj.Width, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: obj.Height, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!DoorsCount": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var iDoors = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var iLocks = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var iTraps = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var iHidden = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var iErrors = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var door = new DungeonDoorControl(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(state.DoorControls, function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (door.Load(obj.SwitchID)) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iDoors++; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (door.IsHidden()) iHidden++; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (door.IsLocked()) iLocks++; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (door.IsTrapped()) iTraps++; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { iErrors++; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors","/w GM Doors:" + iDoors + ", Locked:" + iLocks + ", Trapped:" + iTraps + ", Hidden:" + iHidden); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (iErrors &gt; 0) sendChat("","/w GM There were " + iErrors + " doors that did not load properly."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!DoorsDeleteAllLinks": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(state.DoorControls, function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getObj("graphic", obj.SwitchID).set("layer","objects"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getObj("graphic", obj.DoorID).set("layer","objects"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getObj("path", obj.PathID).set("layer","objects"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; state.DoorControls = {}; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors","/w GM All door links have been deleted from state. &nbsp;No doors will function until relinked with !DoorsLink command."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!SideID": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (msg.selected.length !== 1) throw "selection error"; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var obj = getObj(msg.selected[0]["_type"], msg.selected[0]["_id"]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors", "/w GM SIDEID: obj [" + obj.get("name") + "] is set to side: " + obj.get("currentSide")); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { sendChat ("SIDE", err); } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; &nbsp; &nbsp; case "!DoorsTableUpdate": &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //make sure we have one door image selected &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!msg.selected || msg.selected.length !== 1) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors","/w GM Select a single door graphic"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var newDoor = getObj("graphic", msg.selected[0]["_id"]); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (newDoor.get("name") !== "Door") { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors","/w GM Selected door must be named 'Door'."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //update all doors' 'sides' to selected door's 'sides' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var iErrors = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _.each(state.DoorControls, function(obj) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisDoor = getObj("graphic", obj.DoorID); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; thisDoor.set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //imgsrc: decodeURIComponent(newDoor.get("sides").split("|")[thisDoor.get("currentSide")]).replace(/med\.png/g, "thumb.png"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgsrc: getCleanImgsrc(decodeURIComponent(newDoor.get("sides").split("|")[thisDoor.get("currentSide")])), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sides: newDoor.get("sides"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iErrors++; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log("Error updating door " + obj.DoorID); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //display results of update &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (iErrors === 0) { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors","GM Table images updated sucessfully."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors","Table images updated, but " + iErrors + " error(s) occured."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break; &nbsp; &nbsp; } }); &nbsp;//GM chat commands on("change:graphic", function(obj) { &nbsp; &nbsp; //only reset a valid switch &nbsp; &nbsp; var o = state.DoorControls[obj.get("_id")]; &nbsp; &nbsp; if (!o) return; &nbsp; &nbsp; //keep the switch in place &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; obj.set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: o.Top, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: o.Left, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rotation: o.Rotation, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: o.Width, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: o.Height, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer: (obj.get(statusDoors.doorType) === statusDoors.doorTypeHidden) ? "gmlayer" : "objects", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aura1_color: "transparent", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aura2_color: "transparent", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lastmove: "", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; statusmarkers: "", &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; } catch (err) { } }); //prevents switch movement on("destroy:graphic", function(obj) { &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; var o = state.DoorControls[obj.get("_id")]; &nbsp; &nbsp; &nbsp; &nbsp; if (!o) return ; &nbsp; &nbsp; &nbsp; &nbsp; //move door back to objects layer &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getObj("graphic", o.DoorID).set("layer","objects"); &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { } &nbsp; &nbsp; &nbsp; &nbsp; //move wall back to objects layer &nbsp; &nbsp; &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getObj("path", o.PathID).set("layer","objects"); &nbsp; &nbsp; &nbsp; &nbsp; } catch (err) { } &nbsp; &nbsp; &nbsp; &nbsp; //remove data from state &nbsp; &nbsp; &nbsp; &nbsp; delete state.DoorControls[obj.get("_id")]; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors","/w GM A door control has been deleted. &nbsp;Associated controls have been moved to the objects layer."); &nbsp; &nbsp; } catch (err) { log (err); } }); &nbsp;//remove link in state when switch deleted on("change:graphic", function(obj) { &nbsp; &nbsp; //do nothing if not a character &nbsp; &nbsp; if(obj.get("represents") === "" || state.DoorControls[obj.get("_id")]) return; &nbsp; &nbsp; //check controlledby for character &nbsp; &nbsp; var pcSheet = getObj("character", obj.get("represents")); &nbsp; &nbsp; if (pcSheet.get("controlledby").replace("all","") === "") return; &nbsp; &nbsp; //load the player &nbsp; &nbsp; var pc = new PlayerControl() &nbsp; &nbsp; pc.Load(pcSheet.get("name"), obj.get("_pageid"),obj); &nbsp; &nbsp; //dm cannot detect secret doors &nbsp; &nbsp; if(pc.IsGM()) return; &nbsp; &nbsp; //no proximity check needed if no skill &nbsp; &nbsp; if (!pc.HasSkill(statusDoors.attribFindHidden)) return; &nbsp; &nbsp; //find all secret doors on the same page as the token &nbsp; &nbsp; var secretSwitches = findObjs({ &nbsp; &nbsp; &nbsp; &nbsp; _type: "graphic", &nbsp; &nbsp; &nbsp; &nbsp; _pageid: pc.OnPage(), &nbsp; &nbsp; &nbsp; &nbsp; aura1_radius: statusDoors.doorTypeHidden, &nbsp; &nbsp; }); &nbsp; &nbsp; //check detection for each hidden door &nbsp; &nbsp; var door = new DungeonDoorControl(); &nbsp; &nbsp; _.each(secretSwitches, function(secretSwitch) { &nbsp; &nbsp; &nbsp; &nbsp; if (door.Load(secretSwitch.get("_id"))) door.DetectSecret(pc); &nbsp; &nbsp; }); }); //check movement for proximity to secret doors //=========== functions ========== var AddSwitchControl = function(thisSwitch, thisDoor, thisPath) { &nbsp; &nbsp; //use the switch as a reference ID in state &nbsp; &nbsp; var thisID = thisSwitch.get("_id"); &nbsp; &nbsp; //pair items in state data &nbsp; &nbsp; state.DoorControls[thisID] = ({ &nbsp; &nbsp; &nbsp; &nbsp; SwitchID: thisID, &nbsp; &nbsp; &nbsp; &nbsp; PathID: thisPath.get("_id"), &nbsp; &nbsp; &nbsp; &nbsp; DoorID: thisDoor.get("_id"), &nbsp; &nbsp; &nbsp; &nbsp; Left: thisSwitch.get("left"), &nbsp; &nbsp; &nbsp; &nbsp; Top: thisSwitch.get("top"), &nbsp; &nbsp; &nbsp; &nbsp; Rotation: thisSwitch.get("rotation"), &nbsp; &nbsp; &nbsp; &nbsp; Width: thisSwitch.get("width"), &nbsp; &nbsp; &nbsp; &nbsp; Height: thisSwitch.get("height"), &nbsp; &nbsp; }); &nbsp; &nbsp; //set additional state variables &nbsp; &nbsp; state.DoorControls[thisID].UnlockAttempts = {}; &nbsp; &nbsp; state.DoorControls[thisID].TrapFinding = {}; &nbsp; &nbsp; state.DoorControls[thisID].TrapDisarming = {}; &nbsp; &nbsp; state.DoorControls[thisID].TrapFound = false; &nbsp; &nbsp; //set default values for locks as traps &nbsp; &nbsp; thisSwitch.set({ &nbsp; &nbsp; &nbsp; &nbsp; bar1_value: statusDoors.isUnlocked, &nbsp; &nbsp; &nbsp; &nbsp; bar1_max: "0", &nbsp; &nbsp; &nbsp; &nbsp; bar2_value: statusDoors.trapNone, &nbsp; &nbsp; &nbsp; &nbsp; bar2_max: "0", &nbsp; &nbsp; &nbsp; &nbsp; aura1_radius: statusDoors.doorTypeVisible, &nbsp; &nbsp; &nbsp; &nbsp; aura1_color: "transparent", &nbsp; &nbsp; &nbsp; &nbsp; aura2_radius: statusDoors.doorSideBoth, &nbsp; &nbsp; &nbsp; &nbsp; aura2_color: "transparent", &nbsp; &nbsp; &nbsp; &nbsp; gmnotes: "PC has triggered a trap.", &nbsp; &nbsp; }); &nbsp; &nbsp; //format the switch to default role settings &nbsp; &nbsp; thisSwitch.set({ &nbsp; &nbsp; &nbsp; &nbsp; layer: "objects", &nbsp; &nbsp; &nbsp; &nbsp; isdrawing: true, &nbsp; &nbsp; &nbsp; &nbsp; showplayers_name: false, &nbsp; &nbsp; &nbsp; &nbsp; showplayers_bar1: false, &nbsp; &nbsp; &nbsp; &nbsp; showplayers_bar2: false, &nbsp; &nbsp; &nbsp; &nbsp; showplayers_bar3: false, &nbsp; &nbsp; &nbsp; &nbsp; showplayers_aura1: false, &nbsp; &nbsp; &nbsp; &nbsp; showplayers_aura2: false, &nbsp; &nbsp; &nbsp; &nbsp; playersedit_name: false, &nbsp; &nbsp; &nbsp; &nbsp; playersedit_bar1: false, &nbsp; &nbsp; &nbsp; &nbsp; playersedit_bar2: false, &nbsp; &nbsp; &nbsp; &nbsp; playersedit_bar3: false, &nbsp; &nbsp; &nbsp; &nbsp; playersedit_aura1: false, &nbsp; &nbsp; &nbsp; &nbsp; playersedit_aura2: false, &nbsp; &nbsp; &nbsp; &nbsp; controlledby: "all", &nbsp; &nbsp; }); &nbsp; &nbsp; //move the door graphic to the map layer &nbsp; &nbsp; thisDoor.set({ &nbsp; &nbsp; &nbsp; &nbsp; layer: "map", &nbsp; &nbsp; }) &nbsp; &nbsp; //move the lighting path to the walls layer &nbsp; &nbsp; thisPath.set({ &nbsp; &nbsp; &nbsp; &nbsp; layer: "walls", &nbsp; &nbsp; &nbsp; &nbsp; stroke: statusDoors.DoorPathColor, &nbsp; &nbsp; &nbsp; &nbsp; stroke_width: 5, &nbsp; &nbsp; &nbsp; &nbsp; fill: "transparent", &nbsp; &nbsp; }); &nbsp; &nbsp; try { &nbsp; &nbsp; &nbsp; &nbsp; var door = new DungeonDoorControl(); &nbsp; &nbsp; &nbsp; &nbsp; if (!door.Load(thisID)) throw "could not load new door"; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("Doors","/w GM Door has been successfully linked. ID:" + thisID); &nbsp; &nbsp; } catch (err) { sendChat ("Doors", "/w GM ERROR: " + err); } } //adds trio as a door control //=========== non-essential ========== on("chat:message", function(msg) { &nbsp; &nbsp; cmdName = "!CleanUp"; &nbsp; &nbsp; if (msg.type !== "api" || msg.content.indexOf(cmdName) === -1) return; &nbsp; &nbsp; _.each(findObjs({ _type: "graphic", name: "Switch"}), function(o) { &nbsp; &nbsp; &nbsp; &nbsp; o.set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer: "gmlayer", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 140, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 140, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: 70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: 70, &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }); &nbsp; &nbsp; _.each(findObjs({ _type: "graphic", name: "Door"}), function(o) { &nbsp; &nbsp; &nbsp; &nbsp; o.set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer: "gmlayer", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 140, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 140, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: 70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: 70, &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }); &nbsp; &nbsp; _.each(findObjs({ _type: "path", stroke: statusDoors.DoorPathColor, stroke_width: 5, fill: "transparent"}), function(o) { &nbsp; &nbsp; &nbsp; &nbsp; o.set({ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer: "gmlayer", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: 70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left: 70, &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; }); });
Hmm. When I use the script you just pasted, I get&nbsp; TypeError: Cannot read property 'substring' of undefined TypeError: Cannot read property 'substring' of undefined at TrackedObj._validateAttrs (/home/node/d20-api-server/api.js:787:21) at TrackedObj.set (/home/node/d20-api-server/api.js:858:18) at SetMultiSide (apiscript.js:20036:18) at DungeonDoorControl.Open (apiscript.js:20081:9) at apiscript.js:20638:18 at eval (eval at (/home/node/d20-api-server/api.js:146:1), :65:16) at Object.publish (eval at (/home/node/d20-api-server/api.js:146:1), :70:8) at /home/node/d20-api-server/api.js:1510:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) The door images I"m using only exist in my Library- they aren't from the marketplace. I uploaded them, clicked 'add to library' , and this is where I dragged them from. Just did it again. &nbsp;I am also copy/pasting the gear, but still getting the thumbs message. &nbsp;THe SideID on the token does not change. This isn't *crucial* - its cosmetic - the yellow line allowing/blocking vision on the dynamic lighting layer is working. its just.. weird. (I"m no programmer, so I will happily admit to blindly following instructions. I just can't figure out why this is giving me so much grief. I did see a post about png vs jpg problems - also one you posted in - so I made sure I uploaded my files as png, but.. still having weirdness)
1494251181
The Aaron
Pro
API Scripter
If you want to PM me a join link and GM me, I'll be happy to come take a look and try to solve it.
If its any consolation ... I am experiencing the EXACT same issue the OP is having. My 'Switch' is a random icon from the market place. My 'Door' icon has been saved to my drive, and uploaded back into my library (for both opened and closed icons). My roll table (named Door) has the Open Door at 0 and Closed Door at 1. My Switch token has Bar3 set up as 1/0 I place my closed door token on the map, draw my path, place my Switch token on top and then I highlight the group. I run the DoorsLink command, which works, and then test the OpenDoor/CloseDoor function. &nbsp;It opens and closes fine, however, the door icon does not change and when i run the SideID command the open/close are both labeled as side 0. I figured I was doing something wrong so I have deleted the links on that set and attempted it, 3 times, with the same results. &nbsp;I then created a whole new door setup and am getting identical results. I did just notice that the error is in my API panel as well "ERROR: Please use the 'thumb' size for imgsrc properties." I do agree with the OP in that this probably shouldnt aggravate me NEARLY as much as it is lol.
1494276361
The Aaron
Pro
API Scripter
Grab the version I uploaded here: &nbsp; <a href="https://app.roll20.net/forum/post/5019325/script-u" rel="nofollow">https://app.roll20.net/forum/post/5019325/script-u</a>... It should give you much better feedback about what the issue is. &nbsp;Probably you need to put the indexes of the door in &nbsp;bar3's current and max field for the switch. &nbsp;This should also handle the thumb error.