Rvby1

Synchronize Ferocity Between Companion and Beastheart

Apr 28th, 2022 (edited)
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. function getActorByName(actorName)
  2. {
  3. let actor = canvas.tokens.placeables.find(p => p.data.name === actorName)?.actor;
  4. if (!actor) actor = game.actors.entities.find(e => e.name === actorName);
  5. return actor;
  6. }
  7.  
  8. let beastheartName = "REPLACE_beastheartActorName";
  9. let companionName = "REPLACE_companionActorName";
  10.  
  11. let beastheart = getActorByName(beastheartName);
  12. let companion = getActorByName(companionName);
  13.  
  14. let companionFerocity = companion.data.data.resources.primary.value;
  15.  
  16. let beastheartFerocity = beastheart.data.data.resources.primary.value;
  17.  
  18. let log = "";
  19.  
  20. if(companionFerocity == beastheartFerocity)
  21. {
  22. log = `${beastheartName} and ${companionName}'s ferocity values are the same, so did nothing.`;
  23. }
  24. else if(companionFerocity > beastheartFerocity)
  25. {
  26. await beastheart.update({"data.resources.primary.value": companionFerocity});
  27. log = `Set ${beastheartName}'s ferocity to ${companionName}'s ferocity value of ${companionFerocity}.`;
  28. }
  29. else
  30. {
  31. await companion.update({"data.resources.primary.value": beastheartFerocity});
  32. log = `Set ${companionName}'s ferocity to ${beastheartName}'s ferocity value of ${companionFerocity}.`;
  33. }
  34.  
  35. ChatMessage.create({
  36. user: game.user._id,
  37. speaker: ChatMessage.getSpeaker({token: actor}),
  38. content: log
  39. });
Add Comment
Please, Sign In to add comment