DisplayNameTag Weapon bool

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is ON
[img] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: DisplayNameTag Weapon bool

DisplayNameTag Weapon bool

by Major Cooke » Sun Jan 20, 2019 6:33 pm

Just as it says.

[spoiler="What am I doing that needs this?]Currently, I have something of an elaborate weapon system scheme that's devised to override any and all keyconf files by going through each actor class and pulling the current SlotNumber and SlotPriority, organizing a list in order and basically performing the Pick*Weapon functions. This allows global switching between ALL weapons and basically tells the keyconf slots to jump off a bridge.

This has to be done by hijacking whenever a player presses a 'slot' or 'weapnext/prev' key, and sending a network event to perform the weapon switch instead of the player functions. Then the weapon is loaded into an object that marks the time, the weapon, and makes the UI tick function call DisplayNameTag, and WorldTick then deletes it right after.

It must be done this way since other player classes may be involved. I intend on making this an external addon anyone can hook up anywhere, but it's only useful if KEYCONF is involved. Otherwise there's no point in having it, truthfully. Some mod authors will not allow their KEYCONFs to be deleted so this is the only way to do it aside encouraging people to go in and delete it themselves.[/spoiler]

When I checked the code for DisplayNameTag, I noticed it's only for items. Can we get this for weapons please? That way it respects the DisplayNameTags cvar.

Here's the code for how I got it to queue up to print the message if anyone's interested. I removed the irrelevant stuff though.

Code: Select all

// Based off of Marisa Kirisame's NotHudMessage classes.
Class QueuedWeapon
{
	Weapon weap;
	int timestamp;
	static clearscope QueuedWeapon Create(Weapon next)
	{
		if (!next)	return null;
		let q = new('QueuedWeapon');
		q.weap = next;
		q.timestamp = gametic;
		return q;
	}
	
	ui void PrintTag()
	{
		if (weap != null)
			weap.DisplayNameTag();
	}
}

Class CPHandler : EventHandler
{	
	private Array<QueuedWeapon> Queue;
	override void OnRegister()
	{
		SetOrder(999);
		Queue.Clear();
	}
	
	// Tremendous thanks to Phantombeta for helping me out with this.
	
	override bool InputProcess(InputEvent ev)
	{
		if (ev.Type == InputEvent.Type_KeyDown)
		{
			int index = consoleplayer;
			let plr = players[index].mo;
			if (!plr || plr.health < 1 || plr.FindInventory("PowerMorph",true))
				return false;
			
			static const String KeyBindsCCMDs [] = {
				"slot 1", "slot 2", "slot 3", "slot 4", "slot 5",
				"slot 6", "slot 7", "slot 8", "slot 9", "slot 0",
				"weapnext", "weapprev"	};
			static const String KeyBindsNetEvents [] = {
				"slot:1", "slot:2", "slot:3", "slot:4", "slot:5",
				"slot:6", "slot:7", "slot:8", "slot:9", "slot:0",
				"next", "prev"	};
			
			// Find the key and translate it from the raw command to an 
			// event-friendly string. Makes splitting it easier.
			int bind1, bind2;
			for (int i = 0; i < KeyBindsCCMDs.Size(); i++) 
			{
				// Bindings is a global struct. Definition in menu.txt inside GZDoom.pk3.
				// Get the keys that are bound to this action.
				[bind1, bind2] = Bindings.GetKeysForCommand (KeyBindsCCMDs [i]);
				
				if (ev.KeyScan == bind1 || ev.KeyScan == bind2) 
				{
					//Console.Printf("%s", KeyBindsNetEvents[i]);
					EventHandler.SendNetworkEvent(String.Format("CP_SelectWeapon:%s", KeyBindsNetEvents[i]));
					return true;
				}
			}
		}
		return false;
	}
	
	static play void QueueWeapon( QueuedWeapon tosend )
	{
		CPHandler local = CPHandler(Find("CPHandler"));
		if ( !local ) return;
		local.Queue.Push(tosend);
	}
	
	override void PostUiTick()
	{
		// load 'em up
		for ( int i=0; i<queue.size(); i++ )
			if ( queue[i].timestamp >= gametic )
				queue[i].PrintTag();
	}
	
	override void WorldTick()
	{
		for (int i = 0; i < Queue.size(); i++)
		{
			if (Queue[i].timestamp >= gametic) continue;
			Queue.Delete(i);
			i--;
		}
	}
	
	override void NetworkProcess(ConsoleEvent e)
	{
		int num = e.Player;
		let plr = players[num].mo;
		if (!plr)	return;
		
		String s = e.Name;
		Array<String> strings;
		e.Name.Split (strings, ":");

		if (strings.Size() > 1)
		{
			if (strings[0] == 'CP_SelectWeapon')
			{
				Weapon next = ChangeWeapons(e);
				if (next) 
				{
					QueuedWeapon tosend = QueuedWeapon.Create(next);
					QueueWeapon(tosend);
				}
			}
		}
		return;
	}
}

Top