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] set weapon values using the API

currently set to three attack types, it will allow you to type an API command string and then set the values of the three(or more - working on expanding the script so it IS a work in progress) attack attributes associated with that attack option. the three types of attack and their attributes are currently: Melee: MeleeWeapon MeleeAttack MeleeDamage Off-Hand Weapon: MeleeOffWeapon MeleeOffAttack MeleeOffDamage Ranged Weapon: RangedWeapon RangedAttack RangedDamage these have to be set into your character sheet attributes (though I am planning on making a customisable set of variables in the future) The command Line for this script is simple enough.&nbsp; !Equip &lt;characters name&gt; &lt;attack type&gt; &lt;weapons name&gt; &lt;weapon attack bonus&gt; &lt;weapons damage string&gt; characters name = the name of the character you wish to equip the weapon to, as on the character sheet (names with spaces in them will break the script, so take care till I figure something out for that) attack type = the type of attack it is - at the moment - restricted to melee (main hand weapon), offhand (your offhand weapon), and ranged (your ranged attack) weapons name &nbsp;= the name of the weapon you are equipping (whatever you want to call it, again, so long as their are no spaces in the name) weapon attack bonus &nbsp;= the value that is added to your macro for attacking with that weapon. weapon damage string = the string that will be added to damage each time you roll your attack (for example, a +2 longsword in the hands of a specialist might be 1d8+4 (1d8+2 from the sword, + 2 points from weapon specialization. if the sword also did 1d6 fire damage, then is would be set to 1d8+4+1d6 - bear in mind that on my sheets the macros for attack calculate the bonuses from high or low strength and BAB of an attack separately, so bonuses tend to be very specific to each attack depending on feats, special weapon stats, or some other non-standard value) &lt;script src="<a href="https://gist.github.com/Fantell/5832743.js&quot;&gt;&lt;/script" rel="nofollow">https://gist.github.com/Fantell/5832743.js"&gt;&lt;/script</a>&gt;
Ok, some pointers and suggestions.&nbsp; &nbsp; First, when doing a test in an if statement, you need a double equals "==" to do the test. A single "=" is changing the value of the left hand variable. So none of your if statements will work properly. I.E you have: (type = "ranged") And you should have: (type == "ranged") The second thing is that, I have tried to store text in attributes and it has failed for me every time. I think it is an integer storage only. That said, you might want to think about storing them in "state". "state" is a persisting data storage set up a couple updates ago that persists even when people are not in the game, so if you store a value in it (for instance, you could create state.weapons, make it an array with the following values: id: //the id of the character holding it attackValue: //the macro for determining the attack bonus (using the relevant attributes) attackDamage: //the macro text for the damage attackType: //the type of attack it is (melee/ranged/etc) By making it an array, you can have it hold far more than you need, and you can have multiples per character without tying up attributes.
thank you. learning all this as I go. Much appreciated
and yes, I know, Arrays work much better, But those are something I'm still iffy on. I was planning on having it update on the character sheet itself both as storage and so players could see what they had equipped without having to do anything extra. &nbsp; Also like to point out that the stats, both names and numbers, go through to the right place, they just go through to EVERY character sheet and overwrite what is there. Would like to know how to define character.id in relation to THIS script and making the stast go to only the target character sheet.
Guess that means you can store texts in attributes, and change them using the API - I CAN get that effect, just not in the right places, and thats my failing in id'ing the character sheet by .id
btw, this script goes hand in hand with my 3.5 character sheet auto generator. I plan on doing the same thing as here with armor bonuses as well, calculating touch, flootfooted and total AC from the numbers inputted on the sheet.&nbsp;
as of right now I have the script changing the value of all my attributes correctly, except for one thing it changes the current value of every sheet instead of just the one i want it to.&nbsp; I know this is because I have failed to properly identify the attributes _characterid and that is what I would like help with now.&nbsp; how would I set a variable to a single character sheets attribute? can already get it to update on ALL sheets with the right name. just need to narrow it down to the one i choose.&nbsp;
Ok, on each of your findObjs() add a line: _id: targetMatched.id, This will limit it to your target character. I would also add an insentitive to the targetMatch findObj, because sometimes casing can be an issue with character names.
Also, to make it easier on you, I simplified your command code: var cleanedMsg = msg.content.replace(equipCmd, ""); var charName = cleanedMsg.split(" ")[0]; var type = cleanedMsg.split(" ")[1]; var weaponName = cleanedMsg.split(" ")[2]; var weaponAttackBonus = cleanedMsg.split(" ")[3]; var weaponDamage = cleanedMsg.split(" ")[4]; var weaponBonusDamage = cleanedMsg.split(" ")[5]; var weaponBonusType = cleanedMsg.split(" ")[6]; log(charName + "'s " + type + " weapon, a " + weaponName + " with a " + weaponAttackBonus + " for attack, " + weaponDamage + " damage, with " + weaponBonusDamage + " " + weaponBonusType + " damage." ) You don't have to keep editing the original file. Once you split the command into an array (split() command), you can just scroll through the elements as I noted above. The simpler your code, the easier to figure out problems or make changes later. ;)
Thats what I thought it would do too - but it doesnt. just crashes with unexpected identifier.... i'm doing something wrong but I don't know what
Perhaps you need to save it as an array first var cleanedMsg = msg.content.replace(equipCmd, "").split(" "); var charName = cleanedMsg[0]; var type = cleanedMsg[1]; var weaponName = cleanedMsg[2]; var weaponAttackBonus = cleanedMsg[3]; var weaponDamage = cleanedMsg[4]; var weaponBonusDamage = cleanedMsg[5]; var weaponBonusType = cleanedMsg[6]; log(charName + "'s " + type + " weapon, a " + weaponName + " with a " + weaponAttackBonus + " for attack, " + weaponDamage + " damage, with " + weaponBonusDamage + " " + weaponBonusType + " damage." )
Ok that gets rid of the unidentified intentifier but still having issues with actually getting the stats to change still. I can write values to all the identified attributes but fail to single out the sheet using even a direct copy of your currchar value from your auto init script
Perhaps you would like to join my test campaign and have a look there? I can set that up tonight when I get home from work Its wherive been playing with your Initiative script trying to break it so you can see what happens fhere too
I did an update and it worked great. Here is the code I used (I added the char code, and I fixed your searches: <a href="https://gist.github.com/DarokinB/5864579" rel="nofollow">https://gist.github.com/DarokinB/5864579</a> A couple notes, first with findObjs(), you need to have them in order as they are on the wiki. Meaning, name is first, type is last, etc... if your order is incorrect, it will not work.&nbsp; I also added the character id search. You were treating the targetMatched as a token by asking for get("represents"), which you should not do with characters. Their id is their character id.&nbsp;
1372224478
Alex L.
Pro
Sheet Author
You should really be checking the length of cleanedMsg, you should never trust user input. Also I am fairly sure findObjs() has no order requirements what so ever. Also you shouldn't use each to deal with findObjs results, you should check if there is more or less than one result and throw an error if there is.
thank you, but i'm leaving it open ended for now, because planning on adding more effects to it, and i'm the one who writes the macros to equip weapons for now - that will change as my players are more confident in using api commands, but until then its a work in progress anyway.&nbsp; not sure what you mean by your second statement there though - its the only way I know how to do it.&nbsp;
btw, awesome work Josh, I am eternally grateful for the fix there, and now I can see where I was going wrong, I can addapt it to fit the other scripts i am planning on working into my character sheet management&nbsp;
Alex, I understand that it isn't supposed to require them in a specific order of the criteria, but in many of my scripts that have failed, when I reordered them to match the wiki order, they worked fine. I don't know why that is but it does. No problem Michael. Actually this has inspired me to make a class based system for my DnD Next campaign. I want to see how it works out but it could be very cool. I'll keep you posted.
My next project is armor classes and returning values on command based on the individual stats you have - partly so my players can see stacking armor in action. Will be a cintuation of this script and command style. Only wuth armor. Probably.&nbsp;