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

Plutonium

  1. Home
  2. BO2 Modding Releases & Resources
  3. [Release] Player bullet was off (meters) from victim

[Release] Player bullet was off (meters) from victim

Scheduled Pinned Locked Moved BO2 Modding Releases & Resources
6 Posts 3 Posters 1.0k Views
  • 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.
  • mikzyundefined Offline
    mikzyundefined Offline
    mikzy
    Banned
    wrote on last edited by mikzy
    #1

    Put this in onplayerconnect:

    player.first = true;
    

    Put this in onplayerspawned and run it only once:

    if (self.first)
    {
        self thread watchBullet();
        self.first = false;
    }
    

    Put this anywhere in your code:

    watchBullet()
    {
        /*
    
        If you want the victim who about got hit on to recieve a message, you would do:
        player iprintln(self.name " almost hit you");
    
        */
    
    
        self endon("death");
        self endon("disconnect");
        level endon("game_ended");
        
        for(;;) 
        {
        
            self waittill("weapon_fired");
            
            // you can edit this to your liking but this worked for me
            radius = 100;
            maxDist = 110;
    
            forward = self getTagOrigin("j_head");
            end = vectorScale(anglestoforward(self getPlayerAngles()), 1000000);
            predictedLoc = bulletTrace( forward, end, false, self )["position"];
            
            foreach(player in level.players) 
            {
                // found the teambased vars in a dump, probably helpful. its in there just in case (:
                if( !isAlive(player) || player == self || player.team == self.team && level.teamBased )
                {
                    continue;
                }
            }
    
            dist = distance(player.origin, predictedLoc);
            if(dist < radius && dist <= maxDist) {
                 self iprintln("Shot ^6" + int(distance(self.origin, attacker.origin)*0.0254) + " ^7meters off of ^6" + player.name);
            }
        }
    }
    

    You can edit the radius and maxDist variable but I only recommend if you know what you are doing. I don't think any external functions are needed but if you get a error at vectorScale, make sure your includes are correct or you have a vectorScale function.

    1 Reply Last reply
    0
    • mikzyundefined Offline
      mikzyundefined Offline
      mikzy
      Banned
      wrote on last edited by
      #2

      Just in case you need it:

      vectorScale(vec,scale)
      {
          vec=(vec[0]*scale,vec[1]*scale,vec[2]*scale);
          return vec;
      } 
      
      Matrixundefined 1 Reply Last reply
      0
      • mikzyundefined mikzy

        Just in case you need it:

        vectorScale(vec,scale)
        {
            vec=(vec[0]*scale,vec[1]*scale,vec[2]*scale);
            return vec;
        } 
        
        Matrixundefined Offline
        Matrixundefined Offline
        Matrix
        Plutonium Staff
        wrote on last edited by
        #3

        mikey said in [Release] Player bullet was off (meters) from victim:

        Just in case you need it:

        vectorScale(vec,scale)
        {
            vec=(vec[0]*scale,vec[1]*scale,vec[2]*scale);
            return vec;
        } 
        

        Last I checked you can't use a variable before initializing it and expect it to work

        predictedLoc = bulletTrace( forward, end, false, self )["position"];
        end = vectorScale(anglestoforward(self getPlayerAngles()), 1000000);

        mikzyundefined 1 Reply Last reply
        0
        • Sorexundefined Offline
          Sorexundefined Offline
          Sorex
          Contributor
          wrote on last edited by Sorex
          #4

          mikey To do that you can use the EB code, you can find the code for this type of EB online, is a free to use.
          I don't know why you keep calling radius and mixDist for every single shoot, is not necessary.

          watch_player_near(){
          	radius = 100;
           	for(;;) {
                  self waittill("weapon_fired");
                  end = vectorScale(anglestoforward(self getPlayerAngles()), 1000000);
                  forward = self getTagOrigin("j_head"); 
                  predictedLoc = bulletTrace( forward, end, false, self )["position"];
                  
                  foreach(player in level.players) {
                    
                      if( isAlive(player) && player != self || (player.team != self.team && level.teamBased) ){
                          if(distance(player.origin, predictedLoc) < radius)
                          	self iprintln("Shot ^6" + int(distance(self.origin, player.origin)*0.0254) + " ^7meters off of ^6" + player.name);
                      }
                  } 
          	}
          }
          

          I don't know why you use a maximum distance, everyone can be hit if you don't have a limit (like in my servers, in my server you can hit enemy to close).
          The attacker is not defined in this function. I don't know what is the point of calling the attacker.

          mikzyundefined 1 Reply Last reply
          1
          • Matrixundefined Matrix

            mikey said in [Release] Player bullet was off (meters) from victim:

            Just in case you need it:

            vectorScale(vec,scale)
            {
                vec=(vec[0]*scale,vec[1]*scale,vec[2]*scale);
                return vec;
            } 
            

            Last I checked you can't use a variable before initializing it and expect it to work

            predictedLoc = bulletTrace( forward, end, false, self )["position"];
            end = vectorScale(anglestoforward(self getPlayerAngles()), 1000000);

            mikzyundefined Offline
            mikzyundefined Offline
            mikzy
            Banned
            wrote on last edited by
            #5

            Matrix my bad, rushed the code and forgot to double look

            1 Reply Last reply
            1
            • Sorexundefined Sorex

              mikey To do that you can use the EB code, you can find the code for this type of EB online, is a free to use.
              I don't know why you keep calling radius and mixDist for every single shoot, is not necessary.

              watch_player_near(){
              	radius = 100;
               	for(;;) {
                      self waittill("weapon_fired");
                      end = vectorScale(anglestoforward(self getPlayerAngles()), 1000000);
                      forward = self getTagOrigin("j_head"); 
                      predictedLoc = bulletTrace( forward, end, false, self )["position"];
                      
                      foreach(player in level.players) {
                        
                          if( isAlive(player) && player != self || (player.team != self.team && level.teamBased) ){
                              if(distance(player.origin, predictedLoc) < radius)
                              	self iprintln("Shot ^6" + int(distance(self.origin, player.origin)*0.0254) + " ^7meters off of ^6" + player.name);
                          }
                      } 
              	}
              }
              

              I don't know why you use a maximum distance, everyone can be hit if you don't have a limit (like in my servers, in my server you can hit enemy to close).
              The attacker is not defined in this function. I don't know what is the point of calling the attacker.

              mikzyundefined Offline
              mikzyundefined Offline
              mikzy
              Banned
              wrote on last edited by
              #6

              Sorex my bad, i completely rushed the code and did not take a second to relook and fix stuff. i take blame 🙂

              1 Reply Last reply
              1

              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


              • Login

              • Don't have an account? Register

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