AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved]Friendlyfire Between Two Players (https://forums.alliedmods.net/showthread.php?t=236580)

mapper07 03-07-2014 22:36

[Solved]Friendlyfire Between Two Players
 
Alright so I realized my post had more information than needed. Basically, I am trying to allow friendly fire on between two players on the same team and only for those two players. I set a bit on one player as challenger and the other as challengee but I can't get it to work properly? I feel like I am making it harder than it really is.
PHP Code:


plugin_init
()
{
    
RegisterHam(Ham_TakeDamage"player""Fwd_PlayerDamage"0);

}

public 
Fwd_PlayerDamage(const victim, const inflictor, const attackerFloat:damage, const iDamageType)
{
    if(
g_bKnifeDuel)
    {
        if( 
get_bit(Challengerattacker) && !get_bit(Challengeevictim )
        || 
get_bit(Challengeeattacker) && !get_bit(Challengervictim )
        || 
get_bit(Challengervictim) && !get_bit(Challengeeattacker )
        || 
get_bit(Challengeevictim) && !get_bit(Challengerattacker ) )
        {
            
SetHamReturnInteger(0);
            return 
HAM_SUPERCEDE;
        }
        
        
g_iVictimTeam cs_get_user_team_index(victim);
        if( 
g_iVictimTeam == cs_get_user_team_index(attacker) )
        {
            
cs_set_user_team_index(victimg_iVictimTeam == TEAM_T TEAM_CT TEAM_T);
            
EnableHamForward(g_iHhTakeDamagePost);
            return 
HAM_HANDLED;
        }    
    }

    return 
HAM_IGNORED;



Baws 03-09-2014 23:50

Re: Friendlyfire Between Two Players
 
question off topic ( maybe off topic? ) Whats with the || || || under if? Are they like goes with the if but like under it? Or it's another stuff? Me i understood they are part of the if. True?

hornet 03-09-2014 23:57

Re: Friendlyfire Between Two Players
 
Change the attacking player's team, execute the damage, and then change him back.

imindfreak 03-09-2014 23:57

Re: Friendlyfire Between Two Players
 
Quote:

Originally Posted by baws (Post 2109915)
question off topic ( maybe off topic? ) Whats with the || || || under if? Are they like goes with the if but like under it? Or it's another stuff? Me i understood they are part of the if. True?

They're part of the if, structured in a way where you can see all conditions in separate lines for ease of view.
They're used as "or" in a conditional statement.

~Example Removed~

mapper07 03-10-2014 00:38

Re: Friendlyfire Between Two Players
 
Quote:

Originally Posted by hornet (Post 2109918)
Change the attacking player's team, execute the damage, and then change him back.

Sounds simple enough. How do I do that ? lol :shock:

hornet 03-10-2014 00:59

Re: Friendlyfire Between Two Players
 
Code:
const m_iPlayerTeam = 114; public Fwd_PlayerDamage( id, iEnt, iAttacker, Float:flDamage, Bits ) {     new iTeam = get_pdata_int( iAttacker, m_iPlayerTeam );         //do all of your checks here         set_pdata_int( iAttacker, m_iPlayerTeam, iTeam == 1 ? 2 : 1 );     ExecuteHam( Ham_TakeDamage, id, iEnt, iAttacker, flDamage, Bits );     set_pdata_int( iAttacker, m_iPlayerTeam, iTeam ); }

Compidence 03-10-2014 02:12

Re: Friendlyfire Between Two Players
 
Your code is missing a few things. Anyhow try this:

PHP Code:


plugin_init
()
{
    
RegisterHam(Ham_TakeDamage"player""Fwd_PlayerDamage"0);

}

public 
Fwd_PlayerDamage(const victim, const inflictor, const attackerFloat:damage, const iDamageType)
{
    if(
g_bKnifeDuel)
    {
        if(
get_bit(Challengerattacker) && get_bit(Challengeevictim) || get_bit(Challengeeattacker) && get_bit(Challengervictim))
            {
              
g_iVictimTeam cs_get_user_team_index(victim);
              if( 
g_iVictimTeam == cs_get_user_team_index(attacker) )
              {
              
cs_set_user_team_index(victimg_iVictimTeam == TEAM_T TEAM_CT TEAM_T);
              
EnableHamForward(g_iHhTakeDamagePost);
              return 
HAM_HANDLED;
              }
        }
    }

    return 
HAM_IGNORED;


You don't want to do it your way because it would block all other attacks by other players. This way it should allow damage to be done normally to all players, while still allowing the challenger and challengee to attack each other.

Quote:

Originally Posted by hornet (Post 2109925)
Code:
const m_iPlayerTeam = 114; public Fwd_PlayerDamage( id, iEnt, iAttacker, Float:flDamage, Bits ) {     new iTeam = get_pdata_int( iAttacker, m_iPlayerTeam );         //do all of your checks here         set_pdata_int( iAttacker, m_iPlayerTeam, iTeam == 1 ? 2 : 1 );     ExecuteHam( Ham_TakeDamage, id, iEnt, iAttacker, flDamage, Bits );     set_pdata_int( iAttacker, m_iPlayerTeam, iTeam ); }

His code does that already.

mapper07 03-10-2014 02:32

Re: Friendlyfire Between Two Players
 
Okay Hornets code threw me off because his Fwd_PlayerDamage had different parameters than the one I posted. I will try and test yours first Compidence then report back. Thank you.

Compidence 03-10-2014 02:40

Re: Friendlyfire Between Two Players
 
The parameters can be called anything you want them to be called. The name itself doesn't change what they are. You can call the first parameter id or victim or idiot. The information passed to the first parameter would still be the same.

What his code does is allow friendlyfire, which your code already does, assuming you change the index back in damage post. But I think the problem was with your checks, not the friendlyfire code.

ConnorMcLeod 03-10-2014 02:52

Re: Friendlyfire Between Two Players
 
You should hook TraceAttack for weapons so more things are blocked (as blood) and TakeDamage for HE nades.

Is mp_friendlyfire 0 or 1 on your server ? (1 needs to block more things than, but you may need it).


All times are GMT -4. The time now is 14:24.

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