Scale NPC manually with Lua (SOLVED)

  • #1, by nenad-asanovicThursday, 30. November 2017, 14:40 2 years ago
    In my game there is option to do certain things on "seperate" scene where main character don't even show/go. So when we trigger this scene I send npc to that scene and we chose different animations via buttons on the screen. So I was thinking is it possible to somehow scale that NPC (+ and -) via Lua? To make it possible only on that certain scene i would create condition. So would be If "zoom in" is on then... So what I need is scale factor inside script that works for NPC character without main character being on scene. Also would need to limit scale factor to some point so we can't scale under x or over x scale factor... I hope this was clear enough for anyone who maybe know the answer smile

    Newbie

    59 Posts


  • #2, by afrlmeThursday, 30. November 2017, 15:32 2 years ago
    Not really, no... grin

    You can disable auto-scaling of the way system for a character.
    Characters["Tom"].CharacterScale = false -- turn off auto-scaling.
    1

    CharacterSize data structure field says it's not scriptable according to the data structure, but I'm pretty sure it is to a degree as I vaguely recall helping Jacob sort out some script for a specific scene in his Paradigm game where he wanted to force specific sizes for the character. I believe it reset the size each time the animation changed or something so we needed to force the value inside of a loop - I don't remember, anyway... here's an example of how you could scale up a character by 10 percent with a cap of 100%
    if Characters["Tom"].CharacterSize <= 90 then
     Characters["Tom"].CharacterSize = Characters["Tom"].CharacterSize + 10
     if Characters["Tom"].CharacterSize > 100 then Characters["Tom"].CharacterSize = 100 end
    end
    1
    2
    3
    4

    I'm sure you can figure out how to scale them down & add a cap based on that. You could actually create a function instead so that you can scale any character up/down if you wanted to save a bit of time.
    function scaleChar(char, val, cap, dir)
     char = Characters[char] -- store character into variable
     char.CharacterScale = false -- disable scaling
     if dir and char.CharacterSize <= cap then
      char.CharacterSize = char.CharacterSize + val -- increment value
      if char.CharacterSize > cap then char.CharacterSize = cap end -- force cap value if more than
     elseif not dir and char.CharacterSize >= cap then
      char.CharacterSize = char.CharacterSize - val -- decrement value
      if char.CharacterSize < cap then char.CharacterSize = cap end -- force cap value if less than
     end
    end
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    example of usage...
    scaleChar("Tom", 10, 100, true) -- character, percent value to increase/decrease by, min/max cap value, true to increment, false to subtract
    1

    I've written this off the top of my head, so I've no idea whether or not it will work.

    Imperator

    6816 Posts

  • #3, by nenad-asanovicThursday, 30. November 2017, 15:57 2 years ago
    As always works perfectly! All I have to do is play with numbers that I need for my game. Thanks a lot. This is why I support you at: 

    Newbie

    59 Posts

  • #4, by nenad-asanovicThursday, 30. November 2017, 15:58 2 years ago
    As always works perfectly! All I have to do is play with numbers that I need for my game. Thanks a lot. This is why I support you at: 


     


     

    Newbie

    59 Posts

  • #5, by afrlmeThursday, 30. November 2017, 16:03 2 years ago
    Cheers & no problem at all mate. wink

    Imperator

    6816 Posts

  • #6, by MachtnixThursday, 30. November 2017, 16:16 2 years ago
    This also works in 4.2.5? I am just looking for the same ( I have to set the size of main- and npc-characters on each scene manually). To explain why takes a long time.

    Thread Captain

    1078 Posts

  • #7, by afrlmeThursday, 30. November 2017, 16:59 2 years ago
    It should do, yeah. Both CharacterScale & CharacterSize exist in 4.25. wink

    Imperator

    6816 Posts

  • #8, by MachtnixThursday, 30. November 2017, 17:12 2 years ago
    Thx. In my project I have to store direction, position and size of every character to use them later.

    Thread Captain

    1078 Posts

Write post