Advertisement
Guest User

Tyler Howard - Odyssey HUD Unrealscript

a guest
Mar 5th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class OdysseySWFWrapper extends GFxMoviePlayer;
  2.  
  3. //Create a Health Cache variable
  4. var float LastHealthpc;
  5.  
  6. var float healthUpdateCooldown;
  7. var float messageCooldown;
  8.  
  9. // Create cache variables for firing effect
  10. var float xPos;
  11. var float yPos;
  12. var bool storyBoardFlag;
  13. var float alpha;
  14.  
  15. //Create variables to hold references to the Flash MovieClips
  16. //and Text Fields that will be modified
  17. var GFxObject HealthMC, HealthBarMC, BeltMC, TrimMC;
  18.  
  19. //var GFxObject HealthTF;
  20. //var GFxObject AmmoMC, AmmoTF;
  21. var GFxObject CenterTextTF1, CenterTextMC1, ReticleMC, ReticleMC1;
  22.  
  23. var GFxObject Crystal_Jump, Crystal_Glide, Crystal_AirBlade, Crystal_HeatTolerance, Crystal_Contextual, Crystal_LavaMine, Crystal_WaterWalking, Crystal_LightningPulse;
  24.  
  25. var GFxObject GC_A, GC_B, GC_X, GC_Y;
  26.  
  27. var bool bLastFrameInterpActor;
  28.  
  29.  
  30.  
  31. //tracking for "ghost controller" pop-up functionality
  32. var int lastGhostControllerCount[6];    //0: hasn't been picked up yet - 1: been picked up, displaying - 2: been picked up, displayed
  33. var float ghostControllerAlpha;
  34. var float ghostControllerAlphaVelocity;
  35.  
  36. //0=jump, 1=glide, 2=air blast, 3=terraforming?, 4=lava mine, 5=lightning
  37. var bool bShowHUD;
  38.  
  39.  
  40. //  Function to round a float value to an int
  41. function int roundNum(float NumIn)
  42. {
  43.     local int iNum;
  44.     local float fNum;
  45.      
  46.     fNum = NumIn;
  47.     iNum = int(fNum);
  48.     fNum -= iNum;
  49.      
  50.     if (fNum >= 0.5f)
  51.     {
  52.         return (iNum + 1);
  53.     }
  54.     else
  55.     {
  56.         return iNum;
  57.     }
  58. }
  59.  
  60. //  Function to return a percentage from a value and a maximum
  61. function int getpercent(int val, int max)
  62. {
  63.     return roundNum((float(val) / float(max)) * 100.0f);
  64. }
  65.  
  66. function Init(optional LocalPlayer PC )
  67. {
  68.     //Start and load the SWF Movie
  69.     super.Start();
  70.     Advance(0.f);
  71.      
  72.     //Set the cahce value so that it will get updated on the first Tick
  73.     LastHealthpc = -201;
  74.      
  75.     //Load the references with pointers to the movieClips and text fields in the .swf
  76.    
  77.     HealthBarMC = GetVariableObject("_root.healthBar");
  78.     HealthMC = GetVariableObject("_root.HealthBarOutline");
  79.     BeltMC = GetVariableObject("_root.Belt");
  80.     TrimMC = GetVariableObject("_root.Trim");
  81.  
  82.     //CenterTextMC1 = GetVariableObject("_root.messageMC");
  83.     CenterTextTF1 = GetVariableObject("_root.messages");
  84.     ReticleMC = GetVariableObject("_root.reticle");
  85.     ReticleMC1 = GetVariableObject("_root.reticleOther");
  86.     alpha = GetVariableNumber("_root.fade");
  87.    
  88.  
  89.     ReticleMC1.SetVisible(false);
  90.  
  91.     Crystal_Jump = GetVariableObject("_root.Crystal_Jump");
  92.     Crystal_Glide = GetVariableObject("_root.Crystal_Glide");
  93.     Crystal_AirBlade = GetVariableObject("_root.Crystal_AirBlade");
  94.     Crystal_HeatTolerance = GetVariableObject("_root.Crystal_HeatTolerance");
  95.     Crystal_Contextual = GetVariableObject("_root.Crystal_Contextual");
  96.     Crystal_LavaMine = GetVariableObject("_root.Crystal_LavaMine");
  97.     Crystal_WaterWalking = GetVariableObject("_root.Crystal_WaterWalking");
  98.     Crystal_LightningPulse = GetVariableObject("_root.Crystal_LightningPulse");
  99.  
  100.     ActionScriptVoid("setMessageOff");
  101.     messageCooldown = 0.0;
  102.  
  103.     lastGhostControllerCount[0] = 0;
  104.     lastGhostControllerCount[1] = 0;
  105.     lastGhostControllerCount[2] = 0;
  106.     lastGhostControllerCount[3] = 0;
  107.     lastGhostControllerCount[4] = 0;
  108.     lastGhostControllerCount[5] = 0;
  109.  
  110.     //hide X Y B A
  111.     GC_X = GetVariableObject("_root.ghostController_X");
  112.     GC_Y = GetVariableObject("_root.ghostController_Y");
  113.     GC_B = GetVariableObject("_root.ghostController_B");
  114.     GC_A = GetVariableObject("_root.ghostController_A");
  115.  
  116.     ghostControllerAlpha = GetVariableNumber("_root.ghostControllerFade");
  117.  
  118.     ActionScriptVoid("setControllerFade");
  119.  
  120.     GC_X.setVisible(false);
  121.     GC_Y.setVisible(false);
  122.     GC_B.setVisible(false);
  123.     GC_A.setVisible(false);
  124.  
  125.     super.Init(PC);
  126. }
  127.  
  128. //Called every update Tick
  129. function TickHUD( float dt )
  130. {
  131.     local UTPawn UTP;
  132.     local Odyssey_PlayerController OPC;
  133.     local int i;
  134.  
  135.     OPC = Odyssey_PlayerController(GetPC());
  136.  
  137.     if (OPC.IsDead())
  138.     {
  139.         HealthBarMC.SetFloat("_xscale",0);
  140.         SetCenterText("Press 'A' to Respawn");
  141.         messageCooldown = 0.1;
  142.     }
  143.      
  144.     //We need to talk to the Pawn, so create a reference and check the Pawn exists
  145.     UTP = UTPawn(OPC.Pawn);
  146.     if (UTP == None)
  147.     {
  148.         LastHealthpc = -201;    //force it to a value so it'll update on the first tick, similar to how it's done in Init()
  149.         return;
  150.     }
  151.  
  152.     //If the cached value for Health percentage isn't equal to the current...
  153.     if (LastHealthpc != getpercent(UTP.Health, UTP.HealthMax))
  154.     {
  155.         //...Make it so...
  156.        
  157.         //LastHealthpc = getpercent(UTP.Health, UTP.HealthMax);
  158.         LastHealthpc = (( getpercent(UTP.Health, UTP.HealthMax) - LastHealthpc ) * 0.1f) + LastHealthpc;
  159.        
  160.         //...Update the bar's xscale (but don't let it go over 100)...
  161.         if (LastHealthpc <= 0)
  162.         {
  163.             HealthBarMC.SetFloat("_xscale",0);
  164.         }
  165.         else
  166.         {
  167.             HealthBarMC.SetFloat("_xscale", (LastHealthpc > 100) ? 100.0f : LastHealthpc);
  168.         }
  169.     }
  170.  
  171.     if(messageCooldown < 0){
  172.         ActionScriptVoid("setMessageOff");
  173.     }
  174.     else{
  175.         messageCooldown -= dt;
  176.     }
  177.  
  178.     if(OPC != none)
  179.     {
  180.         if(bShowHud)
  181.         {
  182.  
  183.             for( i = 0; i < 6; i++)
  184.             {
  185.                 //check if it's different, show/hide
  186.                 if(lastGhostControllerCount[i] == 0 && OPC.ghostControllerCount[i] == 1)
  187.                 {
  188.                     //Text is placeholder - replace with hide/show commands later on
  189.  
  190.                     //show
  191.                     switch(i)
  192.                     {
  193.                     case 0:
  194.                         GC_A.setVisible(true);
  195.                         SetCenterText("Press A to jump.");
  196.                         break;
  197.                     case 1:
  198.                         GC_A.setVisible(true);
  199.                         SetCenterText("Hold A in midair to glide.");
  200.                         break;
  201.                     case 2:
  202.                         GC_X.setVisible(true);
  203.                         SetCenterText("Press X to shoot an air blast.");
  204.                         break;
  205.                     case 3:
  206.                         GC_X.setVisible(true);
  207.                         SetCenterText("Look directly at a pillar and press X to raise it.");
  208.                         break;
  209.                     case 4:
  210.                         GC_B.setVisible(true);
  211.                         SetCenterText("Press B to lay a lava mine.");
  212.                         break;
  213.                     case 5:
  214.                         GC_Y.setVisible(true);
  215.                         SetCenterText("Press Y to cause a magnetic field.");
  216.                         break;
  217.                     }
  218.  
  219.                     messageCooldown = 1000.0;
  220.                     ghostControllerAlpha = 0.f;
  221.                     ghostControllerAlphaVelocity = 0.01;
  222.                 }
  223.                 else if(lastGhostControllerCount[i] == 1 && OPC.ghostControllerCount[i] == 2)
  224.                 {
  225.                     /*switch(i)
  226.                     {
  227.                     case 0:
  228.                         //hide a
  229.                         break;
  230.                     case 1:
  231.                         //hide a
  232.                         break;
  233.                     case 2:
  234.                         //hide x
  235.                         break;
  236.                     case 3:
  237.                         //hide x
  238.                         break;
  239.                     case 4:
  240.                         //hide b
  241.                         break;
  242.                     case 5:
  243.                         //hide y
  244.                         break;
  245.                     }*/
  246.                     //hide
  247.                     RemoveText();
  248.  
  249.                     ghostControllerAlpha = 1.f;
  250.                     ghostControllerAlphaVelocity = -0.01;       //will hide appropriately when alpha hits 0
  251.                 }
  252.  
  253.                 //increment
  254.                 lastGhostControllerCount[i] = OPC.ghostControllerCount[i];
  255.             }
  256.  
  257.             if(ghostControllerAlpha <= 1.f && ghostControllerAlpha >= 0.f)
  258.             {
  259.                 ghostControllerAlpha += ghostControllerAlphaVelocity;
  260.                 SetVariableNumber("_root.ghostControllerFade", ghostControllerAlpha * 100);
  261.                 ActionScriptVoid("setControllerFade");
  262.  
  263.                 //hide appropriately
  264.                 if(ghostControllerAlpha + ghostControllerAlphaVelocity < 0.f)
  265.                 {
  266.                     GC_X.setVisible(false);
  267.                     GC_Y.setVisible(false);
  268.                     GC_B.setVisible(false);
  269.                     GC_A.setVisible(false);
  270.                 }
  271.             }
  272.  
  273.             //setting reticle to be contextual or not
  274.             if(OPC.CurrentInterpActor != none && bLastFrameInterpActor == false)
  275.             {
  276.                 bLastFrameInterpActor = true;
  277.  
  278.                 //change from default to contextual
  279.                 ////`log("changing to contextual reticle");
  280.                 ReticleMC.SetVisible(false);
  281.                 ReticleMC1.SetVisible(true);
  282.             }
  283.             if(OPC.CurrentInterpActor == none && bLastFrameInterpActor == true)
  284.             {
  285.                 bLastFrameInterpActor = false;
  286.        
  287.                 //change from contextual to default
  288.                 ////`log("changing to normal reticle");
  289.                 ReticleMC.SetVisible(true);
  290.                 ReticleMC1.SetVisible(false);
  291.             }
  292.  
  293.             //displaying unlocked abilities
  294.  
  295.             if( Crystal_AirBlade != none )
  296.             {
  297.                 if(OPC.IsAbilityEnabled(PA_AirBlade))
  298.                 {
  299.                     Crystal_AirBlade.SetVisible(true);
  300.                     Crystal_Glide.SetVisible(false);
  301.                     Crystal_Jump.SetVisible(false);
  302.                 }
  303.                 else if( Crystal_Glide != none )
  304.                 {
  305.                     Crystal_AirBlade.SetVisible(false);
  306.  
  307.                     if(OPC.IsAbilityEnabled(PA_Glide))
  308.                     {
  309.                         Crystal_Glide.SetVisible(true);
  310.                         Crystal_Jump.SetVisible(false);
  311.                     }
  312.                     else if( Crystal_Jump != none )
  313.                     {
  314.                         Crystal_Glide.SetVisible(false);
  315.  
  316.                         if(OPC.IsAbilityEnabled(PA_Jump))
  317.                         {
  318.                             Crystal_Jump.SetVisible(true);
  319.                         }
  320.                         else
  321.                         {
  322.                             Crystal_Jump.SetVisible(false);
  323.                         }
  324.                     }
  325.                 }
  326.             }
  327.  
  328.             if( Crystal_LavaMine != none )
  329.             {
  330.                 if(OPC.IsAbilityEnabled(PA_LavaMine))
  331.                 {
  332.                     Crystal_LavaMine.SetVisible(true);
  333.                     Crystal_Contextual.SetVisible(false);
  334.                     Crystal_HeatTolerance.SetVisible(false);
  335.                 }
  336.                 else if( Crystal_Contextual != none )
  337.                 {
  338.                     Crystal_LavaMine.SetVisible(false);
  339.  
  340.                     if(OPC.IsAbilityEnabled(PA_Contextual))
  341.                     {
  342.                         Crystal_Contextual.SetVisible(true);
  343.                         Crystal_HeatTolerance.SetVisible(false);
  344.                     }
  345.                     else if( Crystal_HeatTolerance != none )
  346.                     {
  347.                         Crystal_Contextual.SetVisible(false);
  348.  
  349.                         if(OPC.IsAbilityEnabled(PA_HeatTolerance))
  350.                         {
  351.                             Crystal_HeatTolerance.SetVisible(true);
  352.                         }
  353.                         else
  354.                         {
  355.                             Crystal_HeatTolerance.SetVisible(false);
  356.                         }
  357.                     }
  358.                 }
  359.             }
  360.  
  361.  
  362.             if( Crystal_LightningPulse != none )
  363.             {
  364.                 if(OPC.IsAbilityEnabled(PA_LightningPulse))
  365.                 {
  366.                     Crystal_LightningPulse.SetVisible(true);
  367.                     Crystal_WaterWalking.SetVisible(false);
  368.                 }
  369.                 else if( Crystal_WaterWalking != none )
  370.                 {
  371.                     Crystal_LightningPulse.SetVisible(false);
  372.  
  373.                     if(OPC.IsAbilityEnabled(PA_WaterWalking))
  374.                     {
  375.                         Crystal_WaterWalking.SetVisible(true);
  376.                     }
  377.                     else
  378.                     {
  379.                         Crystal_WaterWalking.SetVisible(false);
  380.                     }
  381.                 }
  382.             }
  383.         }
  384.         else
  385.         {
  386.             Crystal_Jump.SetVisible(false);
  387.             Crystal_Glide.SetVisible(false);
  388.             Crystal_AirBlade.SetVisible(false);
  389.             Crystal_HeatTolerance.SetVisible(false);
  390.             Crystal_Contextual.SetVisible(false);
  391.             Crystal_LavaMine.SetVisible(false);
  392.             Crystal_WaterWalking.SetVisible(false);
  393.             Crystal_LightningPulse.SetVisible(false);
  394.         }
  395.     }
  396. }
  397.  
  398. function SetCenterText(string text)
  399. {
  400.     CenterTextTF1.SetText(text);
  401.     ActionScriptVoid("setMessageOn");
  402.     if (storyBoardFlag == true)
  403.     {
  404.         messageCooldown = 0.1;
  405.         storyBoardFlag = false;
  406.     }
  407.     else
  408.     {
  409.         messageCooldown = 3.0;
  410.         ActionScriptVoid("ResetFade");
  411.     }
  412. }
  413.  
  414. function RemoveText()
  415. {
  416.     ActionScriptVoid("setMessageOff");
  417. }
  418.  
  419. function ToggleHUD(bool showHud)
  420. {
  421.     bShowHUD = showHud;
  422.  
  423.     if(bShowHud == false)
  424.     {
  425.         ReticleMC.SetVisible(false);
  426.         HealthBarMC.SetVisible(false);
  427.         HealthMC.SetVisible(false);
  428.         BeltMC.SetVisible(false);
  429.         TrimMC.SetVisible(false);
  430.     }
  431.     else
  432.     {
  433.         ReticleMC.SetVisible(true);
  434.         HealthBarMC.SetVisible(true);
  435.         HealthMC.SetVisible(true);
  436.         BeltMC.SetVisible(true);
  437.         TrimMC.SetVisible(true);
  438.     }
  439. }
  440.  
  441. defaultproperties
  442. {
  443.     //this is the HUD. If the HUD is off, then this should be off
  444.     bDisplayWithHudOff=false
  445.     //The path to the swf asset we will create later
  446.     MovieInfo=SwfMovie'Odyssey_MenuHUD.OdyHUD'
  447.     //Just put it in...
  448.     //bGammaCorrection = false
  449.     bLastFrameInterpActor=false;
  450.  
  451.     healthUpdateCooldown=0.0;
  452.  
  453.     ghostControllerAlpha = 0.0;
  454.     ghostControllerAlphaVelocity = 0.0;
  455.  
  456.     bShowHUD = true;
  457. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement