I've been working on this but it has 1 problem.
I'm using a task to draw the icon but it seems to put the new one above the old one.
Not good at explaining it, screenshot attached.
This is what i got so far:
PHP Code:
#include <amxmodx>
#include <cstrike>
#pragma semicolon 1
#define VERSION "1.0.0"
new g_iWeapons[33][2];
public plugin_init()
{
register_plugin("Weapon Info", VERSION, "Drekes");
register_event("CurWeapon", "EventCurWeapon", "be", "1=1");
register_event("DeathMsg", "EventDeathMsg", "a");
register_clcmd("drop", "CmdDrop");
set_task(2.0, "TaskDrawWeaponIcons", .flags = "b");
}
public EventCurWeapon(id)
{
new iWeapon = read_data(2);
// These don't seem to work in the switch(iWeapon)
if(g_iWeapons[id][0] == iWeapon || g_iWeapons[id][1] == iWeapon)
return PLUGIN_CONTINUE;
switch(iWeapon)
{
case CSW_KNIFE, CSW_C4, CSW_SMOKEGRENADE, CSW_FLASHBANG, CSW_HEGRENADE:
return PLUGIN_CONTINUE;
default:
{
g_iWeapons[id][1] = g_iWeapons[id][0];
g_iWeapons[id][0] = iWeapon;
}
}
return PLUGIN_CONTINUE;
}
public CmdDrop(id)
{
new iWeapon = get_user_weapon(id);
for(new i = 0; i < sizeof(g_iWeapons[]); i++)
{
if(iWeapon == g_iWeapons[id][i])
{
g_iWeapons[id][i] = 0;
break;
}
}
}
public EventDeathMsg()
arrayset(g_iWeapons[read_data(1)], 0, sizeof(g_iWeapons[]));
public TaskDrawWeaponIcons()
{
static iPlayers[32], iNum, iPlayer, i, j;
get_players(iPlayers, iNum, "ach");
if(!iNum)
return;
for(i = 0; i < iNum; i++)
{
iPlayer = iPlayers[i];
for(j = 0; j < sizeof(g_iWeapons[]); j++)
{
if(g_iWeapons[iPlayer][j])
ShowWeaponPickup(iPlayer, g_iWeapons[iPlayer][j], true);
}
}
}
stock ShowWeaponPickup(id, iWeaponId, bool:bYellow=true) // set bYellow to false for red color
{
bYellow = !!bYellow; // clamp to 0/1
static iMsgWeaponPickup;
if(!iMsgWeaponPickup)
iMsgWeaponPickup = get_user_msgid("WeapPickup");
new ammo = cs_get_user_bpammo(id, iWeaponId);
if((ammo > 0) != bYellow)
{
cs_set_user_bpammo(id, iWeaponId, _:bYellow);
}
message_begin(MSG_ONE_UNRELIABLE, iMsgWeaponPickup, _, id);
write_byte(iWeaponId);
message_end();
if((ammo > 0) != bYellow)
{
cs_set_user_bpammo(id, iWeaponId, ammo);
}
}
I've tried blocking the original message, which didn't change anything
and i've messed around with the task delay, but it doesn't seem to the best way since the draw time is based on a client's cvar.