Skip to content

Changing Weapon HUD (Weapon Custom Hud)

This plugin helps you get rid of some tedious work, such as searching for offsets, adding your own extra functions and registering commands like register_clcmd("weapon_mygun", "switch_handler") Now I'll explain it using an example test plugin that changes the knife's HUD. First of all…

PluginCounter-Strike 1.6Views:47Downloads:13

Description

This plugin helps you get rid of some tedious work, such as searching for offsets, adding your own extra functions and registering commands like register_clcmd("weapon_mygun", "switch_handler")

Now I'll explain it using an example test plugin that changes the knife's HUD.

First, we include the include file
#include <hud>

Now, for convenience, let's define constants for our old weapon and the new one

Pawn
#define WEAPON_OLD "weapon_knife"
#define WEAPON_NEW1 "weapon_knife1"
#define WEAPON_NEW2 "weapon_knife2"
#define WEAPON_NEW3 "weapon_knife3"
#define WEAPON_NEW4 "weapon_knife4"
#define WEAPON_NEW5 "weapon_knife5"

In plugin_init() we register all these HUDs

Pawn
public plugin_init()
{
	// какой-то код
	n21_register_hud(WEAPON_OLD, WEAPON_NEW1)
	n21_register_hud(WEAPON_OLD, WEAPON_NEW2)
	n21_register_hud(WEAPON_OLD, WEAPON_NEW3)
	n21_register_hud(WEAPON_OLD, WEAPON_NEW4)
	n21_register_hud(WEAPON_OLD, WEAPON_NEW5)
}

Now we need to send the client the sprite itself and the special .txt files named after our new knives, i.e. we have to set up 5 files:
weapon_knife1.txt
weapon_knife2.txt
weapon_knife2.txt
weapon_knife3.txt
weapon_knife5.txt

The files' contents look roughly like this:

Pawn
2
weapon			640 custom_hud/640hud21	0	45	170	45
weapon_s		640 custom_hud/640hud21	0	45	170	45

General format:
<тип> <разрешение> <спрайт> <смещение_по_X> <смещение_по_Y> <ширина> <высота>
The type can be one of the following: weapon, weapon_s, ammo, ammo2, autoaim, crosshair, zoom, zoom_aim.

Now we need to send the player the sprites and .txt files:

Pawn
public plugin_precache()
{
	precache_generic("sprites/weapon_knife1.txt")
	precache_generic("sprites/weapon_knife2.txt")
	precache_generic("sprites/weapon_knife3.txt")
	precache_generic("sprites/weapon_knife4.txt")
	precache_generic("sprites/weapon_knife5.txt")
 
	precache_generic("sprites/custom_hud/640hud21.spr")
}

So we can test all of this, let's register the commands in plugin_init:

Pawn
register_clcmd("say /k1", "knife_1")
register_clcmd("say /k2", "knife_2")
register_clcmd("say /k3", "knife_3")
register_clcmd("say /k4", "knife_4")
register_clcmd("say /k5", "knife_5")
register_clcmd("say /k6", "knife_old")

And here are the functions themselves:

Pawn
public knife_1(id)      n21_hud_change_to(id, WEAPON_OLD, WEAPON_NEW1)
public knife_2(id)      n21_hud_change_to(id, WEAPON_OLD, WEAPON_NEW2)
public knife_3(id)      n21_hud_change_to(id, WEAPON_OLD, WEAPON_NEW3)
public knife_4(id)      n21_hud_change_to(id, WEAPON_OLD, WEAPON_NEW4)
public knife_5(id)      n21_hud_change_to(id, WEAPON_OLD, WEAPON_NEW5)
public knife_old(id)    n21_hud_change_to(id, WEAPON_OLD, WEAPON_OLD)

Structure of the function n21_hud_change_to
1st argument - player id
2nd argument - name of the weapon whose HUD we are changing
3rd argument - name of the new weapon

A call of the function like this:
n21_hud_change_to(id, "weapon_knife", "weapon_knife")
returns the standard knife HUD, i.e. to restore the standard HUD of a weapon, you need to specify that weapon in the 2nd and 3rd arguments of the function.

As a result, we get this test plugin:

Pawn
#include <amxmodx>
#include <hud>

#define PLUGIN  "Hud Test"
#define AUTHOR  "trofian"
#define VERSION "1.0"

#define WEAPON_OLD "weapon_knife"
#define WEAPON_NEW1 "weapon_knife1"
#define WEAPON_NEW2 "weapon_knife2"
#define WEAPON_NEW3 "weapon_knife3"
#define WEAPON_NEW4 "weapon_knife4"
#define WEAPON_NEW5 "weapon_knife5"
 
public plugin_precache()
{
        precache_generic("sprites/weapon_knife1.txt")
        precache_generic("sprites/weapon_knife2.txt")
        precache_generic("sprites/weapon_knife3.txt")
        precache_generic("sprites/weapon_knife4.txt")
        precache_generic("sprites/weapon_knife5.txt")
       
        precache_generic("sprites/custom_hud/640hud21.spr")
}
 
public plugin_init()
{
        register_plugin(PLUGIN, VERSION, AUTHOR)
       
        n21_register_hud(WEAPON_OLD, WEAPON_NEW1)
        n21_register_hud(WEAPON_OLD, WEAPON_NEW2)
        n21_register_hud(WEAPON_OLD, WEAPON_NEW3)
        n21_register_hud(WEAPON_OLD, WEAPON_NEW4)
        n21_register_hud(WEAPON_OLD, WEAPON_NEW5)
       
        register_clcmd("say /k1", "knife_1")
        register_clcmd("say /k2", "knife_2")
        register_clcmd("say /k3", "knife_3")
        register_clcmd("say /k4", "knife_4")
        register_clcmd("say /k5", "knife_5")
        register_clcmd("say /k6", "knife_old")
}
 
public knife_1(id)      n21_hud_change_to(id, WEAPON_OLD, WEAPON_NEW1)
public knife_2(id)      n21_hud_change_to(id, WEAPON_OLD, WEAPON_NEW2)
public knife_3(id)      n21_hud_change_to(id, WEAPON_OLD, WEAPON_NEW3)
public knife_4(id)      n21_hud_change_to(id, WEAPON_OLD, WEAPON_NEW4)
public knife_5(id)      n21_hud_change_to(id, WEAPON_OLD, WEAPON_NEW5)
public knife_old(id)    n21_hud_change_to(id, WEAPON_OLD, WEAPON_OLD)

It's important to understand that this is just an example, it is NOT a ready-made implementation. You can use the functions the plugin provides however and wherever you like; it only saves you from routine work. You design the logic yourself; you are not required to stick to any rigid framework.

The custom_hud.amxx plugin must be higher in the plugins.ini list than the plugins that use the hud.inc include
You must load the custom_hud.amxx plugin!

Related

Pluginv1.8

Hats

AMX Mod X plugin for Counter-Strike. The plugin allows the player to wear hats on their heads. The main feature of this modification is the player's ability to choose a skin or a submodel of a headgear on his own and set which of them will be available exclusively to VIP players.

Pluginv0.3

Slot Machine

AMX Mod X plugin for Counter-Strike. The plugin allows you to place slot machines on the map and play them. The player places a bet and waits for a winning combination of symbols to appear. A victory is counted when a whole row or diagonal is filled with the same symbols.

Pluginv1.0

Costumes

This plugin adds costumes to your server; the models are compressed into one so as not to hit the server's limit. It can also be set up for ZombiePlague: to do so, uncomment the code // #define ZP_SUPPORT in the source and compile. Usage: /costumes - in chat to open the costumes menu…