Announcement

Collapse
No announcement yet.

Get speed/velocity to pass to menu

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

    Get speed/velocity to pass to menu

    Howdy folks!
    ok, so i've got the basics of my HUD down, Current/Max hp, Current/Max ammo and weapon name from .INT file, but i cant for the life of me find out how to pass current movement speed to a text field (think of it in terms of a racing games speed counter). tried a number of possibilities but no joy at all

    below: my offering to anyone who needs it, code sample for passing hp/max ammo/max and weapon name to text fields obviously anything tagged with MC needs to be referenced since those are my clip names
    Code:
    Weapon = UTWeapon(UTP.Weapon);
    if (Weapon != none && UTV == none)
    {
    	if (Weapon != LastWeapon)
    	{
    		if (Weapon.AmmoDisplayType == EAWDS_None)
    			AmmoTF.SetText("");
    		//i = (Weapon.MaxAmmoCount > 50 ? 50 : Weapon.MaxAmmoCount);
    		//MaxAmmoMC.GotoAndStopI(51 - i);
    		WeaponMC.SetVisible(true);
    		WeaponMC.GotoAndStopI(Weapon.InventoryGroup);
    		WeaponNameTF.SetString("text", ""$UTWeapon(UTP.Weapon).PickupMessage);
    		LastWeapon = Weapon;
    	}
    	//i = Weapon.GetAmmoCount();
    	//if (i != LastAmmoCount)
    	//{
    	//	LastAmmoCount = i;
    	//	AmmoCountTF.SetText(i);
    	//	if (i > 50)
    	//		i = 50;
    	//	AmmoBarMC.GotoAndStopI(51 - i);
    	//	AmmoBarMC.SetVisible(true);
    	//}
    }
    
    
    
    
    // AMMO  
    
    //If the cached value for Ammo percentage isn't equal to the current...
    if (LastAmmopc != GetPercentage(UTWeapon(UTP.Weapon).AmmoCount, UTWeapon(UTP.Weapon).MaxAmmoCount)) 
    {
    //...Make it so...
    LastAmmopc = GetPercentage(UTWeapon(UTP.Weapon).AmmoCount, UTWeapon(UTP.Weapon).MaxAmmoCount);
    //...Update the bar's xscale (but don't let it go over 100)...
    AmmoBar_MC.SetFloat("_xscale", (LastAmmopc > 100) ? 100.0f : LastAmmopc);
    //...and update the text field
    AmmoTF.SetString("text", ""$UTWeapon(UTP.Weapon).AmmoCount);
    MaxAmmoTF.SetString("text", ""$UTWeapon(UTP.Weapon).MaxAmmoCount);
    //}
    
    
    
    // HEALTH
    
    //If the cached value for Health percentage isn't equal to the current...
      if ( LastHealthpc != GetPercentage( UTP.Health, UTP.HealthMax ) ) 
      {
        //...Make it so...
        LastHealthpc = GetPercentage( UTP.Health, UTP.HealthMax );
        //...Update the bar's xscale (but don't let it go over 100)...
        HPClippingMask.SetFloat( "_xscale", (LastHealthpc > 100) ? 100.0f : LastHealthpc );
        //...and update the text field
        HealthTF.SetString( "text", round(LastHealthpc)$"" );
    	MaxHealthTF.SetString( "text", round(UTP.HealthMax)$"" );
      }
    	
    }

    #2
    here you go
    PawnSpeed = (Pawn.Velocity << Pawn.Rotation).X;

    Comment


      #3
      Cheers tegleg! much appreciated.
      however using
      Code:
      //temp field name to pass it to
      WeaponNameTF.SetString( "text", ""PawnSpeed = (Pawn.Velocity << Pawn.Rotation).X );
      im getting Error, Call to 'SetString': Bad expression or missing ')'
      do i need to tried Var'ing off PawnSpeed with no luck, am i missin somthin here?

      Comment


        #4
        Try this instead:

        PawnSpeed = (Pawn.Velocity << Pawn.Rotation).X;

        WeaponNameTF.SetString("text", PawnSpeed);

        Comment


          #5
          Code:
          function TickHUD() 
          {
          
          local UTWeapon Weapon;
          local UTVehicle UTV;
          local PlayerController PC;
          local URailPawn UTP;
          
          local blah Pawnspeed;
            
          
            PC = GetPC();
          
          //We need to talk to the Pawn, so create a reference and check the Pawn exists
            UTP = URailPawn( GetPC().Pawn );
            
          if( UTP == None ) 
              return;
          
          PawnSpeed = (Pawn.Velocity << Pawn.Rotation).X;
           
          WeaponNameTF.SetString( "text", PawnSpeed);
          ive tried replacing blah with Gameinfo, worldinfo, pawn, UDKpawn, UTPawn and a few others and had no luck, what on earth am i variableing Pawnspeed as. without a "local blah pawnspeed" i get "pawnspeed bad command" but with it "Bad or missing expression in parenthesis for '='" so pawnspeed is a name correct? meaning i need to local/var it off to somthing.

          sorry for being a pain with this, im just a bit er, stuck as to what it needs to be.

          Comment


            #6
            Ok, this is what works for me:

            Code:
            function TickHud(float DeltaTime)
            {
                local UTPawn UTP;
                local PlayerController PC;
                local int Pawnspeed; // or float
            
                PC = GetPC();
                UTP = UTPawn(PC.Pawn);
            
                if( UTP == None ) 
            	return;
            
                PawnSpeed = (UTP.Velocity << UTP.Rotation).X;
                SpeedTF.SetString("text", string(PawnSpeed));
            }

            Comment


              #7
              excellent! thanks Matt. getting no issues with Pawnspeed now. however, issues calling to the string field.
              Code:
              WeaponNameTF.SetString( "text", ""PawnSpeed); //with or without the "" before pawnspeed
              gives Error, Type mismatch in Call to 'SetString', parameter 2

              Code:
              WeaponNameTF.SetString( "text", ""PawnSpeed = (UTP.Velocity << UTP.Rotation).X);
              gives Error, Call to 'SetString': Bad expression or missing ')'

              Comment


                #8
                read my code again - you're not putting the correct code. You must typecast PawnSpeed to a string first - this is the correct code:

                Code:
                 SpeedTF.SetString("text", string(PawnSpeed));

                Comment


                  #9
                  Matt You're a lifesaver mate, that works perfectly! Thankyou once again for the help
                  *posted the other reply while you were typing the one above ^^

                  Comment

                  Working...
                  X