MagicPlugin icon indicating copy to clipboard operation
MagicPlugin copied to clipboard

Attributes applied to mobs not functioning properly?

Open NightScythe1 opened this issue 2 years ago • 24 comments

dragon_stat_randomiser:
  icon: enchanted_book
  actions:
    cast:
    - class: CheckRequirements
      requirement:
        attribute:
          attribute: dragon_generated
          max: 0.5
      actions:
        - class: ModifyEntity
          mage:
            attributes:
              dragon_generated: 1
              health_dragon: ceil(rand(0,12))
              defence_dragon: ceil(rand(0,12))
              power_dragon: ceil(rand(0,12))
              speed_dragon: ceil(rand(0,12))
              agility_dragon: ceil(rand(0,12))
  parameters:
    bypass_undo: true
    target: other

the following spell is intended to apply a randomised number to these attributes on a Magic Mob (made as a workaround to my last issue) but it has some weird functionality-

  1. Upon initial cast it works as intended, giving each stat a random value 0-12
  2. However, this randomised stat then re-rolls and randomises 0-12 again after any reloads and '/magic load'
  3. The randomised stat is set back to 0 when the server restarts

Is there a way to ensure the randomised stat is saved/will stay the same after the spell is first used?

NightScythe1 avatar May 21 '23 23:05 NightScythe1

its just how rand function behaves, i think solution is just to store "ceil(rand(0,12)" into a ModifyVariable action's variables and use them for your ModifyEntity action

PhvntxmX avatar May 28 '23 04:05 PhvntxmX

its just how rand function behaves, i think solution is just to store "ceil(rand(0,12)" into a ModifyVariable action's variables and use them for your ModifyEntity action

No luck with this unfortunately :( I tried adding the following to the start of the spell:

    - class: ModifyVariable
      variable: hprand
      value: ceil(rand(0,12))

and calling it back later via

        - class: ModifyEntity
          mage:
            attributes:
              health_dragon: hprand

(varying with 'hprand' and '@hprand' and '$hprand') but it doesn't seem to work at all, and the stat remains at 0

NightScythe1 avatar May 28 '23 08:05 NightScythe1

What about using command action and /mage command instead of this?

PhvntxmX avatar Jun 01 '23 01:06 PhvntxmX

It doesn't fix the problem obviously, but I'm sure it'll work as a temporary solution

PhvntxmX avatar Jun 01 '23 01:06 PhvntxmX

I'll give it a try now!

NightScythe1 avatar Jun 01 '23 15:06 NightScythe1

No luck, unfortunately. It works on players, but not on mobs.

NightScythe1 avatar Jun 01 '23 15:06 NightScythe1

that's really strange, i need to test it myself...

PhvntxmX avatar Jun 01 '23 23:06 PhvntxmX

This is working for me:

test:
  actions:
    cast:
    - class: CustomProjectile
      actions:
        - class: ModifyProperties
          modify_target: "mage"
          modify:
          - property: attributes.ag
            value: rand(0,5)
        - class: Cast
          as_target: true
          spell: check
  parameters:
    target: other
    range: 32

check:
  actions:
    cast:
    - class: AreaOfEffect
      actions:
        - class: Message
          message_target: true
          message: "$ag"
  parameters:
    target: self
    target_self: false
    range: 5
    radius: 10
    y_radius: 10

PhvntxmX avatar Jun 02 '23 14:06 PhvntxmX

"ag" attribute will change every cast as expected, but you can add checkrequirements to prevent it

PhvntxmX avatar Jun 02 '23 15:06 PhvntxmX

This is working for me:


test:

  actions:

    cast:

    - class: CustomProjectile

      actions:

        - class: ModifyProperties

          modify_target: "mage"

          modify:

          - property: attributes.ag

            value: rand(0,5)

        - class: Cast

          as_target: true

          spell: check

  parameters:

    target: other

    range: 32



check:

  actions:

    cast:

    - class: AreaOfEffect

      actions:

        - class: Message

          message_target: true

          message: "$ag"

  parameters:

    target: self

    target_self: false

    range: 5

    radius: 10

    y_radius: 10

Thank you so much for this!!! I'll give it a test as soon as i'm home. Do these stats remain after reloads & server restarts?

NightScythe1 avatar Jun 02 '23 15:06 NightScythe1

haven't tested that part, but i assume - yes upd: NO

PhvntxmX avatar Jun 02 '23 16:06 PhvntxmX

well now i'm dissapointed: is it not just 1 single action reverting itself on restart, but it's actually every action?

PhvntxmX avatar Jun 02 '23 16:06 PhvntxmX

something here is definetly broken, these actions are not supposed to revert on restart - it's just breaks the whole purpose of them

PhvntxmX avatar Jun 02 '23 16:06 PhvntxmX

Have you tried ModifyAttributes instead of ModifyProperties?

Sorry if I'm not totally following, I'm honestly a little hazy on the difference between the two, especially when using the latter to modify attributes :|

NathanWolf avatar Jun 02 '23 16:06 NathanWolf

Have you tried ModifyAttributes instead of ModifyProperties?

Sorry if I'm not totally following, I'm honestly a little hazy on the difference between the two, especially when using the latter to modify attributes :|

Tried it now and it also does not work. I assume attributes itself are broken?

PhvntxmX avatar Jun 02 '23 16:06 PhvntxmX

Also tried it on both magic and vanilla mobs - same result. So it's not a magic mob's template overwriting the data i guess

PhvntxmX avatar Jun 02 '23 16:06 PhvntxmX

This is working for me:

I tried using this spell but it doesn't seem to work at all for me, it doesn't change the mob's stat and always prints '0'. The only things I changed from your original example was the attribute name-

test:
  actions:
    cast:
    - class: CustomProjectile
      actions:
        - class: ModifyProperties
          modify_target: "mage"
          modify:
          - property: attributes.health_dragon
            value: rand(0,5)
        - class: Cast
          as_target: true
          spell: check
  parameters:
    target: other
    range: 32

check:
  actions:
    cast:
    - class: AreaOfEffect
      actions:
        - class: Message
          message_target: true
          message: "$health_dragon"
  parameters:
    target: self
    target_self: false
    range: 5
    radius: 10
    y_radius: 10

NightScythe1 avatar Jun 03 '23 11:06 NightScythe1

  1. Upon initial cast it works as intended, giving each stat a random value 0-12
  2. However, this randomised stat then re-rolls and randomises 0-12 again after any reloads and '/magic load'
  3. The randomised stat is set back to 0 when the server restarts

Is there a way to ensure the randomised stat is saved/will stay the same after the spell is first used?

This also occurs if using SpawnEntity instead. Still struggling to find a way to allow Magic Mobs to keep set-stats after restarts & to allow placeholders for some of these equations.

    - class: SpawnEntity
      type: monstrous_nightmare
      mage:
        attributes:
          speed_dragon: ceil(rand(0,12))

NightScythe1 avatar Jun 03 '23 14:06 NightScythe1

Just another update, I actually did manage to get ModifyAttributes to work on the mob, it sets the random stat without being changed on reloads and /magic load, but it does still reset upon server restart (as @PhvntxmX said in #1226)

    - class: ModifyAttribute
      bypass_undo: true
      attribute: health_dragon
      value: ceil(rand(0,12)) 

NightScythe1 avatar Jun 03 '23 21:06 NightScythe1

Update: from my testing so far, MagicMob attributes, edits, stats, etc, can be saved with save_non_player_mages: true set in config!

NightScythe1 avatar Jan 10 '24 19:01 NightScythe1

Well that makes sense!

Just keep in mind that is off by default for performance/storage reasons.

It's maybe not a huge deal, but this will cause a file (or db row, or whatever player data storage you're using) to get created for every magic mob you spawn.

NathanWolf avatar Jan 10 '24 20:01 NathanWolf

Ahh I see, that makes sense. Could there be a way to differentiate/decide if particular mobs get their stats saved? I'm mostly just trying to make sure owned pets (or anything with the persist tag) don't get wiped. I assume this will be an issue as dragons are naturally spawning mobs that need to be tamed? (i.e. every wild dragon ever spawned will have a file generated)

NightScythe1 avatar Jan 10 '24 20:01 NightScythe1

Yeah that's kind of my concern .... are the naturally spawned ones persistent also, or do they not persist until tamed?

Either way it sounds like a special flag to save mobs would be nice.

Alternately I should really look into using the persistent data container on mobs for this kind of thing, I can't remember if magic does anything with that or not.

NathanWolf avatar Jan 10 '24 20:01 NathanWolf

Naturally spawned dragons don't have the persistent tag until they're tamed, the interaction spell they have (like philbert's) applies the persist: true tag to them and thankfully this seems to stick/remain on server restarts, even if the save_non_player_mages is set to false. With this false, they seems they keep most vanilla attributes and tags even if they're set with magic, it was just things that are solely magic/magic integrated that got wiped (e.g. disguises, attributes)

NightScythe1 avatar Jan 10 '24 20:01 NightScythe1