17/08/2014, 12:51 PM
(Última modificación: 18/08/2014, 08:53 AM por alan_el_more.)
Dado que he visto muchos hud horribles donde crean variables/macros inservibles y horrores como llamar natives cada vez que se muestra el HUD, he decidido en aportarles este. En el cual, creo yo, es el más optimizado.
Cualquier duda, pregunten.
Código PHP:
#include <amxmodx>
#include <engine>
#include <hamsandwich>
const MAX_PLAYERS = 32
const TASK_HUD = 16367
enum _:INFO
{
HEALTH,
ARMOR
}
#define get_bit(%1,%2) (%1 & 1 << (%2 & 31))
#define set_bit(%1,%2) (%1 |= (1 << (%2 & 31)))
#define clear_bit(%1,%2) (%1 &= ~(1 << (%2 & 31)))
new g_iPlayerInfo[MAX_PLAYERS + 1][INFO]
new g_bAlive
new g_iMsgSync
public plugin_init()
{
register_plugin("Info Hud", "1.0", "alan_el_more")
register_event("Health", "Event_Health", "b")
register_event("Battery", "Event_Battery", "b")
register_event("DeathMsg", "Event_DeathMsg", "a")
RegisterHam(Ham_Spawn, "player", "Ham_PlayerSpawn_Post", true)
g_iMsgSync = CreateHudSyncObj()
}
public Event_Health(id)
{
g_iPlayerInfo[id][HEALTH] = read_data(1)
}
public Event_Battery(id)
{
g_iPlayerInfo[id][ARMOR] = read_data(1)
}
public Event_DeathMsg()
{
clear_bit(g_bAlive, read_data(2))
}
public Ham_PlayerSpawn_Post(id)
{
if(!is_user_alive(id))
return HAM_IGNORED;
set_bit(g_bAlive, id)
return HAM_IGNORED
}
public client_putinserver(id)
{
set_task(1.0, "Task_ShowHUD", id + TASK_HUD, _, _, "b")
}
public client_disconnect(id)
{
remove_task(id + TASK_HUD)
}
public Task_ShowHUD(id)
{
id -= TASK_HUD
static iSpec
iSpec = 0
if(!get_bit(g_bAlive, id))
{
iSpec = entity_get_int(id, EV_INT_iuser2)
if(!get_bit(g_bAlive, iSpec))
return
}
if(iSpec && id != iSpec)
{
set_hudmessage(255, 255, 0, 0.025, 0.21, 1, 6.0, 1.1, 0.0, 0.0, -1)
ShowSyncHudMsg(id, g_iMsgSync, "Vida: %d^nChaleco: %d",
g_iPlayerInfo[iSpec][HEALTH], g_iPlayerInfo[iSpec][ARMOR])
}
else
{
set_hudmessage(255, 255, 0, 0.025, 0.21, 1, 6.0, 1.1, 0.0, 0.0, -1)
ShowSyncHudMsg(id, g_iMsgSync, "Vida: %d^nChaleco: %d",
g_iPlayerInfo[id][HEALTH], g_iPlayerInfo[id][ARMOR])
}
}
Cualquier duda, pregunten.
Mis plugins públicos
Batalla de cuchillos 2.1 [18/10/13] [Aprobado]
Crear botones 1.1b [09/09/14] [Aprobado]
Vencimiento de admins 1.0d [09/09/14] [Aprobado]
Batalla de cuchillos 2.1 [18/10/13] [Aprobado]
Crear botones 1.1b [09/09/14] [Aprobado]
Vencimiento de admins 1.0d [09/09/14] [Aprobado]
Ni te molestes en enviarme un mensaje privado para pedirme ayuda porque NO lo voy a contestar.
Gracias por su atención.
Gracias por su atención.