Skip to content
  • 0 Unread 0
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Donate
Collapse

Plutonium

  1. Home
  2. BO2 Modding Support & Discussion
  3. [Support] Code for distance meter for trickshots?

[Support] Code for distance meter for trickshots?

Scheduled Pinned Locked Moved BO2 Modding Support & Discussion
27 Posts 10 Posters 5.5k Views 3 Watching
  • 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.
  • Ox_ Ox_

    Cahz said in Code for distance meter for trickshots?:

    Ox_ Okay so if one CoD world unit is 2.54cm, then you would actually divide by 39.37.

    2.54 cm = 1 unit

    100 cm = 39.3700 units = 1 m

    Well actually you'd divide by 5000/127, but maybe just multiply by 0.0254, be easier.

    Cahz Offline
    Cahz Offline
    Cahz
    VIP
    wrote on last edited by
    #9

    Ox_ said in Code for distance meter for trickshots?:

    Cahz said in Code for distance meter for trickshots?:

    Ox_ Okay so if one CoD world unit is 2.54cm, then you would actually divide by 39.37.

    2.54 cm = 1 unit

    100 cm = 39.3700 units = 1 m

    Well actually you'd divide by 5000/127, but maybe just multiply by 0.0254, be easier.

    5000/127 is literally 39.37... which works totally fine by the way. So no need to multiply

    Ox_ 1 Reply Last reply
    0
    • Cahz Cahz

      Ox_ said in Code for distance meter for trickshots?:

      Cahz said in Code for distance meter for trickshots?:

      Ox_ Okay so if one CoD world unit is 2.54cm, then you would actually divide by 39.37.

      2.54 cm = 1 unit

      100 cm = 39.3700 units = 1 m

      Well actually you'd divide by 5000/127, but maybe just multiply by 0.0254, be easier.

      5000/127 is literally 39.37... which works totally fine by the way. So no need to multiply

      Ox_ Offline
      Ox_ Offline
      Ox_
      wrote on last edited by
      #10

      Cahz said in Code for distance meter for trickshots?:

      Ox_ said in Code for distance meter for trickshots?:

      Cahz said in Code for distance meter for trickshots?:

      Ox_ Okay so if one CoD world unit is 2.54cm, then you would actually divide by 39.37.

      2.54 cm = 1 unit

      100 cm = 39.3700 units = 1 m

      Well actually you'd divide by 5000/127, but maybe just multiply by 0.0254, be easier.

      5000/127 is literally 39.37... which works totally fine by the way. So no need to multiply

      It's not, but sure, it's close enough for most uses.

      1 Reply Last reply
      0
      • Sass Offline
        Sass Offline
        Sass
        Plutonium Staff
        wrote on last edited by
        #11

        I already changed my post to 40 yesterday. That's more than good enough, it doesn't need to be dead-on precise.

        1 Reply Last reply
        1
        • Sass Offline
          Sass Offline
          Sass
          Plutonium Staff
          wrote on last edited by Sass
          #12

          I also feel so fucking dumb for not posting the right thing. I thought OP wanted a function that detects a player you almost hit and the distance between the impact and the player, not the distance from the player you just killed...


          Edit )
          Here's what you want to do. I also edited my first reply to include this script instead, sorry for the confusion. While I'm at it I included the "more precise" multiplier too since it seems to cause alot of debate for whatever reason.

          Step 1 - Add the following in init() :

          level.onkillscore = level.onplayerkilled;
          level.onplayerkilled = ::onplayerkilled;
          

          Step 2 - Copy the following somewhere in your file :

          onPlayerKilled(einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration) 
          {
              thread [[level.onkillscore]](einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration);
              // ^ this is here so you can still score normally
              
              attacker iPrintLn("You killed " + self.name + " from " + int(distance(self.origin, attacker.origin)*0.0254) + "m away");
          }
          
          Duui YT 1 Reply Last reply
          1
          • Sass Sass

            I also feel so fucking dumb for not posting the right thing. I thought OP wanted a function that detects a player you almost hit and the distance between the impact and the player, not the distance from the player you just killed...


            Edit )
            Here's what you want to do. I also edited my first reply to include this script instead, sorry for the confusion. While I'm at it I included the "more precise" multiplier too since it seems to cause alot of debate for whatever reason.

            Step 1 - Add the following in init() :

            level.onkillscore = level.onplayerkilled;
            level.onplayerkilled = ::onplayerkilled;
            

            Step 2 - Copy the following somewhere in your file :

            onPlayerKilled(einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration) 
            {
                thread [[level.onkillscore]](einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration);
                // ^ this is here so you can still score normally
                
                attacker iPrintLn("You killed " + self.name + " from " + int(distance(self.origin, attacker.origin)*0.0254) + "m away");
            }
            
            Duui YT Offline
            Duui YT Offline
            Duui YT
            wrote on last edited by
            #13

            Sass how to make it so every one sees the message

            Deicide 1 Reply Last reply
            0
            • Duui YT Duui YT

              Sass how to make it so every one sees the message

              Deicide Offline
              Deicide Offline
              Deicide
              wrote on last edited by
              #14

              Duui YT said in [Support] Code for distance meter for trickshots?:

              Sass how to make it so every one sees the message
              Change this

              attacker iPrintLn("You killed " + self.name + " from " + int(distance(self.origin, attacker.origin)*0.0254) + "m away");
              
              iPrintLn("You killed " + self.name + " from " + int(distance(self.origin, attacker.origin)*0.0254) + "m away");
              

              To this. You should try experimenting and figuring out some things yourself too 🙂

              Duui YT 1 Reply Last reply
              0
              • Deicide Deicide

                Duui YT said in [Support] Code for distance meter for trickshots?:

                Sass how to make it so every one sees the message
                Change this

                attacker iPrintLn("You killed " + self.name + " from " + int(distance(self.origin, attacker.origin)*0.0254) + "m away");
                
                iPrintLn("You killed " + self.name + " from " + int(distance(self.origin, attacker.origin)*0.0254) + "m away");
                

                To this. You should try experimenting and figuring out some things yourself too 🙂

                Duui YT Offline
                Duui YT Offline
                Duui YT
                wrote on last edited by Duui YT
                #15

                Deicide can i do this or it will not work

                iPrintLn("+ self.name +  " + self.name + " from " + int(distance(self.origin, attacker.origin)*0.0254) + "m away");
                
                1 Reply Last reply
                0
                • Duui YT Offline
                  Duui YT Offline
                  Duui YT
                  wrote on last edited by Duui YT
                  #16

                  it did not work it says it when someone dies not when they get a kill

                  Sass 1 Reply Last reply
                  0
                  • Duui YT Duui YT

                    it did not work it says it when someone dies not when they get a kill

                    Sass Offline
                    Sass Offline
                    Sass
                    Plutonium Staff
                    wrote on last edited by
                    #17

                    It does work, I tested it just now. I'm not sure what the problem is.

                    1 Reply Last reply
                    1
                    • Duui YT Offline
                      Duui YT Offline
                      Duui YT
                      wrote on last edited by Duui YT
                      #18

                      Sass this is what i do as Deicide told me but it says it when someone dies not when they get a kill

                      onPlayerKilled(einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration) 
                      {
                          thread [[level.onkillscore]](einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration);
                          // ^ this is here so you can still score normally
                          
                          iPrintLn(int(distance(self.origin, attacker.origin)*0.0254) + "m away");
                      } 
                      
                      Cahz Sass 2 Replies Last reply
                      0
                      • Duui YT Duui YT

                        Sass this is what i do as Deicide told me but it says it when someone dies not when they get a kill

                        onPlayerKilled(einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration) 
                        {
                            thread [[level.onkillscore]](einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration);
                            // ^ this is here so you can still score normally
                            
                            iPrintLn(int(distance(self.origin, attacker.origin)*0.0254) + "m away");
                        } 
                        
                        Cahz Offline
                        Cahz Offline
                        Cahz
                        VIP
                        wrote on last edited by
                        #19

                        Duui YT
                        When someone dies, does another player not get a kill?
                        1 KILL (attacker) = 1 DEATH (self)

                        You're literally making no sense when it comes to this. Instead of spamming the forums with questions over and over, how about do some research into the game files and ask YOURSELF, "why is this script behaving like this?" Instead of asking a million questions on the forums. (Which could all be solved on your own if you put a little time into learning)

                        I personally don't like the idea of someone running a server that only knows how to copy and paste other people's scripts, but couldn't tell you how any of them work. This is exactly the type of stuff that leads to servers crashing more frequently due to poorly made/unstable scripts being used by someone who doesn't know that it is poorly made/unstable.

                        Research GSC there's plenty of information out on the internet.

                        1 Reply Last reply
                        3
                        • Duui YT Duui YT

                          Sass this is what i do as Deicide told me but it says it when someone dies not when they get a kill

                          onPlayerKilled(einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration) 
                          {
                              thread [[level.onkillscore]](einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration);
                              // ^ this is here so you can still score normally
                              
                              iPrintLn(int(distance(self.origin, attacker.origin)*0.0254) + "m away");
                          } 
                          
                          Sass Offline
                          Sass Offline
                          Sass
                          Plutonium Staff
                          wrote on last edited by Sass
                          #20

                          Backing up on what Cahz , this is basic GSC knowledge. If you're willing to host servers with mods, you should atleast take the time to learn and comprehend how the script works. We could babysit you through the whole process, but that will never play in your favor and you'll be stuck because of the smallest issues such as this one. You can find plenty of resources and even tutorials with enough searching. Please take some time to learn, it will help you alot.

                          1 Reply Last reply
                          2
                          • Duui YT Offline
                            Duui YT Offline
                            Duui YT
                            wrote on last edited by Duui YT
                            #21

                            so i did do some research on it but can't get it. so this what happens when i die it says (X m away) and not when i kill someone so when i die it says it so how can i make it not say it when i die and i did try calling it on onplayerdamge but that did not work

                            Sass 1 Reply Last reply
                            0
                            • Duui YT Duui YT

                              so i did do some research on it but can't get it. so this what happens when i die it says (X m away) and not when i kill someone so when i die it says it so how can i make it not say it when i die and i did try calling it on onplayerdamge but that did not work

                              Sass Offline
                              Sass Offline
                              Sass
                              Plutonium Staff
                              wrote on last edited by
                              #22

                              If you want it to show when you kill someone, then don't remove attacker, simple as that. If you want it to show for everyone, maybe do something like a foreach(player in level.players) and use player instead of attacker ?

                              I don't know, there are plenty of ways to do this, you have to give it more thought than that.

                              1 Reply Last reply
                              3
                              • Duui YT Offline
                                Duui YT Offline
                                Duui YT
                                wrote on last edited by
                                #23

                                so i did do some research on how to use foreach. so i did it like this still the same thing

                                onPlayerKilled(einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration)
                                {
                                    foreach(player in level.players)
                                    {
                                        thread [[level.onkillscore]] (einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration);
                                        // ^ this is here so you can still score normally
                                
                                        player iPrintLn(int(distance(self.origin, attacker.origin) * 0.0254) + "m away");
                                    }
                                } 
                                
                                Sass 1 Reply Last reply
                                0
                                • Duui YT Duui YT

                                  so i did do some research on how to use foreach. so i did it like this still the same thing

                                  onPlayerKilled(einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration)
                                  {
                                      foreach(player in level.players)
                                      {
                                          thread [[level.onkillscore]] (einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration);
                                          // ^ this is here so you can still score normally
                                  
                                          player iPrintLn(int(distance(self.origin, attacker.origin) * 0.0254) + "m away");
                                      }
                                  } 
                                  
                                  Sass Offline
                                  Sass Offline
                                  Sass
                                  Plutonium Staff
                                  wrote on last edited by Sass
                                  #24

                                  The script you've made gives point to every player once you get a kill... This isn't about "doing research" at this point, this is about knowing how to script at all.

                                  The following should work, but PLEASE take some time to LEARN how to do such simple tweaks :

                                  onPlayerKilled(einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration) 
                                  {
                                      thread [[level.onkillscore]](einflictor, attacker, idamage, smeansofdeath, sweapon, vdir, shitloc, psoffsettime, deathanimduration);
                                      foreach(player in level.players)
                                      	player iPrintLn( attacker.name + " killed " + self.name + " from " + int(distance(self.origin, attacker.origin)*0.0254) + "m away");
                                  }
                                  
                                  1 Reply Last reply
                                  2
                                  • gunji Offline
                                    gunji Offline
                                    gunji
                                    Contributor
                                    wrote on last edited by
                                    #25
                                    This post is deleted!
                                    birchy mikzy 2 Replies Last reply
                                    0
                                    • gunji gunji

                                      This post is deleted!

                                      birchy Offline
                                      birchy Offline
                                      birchy
                                      wrote on last edited by
                                      #26

                                      gunji you can check on player kill whether or not the player/teams score is equal to that of the score required to win the mode.

                                      1 Reply Last reply
                                      0
                                      • gunji gunji

                                        This post is deleted!

                                        mikzy Offline
                                        mikzy Offline
                                        mikzy
                                        Banned
                                        wrote on last edited by
                                        #27

                                        gunji you just check if the attacker is on last, nothing to do with the gameended notify

                                        1 Reply Last reply
                                        0

                                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                        With your input, this post could be even better 💗

                                        Register Login
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        • 1
                                        • 2
                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Unread 0
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Donate