Raised This Month: $12 Target: $400
 3% 

[Solved]Friendlyfire Between Two Players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mapper07
Member
Join Date: Oct 2012
Location: NY
Old 03-07-2014 , 22:36   [Solved]Friendlyfire Between Two Players
Reply With Quote #1

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;


Last edited by mapper07; 03-10-2014 at 21:24. Reason: Solved thanks to Hornet and Compidence
mapper07 is offline
Baws
Veteran Member
Join Date: Oct 2012
Old 03-09-2014 , 23:50   Re: Friendlyfire Between Two Players
Reply With Quote #2

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?
__________________
Like my clean plugins and work?
Baws is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 03-09-2014 , 23:57   Re: Friendlyfire Between Two Players
Reply With Quote #3

Change the attacking player's team, execute the damage, and then change him back.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
imindfreak
Senior Member
Join Date: Oct 2007
Location: 127.0.0.1
Old 03-09-2014 , 23:57   Re: Friendlyfire Between Two Players
Reply With Quote #4

Quote:
Originally Posted by baws View Post
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~
__________________
BeastGaming Community - Map Maker & Coder.

Last edited by hornet; 03-10-2014 at 01:02. Reason: Please do not give examples if you do not know what your talking about
imindfreak is offline
mapper07
Member
Join Date: Oct 2012
Location: NY
Old 03-10-2014 , 00:38   Re: Friendlyfire Between Two Players
Reply With Quote #5

Quote:
Originally Posted by hornet View Post
Change the attacking player's team, execute the damage, and then change him back.
Sounds simple enough. How do I do that ? lol
mapper07 is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 03-10-2014 , 00:59   Re: Friendlyfire Between Two Players
Reply With Quote #6

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 ); }
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Compidence
Junior Member
Join Date: Feb 2014
Old 03-10-2014 , 02:12   Re: Friendlyfire Between Two Players
Reply With Quote #7

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 View Post
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.

Last edited by Compidence; 03-10-2014 at 02:33.
Compidence is offline
mapper07
Member
Join Date: Oct 2012
Location: NY
Old 03-10-2014 , 02:32   Re: Friendlyfire Between Two Players
Reply With Quote #8

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.
mapper07 is offline
Compidence
Junior Member
Join Date: Feb 2014
Old 03-10-2014 , 02:40   Re: Friendlyfire Between Two Players
Reply With Quote #9

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.
Compidence is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-10-2014 , 02:52   Re: Friendlyfire Between Two Players
Reply With Quote #10

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).
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:09.


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