Scale NPC manually with Lua (SOLVED)

  • #1, by nenad-asanovicThursday, 30. November 2017, 14:40 6 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 6 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.

    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

    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

    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

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

    Imperator

    7278 Posts

  • #3, by nenad-asanovicThursday, 30. November 2017, 15:57 6 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 6 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 6 years ago
    Cheers & no problem at all mate. wink

    Imperator

    7278 Posts

  • #6, by MachtnixThursday, 30. November 2017, 16:16 6 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

    1097 Posts

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

    Imperator

    7278 Posts

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

    Thread Captain

    1097 Posts