CCBlueX Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Calculating the distance between 2 blocks (X and Z only)

    Scripts
    3
    3
    207
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • notautismatall
      notautismatall last edited by

      This might be helpful with someone who is trying to make a module that can calculate how far the player has moved from his starting point.

      function diff (a, b) {
        if (a > b)
          return a - b
        else
          return b - a
      }
      
      var startX = 0, startZ = 0, diffX = 0, diffZ = 0, bruh = 0;
      
      module.on("enable", function() {
        startX = mc.thePlayer.posX
        startZ = mc.thePlayer.posZ
      })
      
      module.on("update", function() {
        diffX = diff(startX, mc.thePlayer.posX)
        diffZ = diff(startZ, mc.thePlayer.posZ)
      
        bruh = diffX + diffZ
        Chat.log('Blocks traveled: ' + bruh.toFixed(1).toString())
      })
      
      Plumer Man A 2 Replies Last reply Reply Quote 1
      • Plumer Man
        Plumer Man @notautismatall last edited by

        @notautismatall Nice

        1 Reply Last reply Reply Quote 0
        • A
          Aftery @notautismatall last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 3
          • First post
            Last post
          About
          • Terms of Service
          • Privacy Policy
          • Status
          • Contact Us
          Downloads
          • Releases
          • Source code
          • License
          Docs
          • Tutorials
          • CustomHUD
          • AutoSettings
          • ScriptAPI
          Community
          • Forum
          • Guilded
          • YouTube
          • Twitter
          • D.Tube