AlliedModders

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

egbertjan 07-26-2011 11:24

Team healing
 
Hello, I got some problems with a team heal function.

Code:

//init
    register_cvar("diablo_Monk_heal", "20")
    register_cvar("diablo_Monk_distance", "300")

// my task
        case Monk:
        {
            Monk_healteam(id)
           
        }

public Monk_healteam(id) {

    new team1 = get_user_team(id);
    new team2;
    new p_origin[3], t_origin[3];
    get_user_origin(id, p_origin);

    for(new i = 0; i < 3; i++) {
        team2 = get_user_team(i);
        if(team2 != team1 && is_user_alive(i)) {
            get_user_origin(i, t_origin);
            if(get_distance(p_origin, t_origin) <= get_cvar_num("diablo_Monk_distance")) {
                set_user_health(i, get_user_health(i)+get_cvar_num("diablo_Monk_heal"));
                show_hudmessage(i, "You have healed your team for %i HP within %i feet",get_cvar_num("diablo_Monk_heal"),get_cvar_num("diablo_Monk_distance"))
            } else {
            show_hudmessage(i, "You have to get closer to your team mates to heal them!")
           
            }   
        }
    }
}

I have a task for running this function, but I don't know what's wrong with this.

I'm started to understand some basics of scripting, but still there are many things I have to learn, so please if you see what's wrong also explain me why it was wrong.

Edit: There are no compiling errors, just when I do the task it doesn't do anything.

Thanks in advance!

eXtrem 07-26-2011 11:37

Re: Team healing
 
If I'm not wrong,

Code:
if( team1 != team2 /* ... */ )

should be

Code:
if( team1 == team2 /* ... */ )

egbertjan 07-26-2011 11:50

Re: Team healing
 
Edit: This only heals myself and not my team members as I expected.

egbertjan 07-26-2011 16:41

Re: Team healing
 
I figured out another way to use this and after some time I also found out how to use this for purpose, thanks for helping me out though!

For the other interested people:

Code:

public monk_heal(id)
{
    new MaxHealth = race_heal[player_class[id]]+player_strength[id]*2
    new healRadius=get_cvar_num("diablo_monk_distance")
    new specialHeal=get_cvar_num("diablo_monk_heal")
    new location[3], allyOrigin[3], distanceBetween
   
    if (is_user_alive(id)) {       
        get_user_origin(id, location)  // Find out where Medic is
        for(new i = 0; i < 33; i++) {
            if ( (is_user_alive(i) && get_user_team(id)==get_user_team(i)) )  {
                get_user_origin(i, allyOrigin)
                // Check to see if any ally are within radius
                distanceBetween=get_distance(location, allyOrigin)
                if ( distanceBetween < healRadius && get_user_health(id) <= MaxHealth ) {
                    set_user_health(i, get_user_health(i)+specialHeal )
                   
                }
            }
        }
    }
}



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

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