Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fixed] Couldn't swap ballista ammo in offline #2186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mugg91
Copy link
Contributor

@mugg91 mugg91 commented Nov 25, 2024

Status

  • READY: this PR is (to the best of your knowledge) ready to be incorporated into the game.

Description

[fixed] Couldn't swap ballista ammo in offline

Fixes #2173

This PR fixes that you couldn't switch from regular ballista bolts to bomb bolts in offline.
In fact, although it visually looks like nothing happens when you press the inventory key, the game actually changes the ammo twice.

Vehicle.as

void onCommand(CBlob@ this, u8 cmd, CBitStream @params)

...

/// SWAP AMMO
	else if (cmd == this.getCommandID("swap_ammo") && isServer())
	{
		CPlayer@ p = getNet().getActiveCommandPlayer();
		if (p is null) return;

		CBlob@ b = p.getBlob();
		if (b is null) return;

		// don't swap ammo if only 1 ammo type
		if (v.ammo_types.size() <= 1) return;

		// don't swap ammo mid-charge
		if (v.charge > 0) return;

		// attached checks
		CAttachment@ ca = this.getAttachments();
		if (ca is null) return;
		AttachmentPoint@ ap = ca.getAttachmentPointByName("GUNNER");
		if (ap is null) return;
		CBlob@ attachedblob = ap.getOccupied();
		if (attachedblob is null) return;
		if (attachedblob !is b) return;

		u8 ammoIndex = v.current_ammo_index + 1;
		if (ammoIndex >= v.ammo_types.size())
		{
			ammoIndex = 0;
		}
		v.current_ammo_index = ammoIndex;

		this.SendCommand(this.getCommandID("swap_ammo_client"));
	}
	else if (cmd == this.getCommandID("swap_ammo_client") && isClient())
	{
		u8 ammoIndex = v.current_ammo_index + 1;
		if (ammoIndex >= v.ammo_types.size())
		{
			ammoIndex = 0;
		}
		v.current_ammo_index = ammoIndex;
	}

...

On a server, the command swap_ammo is run, some checks are done and if successful, it changes ammo on server and sends command for client to change ammo on client.
But in offline, isServer() and isClient() are both true so swap_ammo increments the index and swap_ammo_client increments it again, making it 0 again.
The problem is fixed by adding a check && !isServer() to swap_ammo_client.

Tested in offline and online, the ammo gets swapped properly in both.

@Vam-Jam Vam-Jam added the fix Fixes a bug label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't switch between Ballista Bolts and Bomb Bolts in offline
2 participants