1. Hey Guest! Stardew Valley is now available on Xbox One and PlayStation 4!
    Dismiss Notice

Modding Help Needing more assistance on my armor...

Discussion in 'Starbound Modding' started by MetaFace, Feb 15, 2017.

  1. MetaFace

    MetaFace Space Penguin Leader

    So I opened this one to ask if someone can help me find a way to make it so my armor, which as of yesterday due to a little scripting now slows the character to a walk and drains the energy of the player while worn, however I want it so energy is drained when the X velocity is greater than zero, but cannot find any method for determining this in the vanilla files.

    I'd also like it if I could do something like status.setStat("encumberance", *numerical value or other stat*), but the only set method belongs to Resources. I want this so I can make a momentum like movement system (like you start as a walk but slowly progress into a full run).
     
  2. MetaFace

    MetaFace Space Penguin Leader

    So, um... does mcontroller.xVelocity() still exist? I think that's what I need to complete my armor, but I haven't seen proof of it still being in the game.
     
  3. Wheee321

    Wheee321 Subatomic Cosmonaut

    mcontroller.xVelocity() exists (\vehicles\boat\boat.lua)
    but mostly used as mcontroller.velocity()[1] (\monsters\boss\guardianboss\guaridan.lua or \scripts\pathing.lua)
    I've played a bit with yVelocity() and correct me if i'm wrong, but if it works like mcontroller.yVelocity(), then a negative value means, that you move left (negative yVelocity means falling -> moving down) -> becauso of the coordinate system
    That means, that it will always be greater or smaller than zero, if you move

    Hope that helps

    Edit on the encumberance thing:
    maybe mcontroller.mass() could help you to solve that problem
    or you use the setStat() function like :
    standing : resource = 0
    if character is moving: count timeMoving
    if timeMoving = positive then resource is rising till resourceMax
    if resourceMax then movingSpeed = 100% (running)

    sry for that pseudocode, maybe you know what I mean^^
     
    Last edited: Feb 15, 2017
  4. MetaFace

    MetaFace Space Penguin Leader

    Yeah I solved my energy drain upon moving using the movement controller function .walking(), now I'm figuring out the jump part. As for the encumberance, I don't think there is a function for it but I think I can make one.
     
  5. Wheee321

    Wheee321 Subatomic Cosmonaut

    Yeah actually you could make it without the setStat() - function, and making the encumberance to 100% dependent from timeRunning() (or what you would call the func)
    Good luck with it!
     
  6. MetaFace

    MetaFace Space Penguin Leader

    So this is the part of the player_primary.lua code that determines this if attributes of the armor are present (not efficiently tho).
    Code:
    if status.stat("encumberance") > 0 and not status.resourcePositive("energyRegenBlock") then
        if status.resource("energy") == 0 then
          status.setResourceLocked("energy", true)
        elseif not status.resourceLocked("energy") then
          if mcontroller.walking() then
            status.modifyResourcePercentage("energy", -status.stat("encumberance") / 16 * dt)
          end
        end
      end
    I just need jump and and momentum, but I don't understand what BData is doing, and I can't find the source of the modifyResoursePercentage function. I also still can't confirm a setStat() function existing or whether I need to build one, but then I'd have to understand the BData.lua.
     
  7. Wheee321

    Wheee321 Subatomic Cosmonaut

    Code:
      status.modifyResourcePercentage("energy", -status.stat("encumberance") / 16 * dt)
    why 16*dt?

    Code:
    #### `void` status.modifyResourcePercentage(`String` resourceName, `float` value)
    
    Adds a percentage of the max resource value to the current value of the resource.
    
    #### `void` status.setResource(`String` resourceName, `float` value)
    
    Sets a resource to the specified value.
    
     
  8. MetaFace

    MetaFace Space Penguin Leader

    It's a predetermined value agreed upon by my friend who I am making this partially for, this is more specifically my armor, as mine (character) is supposed to be a tank. 16 * dt is a valid number in this case, dt being a part of the update function, so it seems almost necessary. This allows me to run around for a few minutes (with the armor complete it'd be a run instead of a walk) before slowing down. So I only really need the ability to modify not the encumberance, but the speed which I walk with the armor, but I can't find the script which reads and applies walk speed to the player.
     
  9. Wheee321

    Wheee321 Subatomic Cosmonaut

    dt stands for delta time:
    Code:
    Update deltas are specified in numbers of frames, so a script with an update delta of 1 would run every frame, or a script with an update delta of 60 would run once per second. 
    An update delta of 0 means that the script's periodic update will never be called, but it can still perform actions through script calls, messaging, or event hooks.
    But in case for time-periodic actions CF uses tickrates where every update-call adds a value to the ticker, until the target tick-time is reached (every update ticker = ticker +0.25 if ticker > 1 then ....)
     
  10. Wheee321

    Wheee321 Subatomic Cosmonaut

    to slow the player or npc debuff-stats use this:
    Code:
    mcontroller.controlModifiers({
          groundMovementModifier = 0.5,
          speedModifier = 0.25
        })
    you can adjust this in the update()func as you like
     
    MetaFace likes this.
  11. MetaFace

    MetaFace Space Penguin Leader

    I'll try this as soon as I'm on my home computer. Thanks.

    EDIT:


    I was going to say the only thing left is jumping, but I actually looked up a mcontroller function chart when you mentioned the control modifier, and saw a function called jumping.

    Funny that when you look through these scripts you never see all these functions.
     
    Last edited: Feb 16, 2017 at 3:08 PM
  12. MetaFace

    MetaFace Space Penguin Leader

    It'll take some work to get the control modifier to implement momentum though, as this will just make it so my walk speed is normal from the get go, I think I can find something somewhere that would give me an example. Unless you know of something? I've checked functions that supposedly did these, but they didn't work (such as the acceleration function just told me that it was nil).

    EDIT:


    So as an example (not tested), I made this.
    Code:
    if status.stat("encumberance") > 0 and not status.resourcePositive("energyRegenBlock") then
      if status.resource("energy") == 0 then
        status.setResourceLocked("energy", true)
      elseif not status.resourceLocked("energy") then
        if mcontroller.walking() then
          status.modifyResourcePercentage("energy", -status.stat("encumberance") / 16 * dt)
          mcontroller.controlModifiers({
            groundMovementModifier = 1.0,
            speedModifier = 1.0
          })
        end
        if mcontroller.jumping() then
          status.modifyResourcePercentage(“energy”, -status.stat(“encumberance”) / 2 * dt)
        end
      end
    end
    I just have to figure the above where as you walk you speed up till you are going... maybe a little faster than normal do to "weight" and exponential speed gain. Of course this control modifier will handle it to the point of how fast, but as an idea, if I could make a variable which started at the default walk speed and only went as high as a calculated number based off said "weight" of armor and use that variable in place of the values in the ground and speed modifiers. You think it'll work?
     
    Last edited: Feb 16, 2017 at 4:45 PM
  13. bk3k

    bk3k Existential Complex

    Yeah mcontroller.velocity probably has you covered, but velocity isn't so hard to figure out over the course of multiple update() ticks.
    You get your position.
    Save it.
    Next run you get your position
    position - oldPosition = travel distance
    travel distance / dt = distance per dt

    Using multiplying/dividing/etc by dt means you have a consistent result despite what the update interval is. So that adds some flexibility. That drain per second will be the same no matter if the script is called every 5 dt or every 30 dt.

    It is like this. Take 30 energy twice a second. Take 15 energy 4 times a second. Take 1 energy 60 times a second. All mostly equivalent. Why does that code work this way?

    As dt is increased, the code is ran less often. A dt of 5 runs twice as often as dt of 10
    --dt = 5
    10 * dt = 50

    --dt = 10
    10 * dt = 100

    But the since the dt of 5 runs twice as often so effectively,,,
    50 * 2 = 100

    I expect that answers the question as to why use dt in your calculations.
     
  14. MetaFace

    MetaFace Space Penguin Leader

    I could make the above logistical in terms of
    position - oldposition = traveldistance
    traveldistance / dt = traveldelta

    Multiply traveldelta by some magic number and use it to logistically alter my velocity until a certain point which it will cap, this cap could be a fixed amount or a number determined by "weight" of armor. I just would have to work out and possible kinks and hope performance isn't impacted terribly, may have to move all this code to a new script that is called from the player_primary instead of running directly in it.

    However I'm mostly just full of terrible ideas, so this will go really bad and probably have to come back for some help, hopefully I will be able to come back tomorrow and say "[SOLVED]".

    EDIT: actually ignore that part that's underlined, it's stupid.
     
  15. MetaFace

    MetaFace Space Penguin Leader

    So what I need now is a fix for the animation, since I can change how fast I walk, but I still use the walking animation instead of the run. Anyone know how to tell the game what animation to use and how fast the animation should be?

    Next is removing status effects when a certain condition is met.

    as an edit to this post... here's the current working code without any momentum because I had to go to sleep eventually.
    Code:
    if status.stat("encumberance") > 0 and not status.resourcePositive("energyRegenBlock") then
      if status.resource("energy") == 0 then
        status.setResourceLocked("energy", true)
      elseif not status.resourceLocked("energy") then
        if mcontroller.walking() then
          status.modifyResourcePercentage("energy", -status.stat("encumberance") / 16 * dt)
          mcontroller.controlModifiers({
            groundMovementModifier = 1.0,
            speedModifier = 1.0
          })
        end
        if mcontroller.jumping() then
          status.modifyResourcePercentage("energy", -status.stat("encumberance") / 2 * dt)
        end
      end
    end
    This was written after some of your guy's help, then when I got home I imported into the game, it worked, but I don't know where to find the file that controls player animation, and I need that so I can control how and what animation plays.
     
    Last edited: Feb 17, 2017 at 2:37 PM
  16. EmissaryOfInfinity

    EmissaryOfInfinity Space Spelunker

    I'm actually gonna watch this thread myself, cuz I've been wondering how I might modify the animation speeds for a tech I have. I know there's the function animator.setAnimationRate(), but I believe that only applies to particles and special animations added by the script itself.
     
  17. MetaFace

    MetaFace Space Penguin Leader

    Welcome to the really confused club then.
     
  18. EmissaryOfInfinity

    EmissaryOfInfinity Space Spelunker

    The main issue is that CF doesn't make player animations manifest to modding. They're embedded in the code and can't be edited. If they made the animations more freely moddable, a lot of current issues would dissolve overnight.
     
  19. MetaFace

    MetaFace Space Penguin Leader

    So if I can't access the animations of send a command through to tell it how and what animation to play, then I guess I have to make the armor a small mech-like suit (like power armor in fallout 4) and give it its own animation for this kind of thing. Meaning I have to learn how to make a vehicle technically, which hopefully won't be too hard to do. I mean there are a ton of vehicle and mech mods, so I guess... okey doke. But if anyone has ever successfully forced that game to do a certain animation on command, then I want to know.
     
  20. Wheee321

    Wheee321 Subatomic Cosmonaut

    Maybe try it with animator.setAnimationState("movement", "walk")
    Found that, but havent used it so far, maybe useful to you

    another thing is, you can add {runningSuppressed = false} to your mcontroller.controlModifiers() function, I have only used it to suppress running, not the other way, but maybe, as written above: it may be useful to you^^
     

Share This Page