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

[TF2] Custom kill icon support #974

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Lizard-Of-Oz
Copy link

Description

This PR allows mappers to define custom kill icons by packing a new file called scripts/map_textures.txt that's structured identical to the game's scripts/mod_textures.txt where the stock kill icons are defined.
This PR also reloads kill icons on LevelInit.

Custom materials/textures are fully supported (unless different maps happened to store non-identical textures under the same name, which is a broader issue with asset caching anyway).

There's several ways for mappers to make use of this feature:

  • This PR adds a keyvalue killicon to trigger_hurt, func_croc and point_hurt. When not empty, its value will be used as the kill icon name.
  • By default, the game uses the inflictor's classname keyvalue for the kill icon name. Using VScript, you can use OnTakeDamage hook to assign a dummy entity as the inflictor:
myCustomInflictor <- SpawnEntityFromTable("info_target", { classname = "my_custom_kill_icon" });
<...>
OnScriptHook_OnTakeDamage = function(params)
{
  if (/* insert condition */)
    params.inflictor = myCustomInflictor;
}
  • It's possible to change classname of an existing entity with a map output MyEntityName | AddOutput | classname my_custom_kill_icon or with a VScript call myEntity.KeyValueFromString("classname", "my_custom_kill_icon"). However, the side-effects of this change are unclear and I recommend the other 2 methods.

Considerations

  • All changes to the kill icon loading procedure are contained within hud.cpp, in case if you want to merge only the icon loading functionality without adding the killicon keyvalue.
  • While I've tested compatibility with sv_pure to the best of my ability, the sv_pure system works in mysterious ways.
  • I've benchmarked the time it takes to reload the kill icons - it's negligible.
  • An alternative path for the file could be maps/%bspname%_map_textures.txt, but keeping the file name in sync with the bsp name is very annoying to deal with during map development, and there is no need for this naming convention here, as the file appears to get reloaded between maps correctly.
  • This PR unintentionally makes it possible to pack scripts/mod_textures.txt that will override the stock file until the map change. In fact, it's already possible in Live TF2, but it requires the user to use hud_reloadscheme command for changes to take effect.
    I see this as non-issue, as if a bad actor wants to mess with players with a poisoned map, there's many other opportunities to do so.
    If you disagree, this can be fixed with the following change to hud.cpp that will force the game to load hud_textures and mod_textures from the game's files.
-	LoadHudTextures( textureList, "scripts/hud_textures", NULL );
-	LoadHudTextures( textureList, "scripts/mod_textures", NULL );
+	const char* dudKey = "123";
+	LoadHudTextures( textureList, "scripts/hud_textures", (const unsigned char*) dudKey );
+	LoadHudTextures( textureList, "scripts/mod_textures", (const unsigned char*) dudKey );

@Lizard-Of-Oz
Copy link
Author

Lizard-Of-Oz commented Mar 9, 2025

An alternative path for the file could be
scripts/map_textures.txt

I've been given a better direction on how the game should choose a file from which to load the kill icon sheet. Will update the PR tomorrow.

@Lizard-Of-Oz Lizard-Of-Oz marked this pull request as draft March 9, 2025 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant