Announcement

Collapse
No announcement yet.

A Rifle rack, or fun with setPos

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • A Rifle rack, or fun with setPos

    Finally (kinda) figured out how to do this.



    The sqf code begins as follows:

    _xpos = getPos AmmoTest02 select 0;
    _ypos = getPos AmmoTest02 select 1;

    _Rifle = "weaponholder" Createvehicle [ 9745.27, 3770.21, 0];
    _Rifle addWeaponCargo ["ACE_M16A4", 1];
    _Rifle setPos [_xpos, (_ypos)+0.3, 0.1];
    _Rifle setVectorUp [-1,0,0];
    _xpos = _xpos - 0.25;

    There are cleaner ways of getting five or however many rifles in a row - while operator, for example - but I figured this would work OK.

    The biggest limitation that I've found is that I don't know vector maths so using setVectorUp results in the rifle pointing up but always with the pistol grip pointing south. I tried using setVectorDirAndUp and managed to get two other directions but again the maths woes hit so I have not really got a clue as to how to get the rifles to face in any direction possible.

    Can anyone shed some light on setVectorUp/setVectorDirAndUp etc so I can place the rack just about anywhere?

    -BoD
    BarnacleofDoom

    One shot - One miss!

  • #2
    Re: A Rifle rack, or fun with setPos

    Uh not to steal your thunder but

    http://www.armaholic.com/page.php?id=666

    You could just use that?
    sigpic
    Pride/Shame of the PLA

    Comment


    • #3
      Re: A Rifle rack, or fun with setPos

      No thunder stealing at all. Just d/l'ed the file, hopefully it'll make things easier and/or show me how to fix my problem.

      Thanks!

      EDIT: Sadly, no, it doesn't help. Looked at the scripting and whilst it certainly makes placing weapons easier it doesn't really help me to do what I am after. Thanks though!
      Last edited by BarnacleofDoom; 02-18-2009, 05:40 PM.
      BarnacleofDoom

      One shot - One miss!

      Comment


      • #4
        Re: A Rifle rack, or fun with setPos

        after figuring out my parachute-control scripts, I have concluded that the setVectorUp command requires a combination of caffeine and hallucinogenics before it will start making sense, neither of which I keep on hand unfortunately.

        if you really want to try to figure it out, there is an old forum topic that may have some info:

        http://www.flashpoint1985.com/cgi-bi...hl=setvectorup

        Comment


        • #5
          Re: A Rifle rack, or fun with setPos

          Great, now I can make a mission that shows the rifle in the back of a pickup window! Like any true American 2nd amendment lover! All we need now is a way to get beer cans set on a hat on players head and we'll be set for some good old American fun.
          Never tell people how to do things. Tell them what to do and they will surprise you with their ingenuity. - General George S. Patton.

          Comment


          • #6
            Re: A Rifle rack, or fun with setPos

            I wanna sit in the back of the pickup playing a banjo! :D
            BlackDog1




            "What we do in life... echoes in eternity!"

            Comment


            • #7
              Re: A Rifle rack, or fun with setPos

              Originally posted by GeneralCarver View Post
              Great, now I can make a mission that shows the rifle in the back of a pickup window! Like any true American 2nd amendment lover! All we need now is a way to get beer cans set on a hat on players head and we'll be set for some good old American fun.
              We need some U.S. map for ArmA, I mean there are like 238130 desert maps, 2 german maps (Schmalfelden and that other one), 1 french (Avignon) map and 381030131 "fantasy" maps.

              I know Opteryx worked on a nevada map (terrain has been released), but it seems he moved to other projects.

              I'm thinking of a modern civil war mission :) .

              I also don't remember seing any US map for OFP.
              Last edited by Skychief; 02-23-2009, 09:47 AM.

              Skychief/Icewind.123/Icewindo
              Stargate Mod / Random stuff

              Comment


              • #8
                Re: A Rifle rack, or fun with setPos

                Originally posted by Skychief View Post
                We need some U.S. map for ArmA,
                Check out Nabukonodexa, it's not perfect, but you could use it...
                "Never forget that you are there to SERVE the soldiers. Listen to your NCOs and always do the right thing." -My Father
                "http://www.youtube.com/watch?v=wGNxHMFjigA"
                "http://www.youtube.com/watch?v=Ce0c6qVnJE4"
                "http://www.youtube.com/watch?v=i2Lpc9vTnqU"
                "http://www.youtube.com/watch?v=xEzc9fB8xPo"
                "http://www.youtube.com/watch?v=4tdCTP_ae_8"
                "http://www.youtube.com/watch?v=RrmoSZgYaFw"

                Comment


                • #9
                  Re: A Rifle rack, or fun with setPos

                  We could pretend that one of the A.C.E islands is a use island and play out a red dawn scenerio where people are random civilians or military personel who can hook up with others. hide in the woods for a little and do some guerilla stuff. endless possibilities with ArmA, and so if you are interested get together with the AMAZING editing group we have here at ArmA and write out a story board of a mission. I know we can come up with something really good.
                  FORMER 22ND RRR/FORMER 1ST JTOC/ ALWAYS A TACTICALGAMER


                  Spartan 4

                  Comment


                  • #10
                    Re: A Rifle rack, or fun with setPos

                    Originally posted by viper1986 View Post
                    We could pretend that one of the A.C.E islands is a use island and play out a red dawn scenerio where people are random civilians or military personel who can hook up with others. hide in the woods for a little and do some guerilla stuff. endless possibilities with ArmA, and so if you are interested get together with the AMAZING editing group we have here at ArmA and write out a story board of a mission. I know we can come up with something really good.
                    I agree with this and support it, we can assign Pathfinders as "Generals" of however many factions there are and have it as a weekly event with background storyboard. Whomever wins or loses will determine the progress of the factions and the progress of the story. Kinda like Evolution but longer, better and more oriented towards teamwork rather than Ramboness.

                    Comment


                    • #11
                      Re: A Rifle rack, or fun with setPos

                      As useless as it may be, but when I couldn't sleep yesterday, I came up with a solution that works reasonably well:

                      Code:
                      ; Weapons type
                      weapon = "m16a2";
                      amount = 5;
                      ; how much space between each weapon
                      spacing = 0.2;
                      ; direction in which the weapons face
                      dir = 0;
                      ; offset from the position of "this"
                      xoff = 0.0;
                      yoff = 0.0;
                      ; this offset is for an ammo box
                      zoff = 0.07;
                      
                      cosDir = cos(dir);
                      sinDir = sin(dir);
                      dx = spacing * cosDir;
                      dy = spacing * sinDir;
                      this setDir dir;
                      xpos = getPos this select 0;
                      ypos = getPos this select 1;
                      i = 0;
                      while { i < amount} do {
                      	_holder = "weaponholder" Createvehicle [ 0, 0, 0];
                      	_holder addWeaponCargo [weapon, 1];
                      	_holder setPos [ xpos - cosDir * xoff + sinDir * yoff, ypos + sinDir * xoff + cosDir * yoff, zoff];
                      	_holder setVectorUp [0, 1, 0];
                      	_holder setVectorDir [sinDir, cosDir, 0];
                      	ypos = ypos + dy;
                      	xpos = xpos - dx;
                      	i = i + 1;
                      };
                      If you use this in the init of an ammo box, for example, and adapt the xoff and yoff, then you get pretty exactly what you have in the image from the 1st post. Unfortunately, for every direction of the underlying box etc., there is some weird shift that I couldn't figure out, so if you change the angle (dir) then the offsets might need to be adapted. It may be more useful if it was an actual function, but it's been a while since my OFP scripting times and I couldn't bother. ;-)

                      Comment


                      • #12
                        Re: A Rifle rack, or fun with setPos

                        Thanks a lot, Bert - I'd gotten it working but my solution is less elegant than yours is - I basically played around with SetVectorDirAndUp until I was able to figure out how to achieve both the vertical position that I was after and the desired weapon orientation. I did try the solution that you have

                        _holder setVectorUp [0, 1, 0];
                        _holder setVectorDir [sinDir, cosDir, 0];

                        but for some reason the setVectorUp would work normally and then the setVectorDir would instantly remove whatever effect the setVectorUp had on the object. I'm not sure why and that's why I ended up going the setVectorDirAndUp route.

                        The only other thing that I am going to play around with is getting the script to obtain the box's direction rather than having to create a script for each separate heading (for two or more boxes).

                        -BoD
                        BarnacleofDoom

                        One shot - One miss!

                        Comment


                        • #13
                          Hooray for Bert!

                          Bert,

                          Your code made things a lot easier... Here's the (slightly modified) result:



                          Here's the required code:

                          Code:
                          _xpos = _this select 0;
                          _ypos = _this select 1;
                          _zpos = _this select 2;
                          _dir = _this select 3;
                          _magdir = _this select 4;
                          _xoff = _this select 5;
                          _yoff = _this select 6;
                          _cosDir = cos(_dir);
                          _sinDir = sin(_dir);
                          _cosmagDir = cos(_magdir);
                          _sinmagDir = sin(_magdir);
                          _weaparray = ["ACE_AK47", "ACE_AKM", "ACE_AKM_Cobra", "ACE_AKMS", "ACE_AKMS_Cobra", "ACE_AK74", "ACE_AKS74"];
                          _magtype = "ACE_30Rnd_762x39_B_AK";
                          
                          _randomweap = random 7;
                          _randomweap = _randomweap - (_randomweap % 1);
                          
                          _cache = "weaponHolder" Createvehicle [ 10, 10, 0];
                          _cache setPos [ _xpos, _ypos, _zpos-0.3 ];
                          _cache setVectorUp [-1, 0, 0];
                          _cache setVectorDir [_sinDir, _cosDir, 0];
                          _cache addWeaponCargo [_weaparray select _randomweap, 1];
                          
                          if ( _randomweap < 4.5 ) then {_magtype = "ACE_30Rnd_762x39_B_AK"} else {_magtype = "ACE_30Rnd_545x39_B_AK"};
                          
                          _magnumber = random 5;
                          _magnumber = _magnumber - (_magnumber mod 1);
                          if ( _magnumber < 1 ) then {_magnumber = 1 };
                          
                          _cacheMags = "weaponHolder" Createvehicle [ 10, 10, 0];
                          _cacheMags setPos [ _xpos - _cosmagDir * _xoff + _sinmagDir * _yoff, _ypos + _sinmagDir * _xoff + _cosmagDir * _yoff, _zpos];
                          _cacheMags setVectorDir [_sinDir, _cosDir, 0];
                          _cacheMags addMagazineCargo [_magtype, _magnumber];
                          As you can see, I set it up to pass in a position, direction, and a magazine direction and offset. The rifle selection is purposely randomized for more fun and games, as the intent is for OPFOR to spawn in game with limited weapons - pistols or bare hands - and have to forage for weapons.

                          Any suggestions to help streamline the code would be welcome. Oh, and this code should be run on the server only, right? i.e. add in something along the lines of !isServer then exitWith[] or whatever it is (have to go look it up).

                          -BoD
                          Last edited by BarnacleofDoom; 03-07-2009, 09:39 PM. Reason: slightly edit code to reflect present version
                          BarnacleofDoom

                          One shot - One miss!

                          Comment


                          • #14
                            Re: A Rifle rack, or fun with setPos

                            Not much code there and I assume it's only executed a couple of times during a mission, so unless you're a big fan of good looking code I wouldn't waste much time streamlining it. If it works it works! :)

                            Making sure it's only run on server is a good idea. I believe the line you're looking for is:
                            Code:
                            if (!isServer) exitWith {};

                            Comment


                            • #15
                              Re: A Rifle rack, or fun with setPos

                              Originally posted by Fincuan
                              Making sure it's only run on server is a good idea.
                              Maybe: when I did this exact same thing earlier (placing actual weapons), I think anything regarding ammo/weapon cargo only worked right when it was executed on both client and server. I believe in the past there has been some confusion with regards to the locality of these commands, and on which machines they should need to be run. Feel free to test and confirm for sure though Barnacle!

                              Looks neat though :)

                              Comment

                              Connect

                              Collapse

                              TeamSpeak 3 Server

                              Collapse

                              Advertisement

                              Collapse

                              Twitter Feed

                              Collapse

                              Working...
                              X