Announcement

Collapse
No announcement yet.

weapon switching event.

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

    weapon switching event.

    im trying to play an animation when i switch to a weapon. im sure it possable afterall u4e did it with the katana. problem is i have no access to that code. but i digress. if anyone here knows what an event would be that activated when i switch to a certain weapon it would be very helpfull. thank you.

    #2
    When the player switches weapons, all inventory items are notified via Inventory.OwnerEvent(). If you want an Inventory item to do something when the owner changes weapons, you can override OwnerEvent - i.e.
    Code:
    function OwnerEvent(name EventName)
    {
        if (EventName == 'ChangedWeapon')
        {
            // do something with current weapon here
        }
        // make sure to call the overridden method in the super-class
        super.OwnerEvent(EventName);
    }
    (Also don't forget to check the current weapon if you want it to act only for a specific weapon or type of weapon.)

    On the other hand, if you are coding it into the weapon, you could override the BringUp() function, or Timer(), which is called BringUpTime seconds after BringUp. Usually Timer would execute around about when the select animation has finished, and also when the put-down animation has finished (checking ClientState == WS_BringUp would ensure that it's the event you want).

    When you say "play an animation", do you mean you want the weapon to play an animation, or some other Actor? If you want the weapon to play a specific animation when you switch to it, you can override the SelectAnim property... Or do you mean you want the animation to play when the weapon has finished being taken out?

    Obviously, overriding the default value for SelectAnim would be a lot simpler than overriding a function, if it does what you want.

    Comment


      #3
      yes i want it to play an animation on another thing not the weapon itself. kinda goes like this
      switch to weapon---->summon pawn----->play animation on summoned pawn--->unpossess current pawn----->possess new pawn---->play another animation on summoned pawn---->remove old pawn---->bring out the weapon.
      if you dont know this is my guyver mod. so what would be the best way of going about this?
      when you say override owner event does that mean this class should be a subclass of inventory and not part of the weapon? would that be a part of a mutator?
      when you say check if its the weapon should i say like if (weapon == guyver) or is it not weapon but something else?

      i know i have a lot of question. every answer just gives me more questions sorry
      but thank you very much for all the info you have given me so far.

      --edit--
      oh a kinda side question but...instigator.location returns a vector so how would i set something at 16 UU behind instigator.location? is it like thisthingies.location = instigator.location - (x = 0, y = 0, z = 16). im looking to make a for loop that will put it 16 (or so i may change it) UU behind the instigator (the one who switched weapons) and then move it 1 or 2 im not sure UU untill it is at instigator.location and then it unpossess the instigator puts it in the pawn and plays an animation and gets rid of the old pawn.
      im thinking it should be something like this:
      Code:
      var byte i
      for (i= 16; i<0 ; i--) {
               spawnedpawn.location = instigator.location - (x=0, y=0, z=i)
      }
      but i dont want it to go super fast either so if i could use ticks in there to or something to make it noticable that it even did it that would be nice too. because im sure a for loop goes very fast. i know in basic you could just make it count to a realy high number and it would slow it down but i dont know if thats the case in unreal. i dont know the speed of a tick nor am i all that sure how to use it. i dont want it to be too slow but not too fast.

      any help would be appriciated.

      Comment


        #4
        Originally posted by the_ultimate_sa
        when you say override owner event does that mean this class should be a subclass of inventory and not part of the weapon?
        Weapon is a sub-class of inventory, so if you are coding it into the weapon, you can override OwnerEvent() in your weapon class. It might be better to override BringUp(), though.
        when you say check if its the weapon should i say like if (weapon == guyver) or is it not weapon but something else?
        If you want to check that the current weapon is the weapon you're putting the code into, use:
        Code:
        if (Instigator.Weapon == self)
        i know i have a lot of question. every answer just gives me more questions sorry
        but thank you very much for all the info you have given me so far.

        No problem.

        oh a kinda side question but...instigator.location returns a vector so how would i set something at 16 UU behind instigator.location? is it like thisthingies.location = instigator.location - (x = 0, y = 0, z = 16).
        Location is declared as a const variable, so it can only be changed by native code. To set an Actor's location, you must use the SetLocation() function.

        Also, Vector literals are expressed as:
        Code:
        vect(x, y, z)
        where x, y and z must be numbers.

        UnrealScript_Vector_Maths might be worth a read.

        Extract:
        (How to)...find a point that's at a certain distance from a starting point in a given direction? :

        LocationTarget = LocationStart + vector(Rotation) * Distance;


        i know in basic you could just make it count to a realy high number and it would slow it down but i dont know if thats the case in unreal. i dont know the speed of a tick nor am i all that sure how to use it. i dont want it to be too slow but not too fast.
        Making it count to a really high number wouldn't work. If anything, it would slow down the entire game - no other processing or rendering could be done while it is in the for loop.

        The speed of a tick depends on the framerate. If you look at the definition of Tick() in Engine.Actor:
        Code:
        event Tick( float DeltaTime );
        you'll see the parameter "DeltaTime". DeltaTime is the amount of time that has passed since the last Tick(), measured in seconds. So, for example, if you wanted to move X units per second, the amount to move in this tick would be X * DeltaTime.

        If you want the Actor to move gradually into position, it would probably be easier to move the Actor by changing its Physics type (using SetPhysics()) and its Velocity (which is measured in UU per second), but I'm not sure exactly how you'd get it to stop moving when it's in position.

        Using SetLocation() to move the Actor could cause it to move right through a solid object (or onto a solid object).

        Comment


          #5
          well im actualy wanting it to move through a solid object (the user) going through a wall or something wouldnt be any big deal. i ment setlocation sorry. *checks the site on vector math.* hmm seems as though vectors only deal with movement and not position. does location return a vector?

          Comment


            #6
            Location of a Actor is a XYZ Vector postion in 3D space

            Comment


              #7
              Originally posted by the_ultimate_sa
              well im actualy wanting it to move through a solid object (the user) going through a wall or something wouldnt be any big deal. i ment setlocation sorry. *checks the site on vector math.* hmm seems as though vectors only deal with movement and not position. does location return a vector?
              When you have a question about a variable or function, you should first check the UT2004 source code. It would have told you (in Engine.Actor):
              Code:
              var(Movement) const vector Location; // Actor's location; use Move to set.
              and also in Engine.Actor:
              Code:
              native(267) final function bool SetLocation( vector NewLocation );
              Originally posted on the Unreal Wiki
              In order to represent physical quantities such as position and momentum in more than one dimension, we must describe them in a way to represent these properties. This is called a vector.
              A vector is just a structure, and can basically be used for anything. They are most commonly used to represent locations and velocities (usually in UU per second). Vector is defined in Engine.Object:
              Code:
              struct Vector
              {
                  var() config float X, Y, Z;
              };
              Also, if you're wanting it to move through solid objects, you may have to set it to not collide with/block actors.
              Code:
              native(262) final function SetCollision( optional bool NewColActors, optional bool NewBlockActors, optional bool NewBlockPlayers );

              Comment


                #8
                ya i just saw that i came to edit it out. well i have some of it biggest problem is inside of vect() it will not take any variables. so if i have vect(0, 0, i) it says i have no z componet. so far i have it so i think it will work (it compiles anyways) but i have yet to take into account deltatime and im not sure where to put it. i have it in the bringup function (which reminds me what the option to switch out of? putdown?) but i dont know where exactly it belongs in that
                i have this:
                Code:
                simulated function BringUp(optional Weapon PrevWeapon)
                {
                local vector MyLocal;
                local controller oldpawn;
                local pawn deleteme;
                local GuyverPawn this;
                local byte i;
                if (instigator.weapon == self) {
                i = 16;
                if (instigator != None) {
                	MyLocal = instigator.location;
                	oldpawn = instigator.controller;
                	deleteme = instigator;
                }
                this = spawn(class'GuyverPawn',,,mylocal - vect(0, 0, 16));
                do{
                	this.setlocation(this.location - vect(0,0,1) );
                	i -= 1;
                } Until (i < 1);
                	instigator.controller.unpossess();	
                	this.controller = oldpawn;
                	deleteme.destroy();
                    Super.BringUp(PrevWeapon);
                    }
                    else
                    Super.BringUp(PrevWeapon);
                }
                so i figure this will go very fast so i want to slow it down.

                btw would it work to set "bcollidesworld" and "bcollidesactor" to false in default options of GuyverPawn? or probly better yet set this.collidesworld to false and this.collidesactor to false then set them back once i possess it?

                Comment


                  #9
                  Originally posted by the_ultimate_sa
                  inside of vect() it will not take any variables.
                  Try it like so:
                  Code:
                      vect(0,0,1) * myZvariable;

                  Comment


                    #10
                    Originally posted by the_ultimate_sa
                    well i have some of it biggest problem is inside of vect() it will not take any variables.
                    Yeah, vect() is the way of writing vector literals. Literals can't have variables in them - they're basically constants. You can, however declare a Vector variable and set it's components individually.

                    You could also do it like Xyx suggests.

                    Code:
                    this = spawn(class'GuyverPawn',,,mylocal - vect(0, 0, 16));
                    Is it your intention to spawn the GuyverPawn 16 UU below the player? If you wanted to find the point 16 UU behind the player, that'd be something like:
                    Code:
                    mylocal - vector(Instigator.Rotation) * -16
                    Code:
                    do{
                    	this.setlocation(this.location - vect(0,0,1) );
                    	i -= 1;
                    } Until (i < 1);
                    Not only will this go very fast, it will go instantly. I suggest you create a "DesiredLocation" variable in GuyverPawn, and set it when you spawn the GuyverPawn. Then, in GuyverPawn.Tick(), gradually move it toward the DesiredLocation. (Maybe there's a built-in way of doing this I don't know of?)
                    btw would it work to set "bcollidesworld" and "bcollidesactor" to false in default options of GuyverPawn? or probly better yet set this.collidesworld to false and this.collidesactor to false then set them back once i possess it?
                    That should work. You'll probably also need to override bBlockActors.

                    Comment


                      #11
                      alright i have a tick event in guyverpawn looking a bit like this:
                      Code:
                      event tick(float deltatime) {
                      local controller oldpawn;
                      local pawn deleteme;
                      local byte i;
                      i=self.location.z;
                      if (instigator != None) {
                      	oldpawn = instigator.controller;
                      	deleteme = instigator;
                      }
                      do{
                      	self.setlocation(self.location - vector(Instigator.Rotation) * -i );
                      	i -= 1;
                      } Until (i < 0);
                      	if (self.location == instigator.location) {
                      	instigator.controller.unpossess();	
                      	self.controller = oldpawn;
                      	deleteme.destroy();
                      	self.bCollideWorld = True;
                      	self.bBlockActors = True;
                      	}
                      }
                      problem is i dont know how to call up this event from the bringup event. i put in this:

                      Code:
                      this.tick();
                      is that how you are supposed to reference it? because i get this error
                      Error, Call to 'tick': bad or missing parameter 1

                      Comment


                        #12
                        What is a "bringup event"?

                        Anyway, you're not supposed to call Tick(). Why do you want to call it and (more importantly) what do you want to do?

                        Comment


                          #13
                          Originally posted by Xyx
                          What is a "bringup event"?

                          Anyway, you're not supposed to call Tick(). Why do you want to call it and (more importantly) what do you want to do?
                          BringUp() is the function in Weapon that is called when the weapon is taken out.
                          Originally posted by the_ultimate_sa
                          Code:
                          local byte i;
                          i=self.location.z;
                          The Z component of vector is a float, so using a byte is going to cause major loss of precision. (Bytes can only be from 0 to 255, with no fractions.) Also, Z could be thousands of UU - are you sure that is what you want to use?

                          problem is i dont know how to call up this event from the bringup event.
                          Is the event Tick in GuyverPawn? If it is, you don't need to trigger it from BringUp, as it would start immediately after the GuyverPawn is spawned (in BringUp).

                          The reason Tick is declared as an "event" in Actor is that it is called by the Engine - every game tick, so you don't need to call it at all.

                          Code:
                          do{
                          	self.setlocation(self.location - vector(Instigator.Rotation) * -i );
                          	i -= 1;
                          } Until (i < 0);
                          You're still doing almost the same thing as before, except you're doing it every Tick now! What I meant was to move the Actor a little bit each time Tick was called.

                          Where exactly do you want the Actor to spawn, and where do you want it to move to?

                          I'll code up an example Tick function soon...

                          Edit: here it is (may not work, though)
                          Code:
                          // in the class of Actor you want to move
                          event Tick(float DeltaTime)
                          {
                              local vector dif;
                              local float distance;
                              
                              dif = DesiredLocation - Location;
                              // (DesiredLocation being a vector representing where you want it to go)
                              distance = VSize(dif);
                              // (VSize gets the length of the vector)
                              if (distance == 0)
                              {
                                  // already there
                                  Disable('Tick');
                                  return;
                              }
                              SetLocation(Location + Normal(dif) * FMin(Speed * DeltaTime, distance));
                              // where Speed is the number of UU per second you want it to move.
                              // Normal() gets a vector with a length of one, pointing in the same direction
                              // Use FMin to limit the distance so that the Actor doesn't move too far.
                          }

                          Comment


                            #14
                            well it compiled fine. untill i get my unreal disk i wont be able to test if it runs fine. however i was wondering:
                            since i used the tick in guyverpawn does instigator in that event still refer to the user of the weapon or is it now pointing at guyverpawn? and whats the dif between instigator and user.

                            oh and thank you again you have been a load of help ^_^ im still kinda new to this and just kinda getting into object oriented programing (previously was in basic programing. so some of my thought proccesses are still basic) but you have been very hepfull.

                            Comment


                              #15
                              Originally posted by the_ultimate_sa
                              since i used the tick in guyverpawn does instigator in that event still refer to the user of the weapon or is it now pointing at guyverpawn?
                              Well...
                              Originally posted in Chain_Of_Events_When_Spawning_Actors
                              the Actor's Instigator is set to the spawning actor's Instigator
                              so if you spawned the GuyverPawn from your weapon, the GuyverPawn's Instigator variable will probably refer to the weapon's Instigator. It might be different for Pawns, though.
                              Originally posted by the_ultimate_sa
                              and whats the dif between instigator and user.
                              In Inventory.GiveTo(), Instigator is set to the Pawn that the item is being given to, so Instigator refers to the user of the weapon/inventory item.

                              Note that it is possible to set a weapon's Instigator to some other Pawn, in which case that other Pawn would get the credit for every kill you get with that weapon. :alien:

                              Comment

                              Working...
                              X