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

possible to change attributes via a command?

I assume it would be possible to change attributes via a command? Have been looking into a quick method of monster generation on the go so was wondering if it was possible to do something such as ! Generate 15 14 13 etc for say defenses such as fort ref will
February 06 (11 years ago)

Edited February 06 (11 years ago)
DXWarlock
Sheet Author
API Scripter
Are the tokens already connected to a sheet with the stats on them, and you just need to set the stats?
For the creatures to have stats, they would need a character sheet they are assigned to with the stats. But then any of those creatures would also have those same stats when you drag a token from that sheet (or ones already placed will update also to the new stats since they are linked to the sheet too)

or do you mean random tokens and setting the 3 bars to those values?
February 06 (11 years ago)

Edited February 06 (11 years ago)
Yes effectively a sheet would have the corresponding attributes ready.

the idea is to grab a token from the net. Drop it in and assign it a sheet and then quickly use a command to assign it a value for defenses, hp etc.


So just setting the stats
Possibly aswell as setting values to bars aswell.

the idea is to create monsters on the go quickly without having to open the sheet up and assigning values to bars.
February 06 (11 years ago)

Edited February 06 (11 years ago)
DXWarlock
Sheet Author
API Scripter
I can work something out I think.
I know I can do it all other than auto linking the bars on the tokens to the right attribute. I cant seem to find anything to do that, bar1_link returns the player its linked to, but not the attribute. so obj.set I dont think would work. I can read the bar min/max, set the bar min/max, if players can see the bar, if they can edit the bar..but not tell it to use 'x' attribute. maybe someone else can fill in that part if Im just missing the callback to do it.

Ill see what i can make to set the attributes of a token and its assigned sheet using !something 1 2 3. I'm 1/2 working and 1/2 browsing the forum so give me a bit, but Ill reply with something for you in a bit :)

Tbh just setting the bars is fine in the long run. It was just for rapid generation.

Ah thank you kind sir. If I had something to start im sure I could manage the rest :)!! ( me too. At work and browsing xD)
February 06 (11 years ago)

Edited February 06 (11 years ago)
DXWarlock
Sheet Author
API Scripter
This should do it, long as the token has a sheet with those attributes on it, it will update them. if it doesn't have all 3 attributes it stops (vs adding them, wouldnt want to randomly add them to a character you didnt want by accident..this way it just does nothing if its missing)
you can even select more than one token and set it on them all, it will loop all selected tokens and set the values.

just rename the Atta, Attb, and Attc to the Attribute names you want it to look for.
doing !Set 10 20 30 will set them to 10,20,30 current and max for the 3, in that order.

So like below you get
fort;10/10
ref:20/20
will:30/30

on('chat:message', function (msg) {
    var CmdName = '!Set '
    if(msg.type == 'api' && msg.content.indexOf(CmdName) !== -1) {
        //Set Attrib names---
        var Atta = 'fort';
        var Attb = 'ref';
        var Attc = 'will';
        //--------------------
	var selected = msg.selected;
        var msgTxt = msg.content;
        var msgFormula = msgTxt.split(" ");
	i = 0;
	_.each(selected, function (obj) {
		var token = getObj('graphic', msg.selected[i]._id);
		//---make sure its a token, and has a sheet---
		if(token.get("represents") != '') {
		if(token.get('subtype') != 'token') return;
		var oCharacter = getObj('character', token.get("_represents"));
		//----------------------------------------
		var oAtt1 = findObjs({_type: "attribute",name: Atta,_characterid: oCharacter.id})[0];
                var oAtt2 = findObjs({_type: "attribute",name: Attb,_characterid: oCharacter.id})[0];
                var oAtt3 = findObjs({_type: "attribute",name: Attc,_characterid: oCharacter.id})[0];
                if(oAtt1 == undefined || oAtt2 == undefined || oAtt3 == undefined){
                    log('Token has no Attributes on its sheet');
                    return;
                }
		oAtt1.set('current', msgFormula[1]);
                oAtt1.set('max', msgFormula[1]);
                oAtt2.set('current', msgFormula[2]);
                oAtt2.set('max', msgFormula[2]);
                oAtt3.set('current', msgFormula[3]);
                oAtt3.set('max', msgFormula[3]);
		}
	i++
	});
    }
});


February 06 (11 years ago)

Edited February 06 (11 years ago)
DXWarlock
Sheet Author
API Scripter
Actually here a shorter and cleaner way to do by just repeating the same lookup with different variables, vs above of doing each one itself over and over. Once I was done, it hit me :P
this way you can add more attributes if you want just by adding them to the top..and making the commands longer like !Set 10 20 30 40

var CONFIG = [{Att: 'fort'}, {Att: 'ref'}, {Att: 'will'}];

on('chat:message', function (msg) {
  var CmdName = '!Set '
  if(msg.type == 'api' && msg.content.indexOf(CmdName) !== -1) {
    var selected = msg.selected;
    var msgTxt = msg.content;
    var msgFormula = msgTxt.split(" ");
    i = 0;
    _.each(selected, function (obj) {
      var token = getObj('graphic', msg.selected[i]._id);
      //---make sure its a token, and has a sheet---
      if(token.get("represents") != '') {
        if(token.get('subtype') != 'token') return;
        var oCharacter = getObj('character', token.get("_represents"));
        //----------------------------------------
        var ii = 1
        CONFIG.forEach(function (opts) {
          var setA = parseInt(msgFormula[ii]);
          var oAtt1 = findObjs({_type: "attribute",name: opts.Att,_characterid: oCharacter.id})[0];
          if(oAtt1 == undefined) {log('Token is missing Attribute on its sheet');return;}
          oAtt1.set('current', setA);
          oAtt1.set('max', setA);
          ii++
        });
      }
      i++
    });
  }
});
February 06 (11 years ago)

Edited February 06 (11 years ago)
You sir. Are a king amongst kings. I am eternally grateful. :) Id use it in conjunction with the another 4e script
You sir. Are a king amongst kings. I am eternally grateful. :) Id use it in conjunction with the another 4e script for creating tokens rapidly.

using mythic emulator with adventures to
February 06 (11 years ago)
DXWarlock
Sheet Author
API Scripter
No problem let me know if it has any problems, I only tested it with a couple tokens..and without selecting anything to make sure it didn't error out.
February 10 (11 years ago)
I like this idea.. it would make creating sheets much easier. I have a sheet generation script that I use and this would be very useful to autofill newly created sheets. I'm wondering if there is a way to modify this to be able to adjust attributes when a power is used.. say a cleric uses healing word and has the feat that gives the target a bonus to all defenses against the next attack made against it.. so if it gives the target a +2, have a code in the macro that increases AC, Fort, Reflex, and Will by 2 (and have a macro for the GM to be able to adjust back to normal when the effect runs out if it's not possible to automate that).. Is something like that possible?
That sheet is perfect. Tbh the only thing I really need thats left is a script that adds powers via prompts. So it goes through the list and creates it as token button etc
February 10 (11 years ago)

Edited February 10 (11 years ago)
You can probably add them to the script for that sheet generation.. just change 'attribute' to 'ability'.. then you can have the name in there. As far as how to add any other things like macros and whether it is checked as a token action.. that is beyond me. I'm sure you can just add in a set number of abilities and then just enter them from there.

Edit:
All the resistances are designed to work with this script
Hmmm fair enough. I can work with that :)