Page 1 of 1

[Solved] How to handle custom weapons reloading sounds?

Posted: 18 Jun 2014, 13:16
by fleo
Hello,

Does anyone know if there is a way to handle the reloading sound of a custom weapon? Because as I said in another post, I'm having some troubles with them.

First I only had a glitch which played this reloading sound in a loop when a player eliminated his last opponent with a custom weapon (there is a video). I fixed that by switching weapon just before the end of the round, which is really just a workaround:

Code: Select all

			// Elim attacker
			if (Players[G_AtkPlayerId].Armor <= 0 && Event.Victim.Id == G_AtkPlayerId) {
				PlaySound(CUIConfig::EUISound::VictoryPoint, 0);
				AtkIsEliminated = True;
				// Unequips the Shotgun and equips the Rocket to avoid reloading sound loop
				ActionBind(Event.Shooter,CSmMode::EActionSlot::Slot_B,CSmMode::EActionInput::None);
				SetPlayerWeapon(Event.Shooter, CSmMode::EWeapon::Rocket, False);
			}
Now I'm having another problem, I modified my gameplay so my custom weapons don't reload when they are not equipped (the reload is paused when it's unequipped and starts back from where it was when it's equipped again). The problem is if I switch from a custom weapon to a classic one when there is the reloading sound playing, this sound just loops until I switch back to this same custom weapon (there is a video showing it).

There is some code I'm using, the SwitchWeapon function:

Code: Select all

		// Rocket
		if (_Weapon == CSmModeEvent::EActionInput::Activable1 && CurWeaponNb != 2) {
			// Unequips Shotgun
			ActionBind(_Player,CSmMode::EActionSlot::Slot_B,CSmMode::EActionInput::None);
			// Equips Rocket
			SetPlayerWeapon(_Player, CSmMode::EWeapon::Rocket, True);
			_Player.AmmoGain = C_DefRocketAmmoGain;
			CurWeaponNb = 2;
		}
		// Shotgun
		else if (_Weapon == CSmModeEvent::EActionInput::Activable2 && CurWeaponNb != 6) {
			// Equips Nucleus for an instant to trigger switching sound (now and  
			//	when switching back), and cooldown of classic weapons (when switching back)
			SetPlayerWeapon(_Player, CSmMode::EWeapon::Nucleus, False);
			SetPlayerAmmoMax(_Player, CSmMode::EWeapon::Nucleus, 1);
			SetPlayerAmmo(_Player, CSmMode::EWeapon::Nucleus, 0);
			// Equips Shotgun
			ActionBind(_Player,CSmMode::EActionSlot::Slot_B,CSmMode::EActionInput::Weapon);
			CurWeaponNb = 6;
		}
And there is how I modified the custom weapon script to make the reload pausing:

Code: Select all

	if (Owner.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned) {
		// Pauses reloading when unequipped
		if (Owner.CurWeapon != 3) Energy = EnergyPause;
		// Reloads normally when it's equipped
		else EnergyPause = Energy;
		// Starts cooldown when switching to this weapon
		if (LastCurrentWeapon != Owner.CurWeapon) Cooldown_Start();
	}
	LastCurrentWeapon = Owner.CurWeapon;

Re: How to handle custom weapons reloading sounds?

Posted: 19 Jun 2014, 10:00
by fleo
I tried to set the energy level to zero when unequipped:

Code: Select all

	if (Owner.SpawnStatus == CSmPlayer::ESpawnStatus::Spawned) {
		// Switching weapon
		if (LastCurrentWeapon != Owner.CurWeapon) {
			// Switching to this weapon
			if (Owner.CurWeapon == 3) {
				// Sets the energy level and start the cooldown
				Energy = EnergyPause;
				Cooldown_Start();
			}
			// Switching to another weapon
			else {
				// Saves the energy level
				EnergyPause = Energy;
				// I set it to zero to avoid sound loop
				Energy = 0;
			}
		}
	}
	else EnergyPause = C_EnergyMax / 2;
	LastCurrentWeapon = Owner.CurWeapon;
That's the best result I got so far, the sound loop happens only half the time... I also tried no to set any value to Energy when unequipped but that's worse.

Re: How to handle custom weapons reloading sounds?

Posted: 19 Jun 2014, 12:56
by fleo
Ok I found a lead, I discovered that if I switch weapon in this order with a timer (50 ms mini) at this exact place, I have no glitch:

Code: Select all

		// Rocket
		if (_Weapon == CSmModeEvent::EActionInput::Activable1 && CurWeaponNb != 2) {
			// Equips Rocket
			SetPlayerWeapon(Player, CSmMode::EWeapon::Rocket, True);
			Player.AmmoGain = C_DefRocketAmmoGain;
			// Waits to avoid sound loop
			MB_Sleep(50);
			// Unequips Shotgun
			ActionBind(Player,CSmMode::EActionSlot::Slot_B,CSmMode::EActionInput::None);
			CurWeaponNb = Player.CurWeapon;
		}
But that's a really bad way to do it, calling the sleep function in an event is really wrong :roflol: Does anyone know an other way to do this trick?

Edit: yield does the exact same result.

Re: How to handle custom weapons reloading sounds?

Posted: 21 Jun 2014, 10:48
by Dommy
I found solution when player dies:

Code: Select all

if (Owner.Armor == 0) Energy = 0;
Put this in action script loop section. (Works only if player get unspawned, but it's fine in HG!)

Re: How to handle custom weapons reloading sounds?

Posted: 21 Jun 2014, 12:59
by fleo
I already tried that and it didn't work but now I tried that:

Code: Select all

if (Owner.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned) Energy = 0;
And it works ^^ but my biggest problem is how to avoid this sound loop when switching weapons...the difference is when a player dies, we have the time to set energy to zero before he's unspawned. When a player switches weapons, everything is done in one frame, so we can't set energy to zero before switching :?

Edit: Writing that gave me an idea :P so I made the weapon switch in multiple steps:

1)The player asks to switch: the mode script sends a variable to the weapon script without switching weapon.
2)The weapon script sets energy to zero and send an acknowledge to the mode script.
3)The mode script switches weapon.

This works for me, I don't have any sound loop. :yes: just hopping it won't bring any other glitch!

My only concern is that I placed a foreach loop in my PlayLoop section and I don't really like that. Any suggestion?

Edit again: the sound glitch is still here :o it just happens less often...

Re: How to handle custom weapons reloading sounds?

Posted: 21 Jun 2014, 14:46
by Dommy
Well, is possible to communicate between action and mode? I already know, you can send information from action using event parameters, but can we use net variables instead? I'm very interested :)

Re: How to handle custom weapons reloading sounds?

Posted: 21 Jun 2014, 18:31
by fleo
I'm using a shared variable but it's not working very well.
In mode script:
declare Integer CurWeaponNb for _Player;
In action script:
declare Integer CurWeaponNb for Owner;