Re: get_user_team
Many things wrong with your code. For one, where are all of these variables defined? I hope they are not globals. You need to post full code if you want an answer. I am making some assumptions with my below comments since you did not give the full picture.
I think the main issue is you are defining these variables globally. That will explain why everyone is seeing the message. You are checking the team of nKiller before you set a value to nKiller. Had these variables been defined locally, you would get an error and would have known that was the issue.
Code:
/*Which game event is calling hook_death? I am assuming DeathMsg. If so, there is no 5th element to read as you have when you check for headshot
DeathMsg
1=KillerID
2=VictimID
3=IsHeadshot
4=TruncatedWeaponName*/
public hook_death()
{
//Where are all of the variables defined that are used in this function?
//1. Use the cs-specific team natives
//2. You are checking the team of nKiller before assigning the value of read_data(1) to the variable. In this case
//it is using the value that was previously assigned to the variable.
//3. Define variables locally for DeathMsg hook.
if(get_user_team(nKiller) == CS_TEAM_CT)
{
nKiller = read_data(1)
if ( (read_data(3) == 1) && (read_data(5) == 0) )
{
nHp_add = get_pcvar_num (health_hs_add)
}
else
//Be consistent with bracketing. If you use it for the if() part of the condition, use it for else as well.
nHp_add = get_pcvar_num (health_add)
nHp_max = get_pcvar_num (health_max)
//If you are going to exit code if the killer is not eligible, do this before calling any other natives. (at the very top when you get the value of read_data(1))
if(!(get_user_flags(nKiller) & ADMIN_LEVEL_H))
return;
nKiller_hp = get_user_health(nKiller)
nKiller_hp += nHp_add
set_hudmessage(0, 0, 255, -1.0, 0.15, 0, 1.0, 1.0, 0.1, 0.1, -1)
show_hudmessage(nKiller, "+%d HP.", nHp_add)
if (nKiller_hp > nHp_max)
nKiller_hp = nHp_max
set_user_health(nKiller, nKiller_hp)
}
else if (get_user_team(id) == CS_TEAM_T)
{
client_print(nKiller, print_center, "Zombies don't get health for kills.");
}
}
Try this:
PHP Code:
public hook_death() { new nHp_add , nKiller_hp; new iKiller = read_data( 1 ); if ( !( get_user_flags( iKiller ) & ADMIN_LEVEL_H ) ) return; new CsTeams:csKillerTeam = cs_get_user_team( iKiller ); new iHeadshot = read_data( 3 ); if ( csKillerTeam == CS_TEAM_CT ) { nHp_add = get_pcvar_num( iHeadshot ? health_hs_add : health_add ); nKiller_hp = get_user_health( iKiller ); nKiller_hp += nHp_add; set_hudmessage(0, 0, 255, -1.0, 0.15, 0, 1.0, 1.0, 0.1, 0.1, -1); show_hudmessage( iKiller , "+%d HP." , nHp_add ); set_user_health( iKiller , clamp( nKiller_hp , 0 , get_pcvar_num( health_max ) ) ); } else if ( csKillerTeam == CS_TEAM_T ) { client_print( iKiller , print_center , "Zombies don't get health for kills." ); } }
|