3darkman

Changing images for tokens on FoundryVTT

Apr 19th, 2021
600
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // array with all images for the token
  2. let shapes = [
  3.   {
  4.      img: 'Tokens/human/archers/119798-M_Human_Archer.png',
  5.      height: 1,
  6.      width: 1
  7.   },
  8.   {
  9.      img: 'Tokens/human/archers/Human_M_Armored_Archer_hi.png',
  10.      height: 2,
  11.      width: 2
  12.   },
  13.   {
  14.     img: 'Tokens/human/archers/Human_Male_Archer3_02_hi.png',
  15.     height: 2,
  16.     width: 1
  17.   },
  18.   // you can add more shapes here, following the pattern above.
  19. ];
  20.  
  21. let index = 0;
  22. let tok = canvas.tokens.controlled[0];
  23.  
  24. // check which is the current image
  25. shapes.some(shape => {
  26.   if (tok.data.img == shape.img) {
  27.     return true;
  28.   }  
  29.   index++;
  30.   return false;
  31. });
  32.  
  33. // defines what will be the next image in the array
  34. if (index >= shapes.length - 1) {
  35.   index = 0;
  36. } else {
  37.   index++;
  38. }
  39.  
  40. // updates the token
  41. tok.update({img: shapes[index].img, height: shapes[index].height, width: shapes[index].width});
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×