ThEDisasteR

AmmoWarning

Jul 6th, 2011
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. //AmmoWarning by NightHawk043
  2. //V1.0
  3. //Plays unique sounds / shows graphics when using weapon with low/no ammo
  4.  
  5. if($Pref::Video::AmmoWarningShowGraphics $= "")
  6. $Pref::Video::AmmoWarningShowGraphics = "1";
  7.  
  8. if($Pref::sfx::AmmoWarningPlaySounds $= "")
  9. $Pref::sfx::AmmoWarningPlaySounds = "1";
  10.  
  11. //initialise other vars
  12.  
  13. addMessageCallback("MsgPlayerKilled", AWhandleMsgPlayerKilled);
  14. function AWhandleMsgPlayerKilled(%msgType)
  15. {
  16. sfxStop($NoAmmoLoop);
  17. sfxStop($LowAmmoLoop);
  18. $trk=0;
  19. }
  20.  
  21. package AmmoWarning
  22. {
  23.  
  24. //First we call the initialize function so we can add our sound files
  25. function Audio::initialize( )
  26. {
  27. //don't forget to let the initialize function continue on it's way.
  28. parent::initialize( );
  29. new SFXProfile(LowAmmo)
  30. {
  31. filename = "mods/autoexec/AmmoWarning/LowAmmo.wav";
  32. description = LoopingAudioGui;
  33. preload = true;
  34. };
  35. new SFXProfile(NoAmmo)
  36. {
  37. filename = "mods/autoexec/AmmoWarning/NoAmmo.wav";
  38. description = LoopingAudioGui;
  39. preload = true;
  40. };
  41. }
  42.  
  43.  
  44. function clientCmdSetWeaponAmmo(%weapon, %ammo)
  45. {
  46. parent::clientCmdSetWeaponAmmo(%weapon, %ammo);
  47. if($WeaponMaxAmmo[%weapon]<=%ammo)
  48. {
  49. $WeaponMaxAmmo[%weapon] = %ammo;
  50. }
  51. }
  52.  
  53.  
  54. //Here's where we tell the game when to start the warning for each weapon
  55. function clientCmdSetActiveWeaponAmmo(%ammo)
  56. {
  57. //we don't want to interfere here, so send the original function back on it's way.
  58. parent::clientCmdSetActiveWeaponAmmo(%ammo);
  59. if($PlayerIsAlive==1)
  60. {
  61. if($WeaponMaxAmmo[$ActiveWeapon] >=500){%maxammo = 500;}
  62. else if ($WeaponMaxAmmo[$ActiveWeapon]<=20){%maxammo = 20;}
  63. else{%maxammo=$weaponMaxAmmo[$ActiveWeapon];}
  64. if (%ammo == 0)
  65. {
  66. sfxStop($LowAmmoLoop);
  67. if($Pref::sfx::AmmoWarningPlaySounds && $trk!=1) {sfxStop($NoAmmoLoop);$NoAmmoLoop= sfxPlay(NoAmmo);$trk=1;}
  68. if($Pref::Video::AmmoWarningShowGraphics){HudOverlay.setHudElementTexture($HudOverlay::Warnicon, "mods/autoexec/AmmoWarning/NoAmmoCaution");}
  69. }
  70. else if (%ammo > 0 && (%ammo <= %maxammo*0.2))
  71. {
  72. sfxStop($NoAmmoLoop);
  73. if($Pref::sfx::AmmoWarningPlaySounds && $trk!=2) {sfxStop($LowAmmoLoop);$LowAmmoLoop= sfxPlay(LowAmmo);$trk=2;}
  74. if($Pref::Video::AmmoWarningShowGraphics){HudOverlay.setHudElementTexture($HudOverlay::Warnicon, "mods/autoexec/AmmoWarning/LowAmmoCaution");}
  75. }
  76. else { sfxStop($NoAmmoLoop);sfxStop($LowAmmoLoop);HudOverlay.setHudElementTexture($HudOverlay::Warnicon, "mods/autoexec/AmmoWarning/blank1");$trk=0;}
  77. }
  78. }
  79.  
  80. //time to create hud elements.
  81. function HudOverlay::AddHudElements(%this)
  82. {
  83. parent::AddHudElements(%this);
  84.  
  85. %index= %this.AddHudElement();
  86. %this.setHudElementTexture(%index, "mods/autoexec/AmmoWarning/blank1");
  87. %this.setHudElementPosition(%index,"450","275");
  88. %this.setHudElementPositionAnchor(%index,"Left","VCenter");
  89. %this.setHudElementParent(%index, $HudElement::BaseContainer);
  90. $HudOverlay::Warnicon = %index;
  91. }
  92. function HudOverlay::OnSleep(%this)
  93. {
  94. parent::OnSleep(%this);
  95. sfxStop($NoAmmoLoop);
  96. sfxStop($LowAmmoLoop);
  97. }
  98.  
  99. function GameOptionsList::onWake(%this)
  100. {
  101. parent::onWake(%this);
  102.  
  103. %this.addRow("Ammo Warning sounds", "1" TAB "0", true, "onPlaySoundsChanged", 0, 0);
  104.  
  105. %this.addRow("Ammo Warning Graphics", "1" TAB "0", true, "onShowGraphicsChanged", 0, 0);
  106.  
  107. %ammowarningsounds = $Pref::sfx::AmmoWarningPlaySounds ? "1" : "0";
  108. %this.selectOption(14, %ammowarningsounds);
  109.  
  110. %ammowarninggraphics = $Pref::Video::AmmoWarningShowGraphics ? "1" : "0";
  111. %this.selectOption(15, %ammowarninggraphics);
  112.  
  113. }
  114. function onPlaySoundsChanged(%direction, %row)
  115. {
  116. $Pref::sfx::AmmoWarningPlaySounds = GameOptionsList.getCurrentOption(%row);
  117. }
  118.  
  119. function onShowGraphicsChanged(%direction, %row)
  120. {
  121. $Pref::Video::AmmoWarningShowGraphics = GameOptionsList.getCurrentOption(%row);
  122. }
  123. };
  124. activatepackage(AmmoWarning);
Advertisement
Add Comment
Please, Sign In to add comment