Spoiler: "What am I doing that needs this?
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 • Expand view
// 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;
}
}