Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //AmmoWarning by NightHawk043
- //V1.0
- //Plays unique sounds / shows graphics when using weapon with low/no ammo
- if($Pref::Video::AmmoWarningShowGraphics $= "")
- $Pref::Video::AmmoWarningShowGraphics = "1";
- if($Pref::sfx::AmmoWarningPlaySounds $= "")
- $Pref::sfx::AmmoWarningPlaySounds = "1";
- //initialise other vars
- addMessageCallback("MsgPlayerKilled", AWhandleMsgPlayerKilled);
- function AWhandleMsgPlayerKilled(%msgType)
- {
- sfxStop($NoAmmoLoop);
- sfxStop($LowAmmoLoop);
- $trk=0;
- }
- package AmmoWarning
- {
- //First we call the initialize function so we can add our sound files
- function Audio::initialize( )
- {
- //don't forget to let the initialize function continue on it's way.
- parent::initialize( );
- new SFXProfile(LowAmmo)
- {
- filename = "mods/autoexec/AmmoWarning/LowAmmo.wav";
- description = LoopingAudioGui;
- preload = true;
- };
- new SFXProfile(NoAmmo)
- {
- filename = "mods/autoexec/AmmoWarning/NoAmmo.wav";
- description = LoopingAudioGui;
- preload = true;
- };
- }
- function clientCmdSetWeaponAmmo(%weapon, %ammo)
- {
- parent::clientCmdSetWeaponAmmo(%weapon, %ammo);
- if($WeaponMaxAmmo[%weapon]<=%ammo)
- {
- $WeaponMaxAmmo[%weapon] = %ammo;
- }
- }
- //Here's where we tell the game when to start the warning for each weapon
- function clientCmdSetActiveWeaponAmmo(%ammo)
- {
- //we don't want to interfere here, so send the original function back on it's way.
- parent::clientCmdSetActiveWeaponAmmo(%ammo);
- if($PlayerIsAlive==1)
- {
- if($WeaponMaxAmmo[$ActiveWeapon] >=500){%maxammo = 500;}
- else if ($WeaponMaxAmmo[$ActiveWeapon]<=20){%maxammo = 20;}
- else{%maxammo=$weaponMaxAmmo[$ActiveWeapon];}
- if (%ammo == 0)
- {
- sfxStop($LowAmmoLoop);
- if($Pref::sfx::AmmoWarningPlaySounds && $trk!=1) {sfxStop($NoAmmoLoop);$NoAmmoLoop= sfxPlay(NoAmmo);$trk=1;}
- if($Pref::Video::AmmoWarningShowGraphics){HudOverlay.setHudElementTexture($HudOverlay::Warnicon, "mods/autoexec/AmmoWarning/NoAmmoCaution");}
- }
- else if (%ammo > 0 && (%ammo <= %maxammo*0.2))
- {
- sfxStop($NoAmmoLoop);
- if($Pref::sfx::AmmoWarningPlaySounds && $trk!=2) {sfxStop($LowAmmoLoop);$LowAmmoLoop= sfxPlay(LowAmmo);$trk=2;}
- if($Pref::Video::AmmoWarningShowGraphics){HudOverlay.setHudElementTexture($HudOverlay::Warnicon, "mods/autoexec/AmmoWarning/LowAmmoCaution");}
- }
- else { sfxStop($NoAmmoLoop);sfxStop($LowAmmoLoop);HudOverlay.setHudElementTexture($HudOverlay::Warnicon, "mods/autoexec/AmmoWarning/blank1");$trk=0;}
- }
- }
- //time to create hud elements.
- function HudOverlay::AddHudElements(%this)
- {
- parent::AddHudElements(%this);
- %index= %this.AddHudElement();
- %this.setHudElementTexture(%index, "mods/autoexec/AmmoWarning/blank1");
- %this.setHudElementPosition(%index,"450","275");
- %this.setHudElementPositionAnchor(%index,"Left","VCenter");
- %this.setHudElementParent(%index, $HudElement::BaseContainer);
- $HudOverlay::Warnicon = %index;
- }
- function HudOverlay::OnSleep(%this)
- {
- parent::OnSleep(%this);
- sfxStop($NoAmmoLoop);
- sfxStop($LowAmmoLoop);
- }
- function GameOptionsList::onWake(%this)
- {
- parent::onWake(%this);
- %this.addRow("Ammo Warning sounds", "1" TAB "0", true, "onPlaySoundsChanged", 0, 0);
- %this.addRow("Ammo Warning Graphics", "1" TAB "0", true, "onShowGraphicsChanged", 0, 0);
- %ammowarningsounds = $Pref::sfx::AmmoWarningPlaySounds ? "1" : "0";
- %this.selectOption(14, %ammowarningsounds);
- %ammowarninggraphics = $Pref::Video::AmmoWarningShowGraphics ? "1" : "0";
- %this.selectOption(15, %ammowarninggraphics);
- }
- function onPlaySoundsChanged(%direction, %row)
- {
- $Pref::sfx::AmmoWarningPlaySounds = GameOptionsList.getCurrentOption(%row);
- }
- function onShowGraphicsChanged(%direction, %row)
- {
- $Pref::Video::AmmoWarningShowGraphics = GameOptionsList.getCurrentOption(%row);
- }
- };
- activatepackage(AmmoWarning);
Advertisement
Add Comment
Please, Sign In to add comment