View Single Post
Aaron
Senior Member
Lone Wolf Staff
 
Join Date: Oct 2011
Posts: 6,776

Old August 4th, 2017, 05:46 PM
Ask and you shall receive!

Code:
    <portal
      id="additem"
      style="actBig"
      tiptext="Click to add a random personality trait.">
      <action
        action="trigger">
        <trigger><![CDATA[
          var thingid as string
          var tagexpr as string

          ~Stop if we have no background
          if (hero.tagis[Background.?] = 0) then
            notify "You must select a background first!"
            done
            endif
          tagexpr = hero.tagids[Background.?," | "]

          ~We exclude any background traits that have already been added
          ~ If the random generator generates one that's already been added and
          ~ and the trait is then deleted, this creates a situation where a 'ghost'
          ~ copy is left on the character that can't be deleted. It goes away
          ~ when the character is next loaded, but an an error message is
          ~ still shown, and this is less than ideal
          if (hero.tagis[BackTrait.?] <> 0) then
            tagexpr &= " & !(" & hero.tagids[BackTrait.?," | "] & ")"
            endif

          var found as number

          foreach thing in BackPerTrt where tagexpr
            found += 1
            nexteach

          if (found = 0) then
            notify "There are no personality traits available for random generation."
            done
            endif

          var i as number
          var index as number

          var thingid as string

          index = random(found)
          i = 0

          foreach thing in BackPerTrt where tagexpr
            if (i = index) then
              thingid = eachthing.idstring
              endif
              i += 1
            nexteach

          perform hero.addpick[BackPers,thingid]
          ]]></trigger>
        <buttontext><![CDATA[
          if (state.istablet = 0) then
            @text = "Random"
            done
            endif

          ~we have a lot more space to use on the tablet
          @text = "Add a random{br}personality trait"
          ]]></buttontext>
        </action>
      </portal>
Aaron is offline   #6 Reply With Quote