Figured it out. Had to set a timer to delay the health change slightly. New code for reference:
Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
#define PLUGIN "12-Pack"
#define VERSION "1.0"
#define AUTHOR "newerakb"
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_event("HLTV", "event_new_round", "a", "1=0", "2=0")
}
public event_new_round()
{
new playerList[32]
new playerCount, ctCount, tCount
new player, team
ctCount = 0
tCount = 0
get_players(playerList, playerCount)
log_amx("playerCount: %d", playerCount)
new i
for (i = 0; i < playerCount; i++)
{
player = playerList[i]
team = get_user_team(player)
if (team == 1)
{
tCount++
}
else if (team == 2)
{
ctCount++
}
}
new ctHeroIndex, tHeroIndex
new ctHero, tHero
new currentCT, currentT
ctHeroIndex = random_num(0, ctCount - 1)
tHeroIndex = random_num(0, tCount - 1)
currentCT = 0
currentT = 0
tHero = 0
ctHero = 0
for (i = 0; i < playerCount; i++)
{
player = playerList[i]
team = get_user_team(player)
if (team == 1)
{
if (currentT == tHeroIndex)
{
tHero = player
}
currentT++
}
else if (team == 2)
{
if (currentCT == ctHeroIndex)
{
ctHero = player
}
currentCT++
}
}
new params[2]
params[0] = ctHero
params[1] = tHero
set_task(0.5, "setHealth", 0, params, 2, "a", 1)
return PLUGIN_HANDLED
}
public setHealth(params[])
{
new ctHero = params[0]
new tHero = params[1]
log_amx("tHero: %d", tHero)
log_amx("ctHero: %d", ctHero)
new name[20]
new health
if (tHero > 0)
{
set_user_health(tHero, 12)
get_user_name(tHero, name, 20)
log_amx("tHero Name: %s", name)
health = get_user_health(tHero)
log_amx("tHero Health: %d", health)
}
if (ctHero > 0)
{
set_user_health(ctHero, 12)
get_user_name(ctHero, name, 20)
log_amx("ctHero Name: %s", name)
health = get_user_health(ctHero)
log_amx("ctHero Health: %d", health)
}
}