AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get_user_team (https://forums.alliedmods.net/showthread.php?t=314063)

Nutu_ 02-02-2019 08:44

get_user_team
 
PHP Code:

public hook_death()
{
    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
            
nHp_add get_pcvar_num (health_add)
        
nHp_max get_pcvar_num (health_max)
        if(!(
get_user_flags(nKiller) & ADMIN_LEVEL_H))
            return;
        
nKiller_hp get_user_health(nKiller)
        
nKiller_hp += nHp_add
        set_hudmessage
(00255, -1.00.1501.01.00.10.1, -1)
        
show_hudmessage(nKiller"+%d HP."nHp_add)
        if (
nKiller_hp nHp_maxnKiller_hp nHp_max
        set_user_health
(nKillernKiller_hp)
    }
    else if (
get_user_team(id) == CS_TEAM_T)
    {
        
client_print(nKillerprint_center"Zombies don't get health for kills.");
    }    


it shows me the client print, no matter if im ct or t, why?

Airkish 02-02-2019 09:04

Re: get_user_team
 
Change to:
PHP Code:

cs_get_user_team(nKiller

or

PHP Code:

get_user_team(nKiller) == //CT
get_user_team(nKiller) == //TER 


Nutu_ 02-02-2019 10:16

Re: get_user_team
 
it doesnt work at all now O.o

Bugsy 02-02-2019 11:21

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);
    
    if ( !( 
get_user_flagsiKiller ) & ADMIN_LEVEL_H ) ) 
        return; 
    
    new 
CsTeams:csKillerTeam cs_get_user_teamiKiller );
    new 
iHeadshot read_data);
    
    if ( 
csKillerTeam == CS_TEAM_CT )  
    { 
        
nHp_add get_pcvar_numiHeadshot health_hs_add health_add );
        
nKiller_hp get_user_healthiKiller );
        
nKiller_hp += nHp_add;
        
        
set_hudmessage(00255, -1.00.1501.01.00.10.1, -1); 
        
show_hudmessageiKiller "+%d HP." nHp_add ); 
        
        
set_user_healthiKiller clampnKiller_hp get_pcvar_numhealth_max ) ) );
    } 
    else if ( 
csKillerTeam == CS_TEAM_T 
    { 
        
client_printiKiller print_center "Zombies don't get health for kills." ); 
    }     



Nutu_ 02-02-2019 11:28

Re: get_user_team
 
it works, thank you!


All times are GMT -4. The time now is 07:36.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.