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 676 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
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
      • Matrixundefined Offline
        Matrixundefined Offline
        Matrix Plutonium Staff
        replied to mikzy 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
          • mikzyundefined Offline
            mikzyundefined Offline
            mikzy Banned
            replied to Matrix on last edited by
            #5

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

            1 Reply Last reply
            1
            • mikzyundefined Offline
              mikzyundefined Offline
              mikzy Banned
              replied to Sorex 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

              • Login

              • Don't have an account? Register

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