daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 67 in 1 day
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ---------------------
  2. -- ON LOADED SETUP --
  3. ---------------------
  4. local inputController,
  5.       fatigueBase,
  6.       fatigueMult,
  7.       fatigueJumpBase,
  8.       fatigueJumpMult,
  9.       jumpAcroBase,
  10.       jumpAcroMult,
  11.       jumpEncumbBase,
  12.       jumpEncumbMult,
  13.       jumpRunBase,
  14.       jumpRunMult
  15.  
  16. local function onLoaded(e)
  17.     inputController = tes3.worldController.inputController
  18.     fatigueBase     = tes3.getGMST("fFatigueBase")
  19.     fatigueJumpBase = tes3.getGMST("fFatigueJumpBase")
  20.     fatigueJumpMult = tes3.getGMST("fFatigueJumpMult")
  21.     fatigueMult     = tes3.getGMST("fFatigueMult")
  22.     jumpAcroBase    = tes3.getGMST("fJumpAcrobaticsBase")
  23.     jumpAcroMult    = tes3.getGMST("fJumpAcroMultiplier")
  24.     jumpEncumbBase  = tes3.getGMST("fJumpEncumbranceBase")
  25.     jumpEncumbMult  = tes3.getGMST("fJumpEncumbranceMultiplier")
  26.     jumpRunMult     = tes3.getGMST("fJumpRunMultiplier")
  27. end
  28. event.register("loaded", onLoaded)
  29. ---------------------
  30.  
  31.  
  32. local function statisticNorm(stat)
  33.     return (stat.base ~= 0) and (stat.current / stat.base) or 1
  34. end
  35.  
  36. local function vectorNorm(vec)
  37.     local f = vec * vec
  38.     f = math.sqrt(f.x + f.y + f.z)
  39.     return vec * (1 / f)
  40. end
  41.  
  42. local function fatigueTerm(actor)
  43.     local norm = math.max(0, statisticNorm(actor.fatigue))
  44.     return fatigueBase.value - fatigueMult.value * (1 - norm)
  45. end
  46.  
  47. local function encumbranceTerm(actor)
  48.     local norm = statisticNorm(actor.encumbrance)
  49.     return jumpEncumbBase.value + jumpEncumbMult.value * (1 - norm)
  50. end
  51.  
  52. local function simulateJump(actor)
  53.     -- https://wiki.openmw.org/index.php?title=Research:Movement#On_jumping
  54.  
  55.     local b, a = 0, actor.acrobatics.current
  56.     if a > 50 then
  57.         b, a = (a - 50), 50
  58.     end
  59.  
  60.     local x = jumpAcroBase.value
  61.     x = x + math.pow(a / 15, jumpAcroMult.value)
  62.     x = x + 3 * b * jumpAcroMult.value
  63.     x = x + actor.jump * 64
  64.     x = x * encumbranceTerm(actor)
  65.     if actor.isRunning then
  66.         x = x * jumpRunMult.value
  67.     end
  68.     x = x * fatigueTerm(actor)
  69.     -- x = x - 627.2 -- gravityAcceleration
  70.     x = x / 3
  71.  
  72.     local g = vectorNorm(actor.velocity); g.z = 1
  73.     actor.velocity = actor.velocity + g * (x * .707)
  74.  
  75.     actor.fatigue.current = actor.fatigue.current - (
  76.         fatigueJumpBase.value + statisticNorm(actor.encumbrance) * fatigueJumpMult.value
  77.     )
  78. end
  79.  
  80. local function checkJumping(e)
  81.     if tes3.mobilePlayer.isJumping then
  82.         if inputController:keybindTest(12, 2) == 1 then
  83.             tes3.messageBox("Double Jump!")
  84.             tes3.messageBox("Before: %s", tes3.mobilePlayer.velocity)
  85.             simulateJump(tes3.mobilePlayer)
  86.             tes3.messageBox("After: %s", tes3.mobilePlayer.velocity)
  87.         end
  88.     end
  89. end
  90. event.register("simulate", checkJumping)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top