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 .
×

[Script] Set light for selected Token

Hello fellow roll20's! I really like roll20 and its functions, so i decided to learn a little java and write my first script. The Target for the script is: -when the "!activate" command comes in the chat, then the script should set the light radius of the selected token (by the player who sent "!activate") -ideally, the script should also remove the light radius, when the !deactivate command comes in the chat window. I am currently having some problems with the command to get the currently controlled token of the player. I took the "Light Switch" Script by Melvin McSnatch code as basis for my script. But currently i'm stuck. Could Someone please give me a hint? var lights = function(radius,dim) { var light1 = GetCurrentToken(); light1.set("light_radius", radius); light1.set("light_dimradius", dim); }; on("chat:message", function(msg) { if(msg.type == "api" && msg.content.indexOf("!activate") !== -1) { lights(100,100);};}); on("chat:message", function(msg) { if(msg.type == "api" && msg.content.indexOf("!activate") !== -1) { lights(0,0);};});
1380359906

Edited 1380359917
Use this instead: var Token = getObj("graphic", msg.selected[0]._id); That will get you the selected token.
1380361812
Lithl
Pro
Sheet Author
API Scripter
function lights(tok, on) { if(on) { tok.set('light_radius', 100); } else { tok.set('light_radius', ''); } } on('chat:message', function(msg) { if(!(msg.selected && msg.selected.length > 0)) return; // Make sure there's a selected object var token = getObj('graphic', msg.selected[0]._id); if(token.get('subtype') != 'token') return; // Don't try to set the light radius of a drawing or card if(msg.type == 'api' && msg.content.indexOf('!activate') !== -1) { lights(token, true); } else if(msg.type == 'api' && msg.content.indexOf('!deactivate') !== -1) { lights(token, false); } }); To actually turn off the light radius, you should probably set the radius to the empty string, the same as deleting the value in the box through the UI. Also, you only need to set the dimradius if you care about having different values. You only need one instance of on('chat:message',...) to get your script to work; just use multiple if blocks to work out different commands.
Thanks alot for your help. The Skript is running just fine. I already have some further ideas for this script. ;)