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

Trying to Build a Mirror Image Mod

So, I'm trying to build a Mod that will spawn duplicate images of a Wizard when using the Mirror image Spell... and THEN if those images continue to exist when the Wizard in question moves, the duplicate images automatically reposition next to him. So far, I've gotten creation of the duplicate images to work just fine... but I cant seem to get the second part to work.&nbsp; I've tried to reference what materials are available on the Wiki - considering I know basically nothing of JavaScript and am having to trial-and-error my way through finding stuff that's been previously posted and appropriate it for my own uses... The script seems to load fine, and isnt throwing me error messages anymore, but just - doesnt DO anything when the appropriate token moves. Here what I've got: &nbsp;on("ready",function() { &nbsp; &nbsp; on("chat:message",function(msg){ &nbsp; &nbsp; &nbsp; &nbsp; if(msg.type=="api" &amp;&amp; msg.content.indexOf("!MirrorImage")==0) &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var selected = msg.selected; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (selected===undefined) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat("API","Please select a character."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var PCtoken = getObj("graphic",selected[0]._id); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var character = getObj("character",PCtoken.get("represents")); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var playerlist = character.get("controlledby") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createObj("graphic",{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left:PCtoken.get("left")-70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:PCtoken.get("top"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height:70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageid:PCtoken.get("pageid"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer:"objects", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgsrc:"<a href="https://s3.amazonaws.com/files.d20.io/images/294888802/RXdKTBjdjj48-HM_Sq46Yg/thumb.png?165802533255" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/294888802/RXdKTBjdjj48-HM_Sq46Yg/thumb.png?165802533255</a>", name:PCtoken.get("name") + "'s First Mirror Image", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; controlledby:playerlist, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createObj("graphic",{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left:PCtoken.get("left"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:PCtoken.get("top")-70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height:70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageid:PCtoken.get("pageid"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer:"objects", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgsrc:"<a href="https://s3.amazonaws.com/files.d20.io/images/294888802/RXdKTBjdjj48-HM_Sq46Yg/thumb.png?165802533255" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/294888802/RXdKTBjdjj48-HM_Sq46Yg/thumb.png?165802533255</a>", name:PCtoken.get("name") + "'s Second Mirror Image", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; controlledby:playerlist, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); createObj("graphic",{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left:PCtoken.get("left")+70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:PCtoken.get("top"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height:70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width:70, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageid:PCtoken.get("pageid"), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; layer:"objects", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgsrc:"<a href="https://s3.amazonaws.com/files.d20.io/images/294888802/RXdKTBjdjj48-HM_Sq46Yg/thumb.png?165802533255" rel="nofollow">https://s3.amazonaws.com/files.d20.io/images/294888802/RXdKTBjdjj48-HM_Sq46Yg/thumb.png?165802533255</a>", name:PCtoken.get("name") + "'s Third Mirror Image", &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; controlledby:playerlist, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp;&nbsp;&nbsp;&nbsp;sendChat(PCtoken.get("name"),"creates several illusions of himself."); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spawnFx(PCtoken.get("left"),PCtoken.get("top"),"burst-magic",PCtoken.get("pageid")); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; }); on("change.graphic", function(obj)&nbsp; { if(obj.type=="graphic" &amp;&amp; obj.get("character")==="Martin") { var PCToken = getObj("graphic",selected._id); if(findObjs({_type:"graphic", name:"Martin's First Mirror Image"})) { var FirstImage = findObjs({_type:"graphic", name:"Martin's First Mirror Image"}); } else { var FirstImage = 0; } if(findObjs({_type:"graphic", name:"Martin's Second Mirror Image"})) { var SecondImage = findObjs({_type:"graphic", name:"Martin's Second Mirror Image"}); } else { var SecondImage = 0; } if(findObjs({_type:"graphic", name:"Martin's Third Mirror Image"})) { &nbsp; &nbsp; var ThirdImage = findObjs({_type:"graphic", name:"Martin's Third Mirror Image"}); } else&nbsp; { var ThirdImage = 0; } if(FirstImage !== 0) { FirstImage.set("left", PCToken.get("left")-70); FirstImage.set("top", PCToken.get("top")); } if(SecondImage !== 0) { SecondImage.set("left", PCToken.get("left")); SecondImage.set("top", PCToken.get("top")-70); } if(ThirdImage !== 0) { ThirdImage.set("left", PCToken.get("left")+70); ThirdImage.set("top", PCToken.get("top")); } } &nbsp; &nbsp; }); });
You will probably want to look at the Spawn or ItsATrap scripts for ideas on generating tokens.&nbsp; However, if you also want to be RAW/pedantic, the mirror image &nbsp;spell shouldn’t be generating new tokens in adjacent spaces. I would suggest using a status marker instead: Three illusory duplicates of yourself appear in your space . Until the spell ends, the duplicates move with you and mimic your actions, shifting position so it's impossible to track which image is real.&nbsp; I think of mirror image appearing more like the agents in The Matrix than actual duplicates of a character&nbsp;
1658611319

Edited 1658611392
Jarren said: You will probably want to look at the Spawn or ItsATrap scripts for ideas on generating tokens.&nbsp; However, if you also want to be RAW/pedantic, the mirror image &nbsp;spell shouldn’t be generating new tokens in adjacent spaces. I would suggest using a status marker instead: Three illusory duplicates of yourself appear in your space . Until the spell ends, the duplicates move with you and mimic your actions, shifting position so it's impossible to track which image is real.&nbsp; I think of mirror image appearing more like the agents in The Matrix than actual duplicates of a character&nbsp; Aaaahhhh.... well... that's a good point --- that CLEARLY I didnt realize (lawlz) This is what I get for trying to run D&amp;D for the first time ever... Multi-Sided Token it is!
1658613694

Edited 1658614015
David M.
Pro
API Scripter
You may also want to check out keithcurtis' mirror image macro set . It is older and set up for the 5eshaped sheet, but the method should be sound and easily converted to another template. You could even easily add a currentside|# command to the token-mod lines if you were so inclined. EDIT - looks like somebody translated it for the 5e by Roll20 sheet here .