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

[SOLVED] Prevent shooting players


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 08-13-2011 , 11:23   [SOLVED] Prevent shooting players
Reply With Quote #1

What I want to do is enable friendlyfire only for some players in a team.
When one player shoots another, if they both have 'enabled' variable on 1, the victim will normally take the damage. But if one of them doesn't, nothing will happen:

PHP Code:
new enabled[33]
public 
plugin_init() {
    
register_message(get_user_msgid("TextMsg") , "block_message");
    
RegisterHam(Ham_TakeDamage"player""tk")
    
register_concmd("amx_ff""enable"ADMIN_RCON"")
}

public 
tk(victiminflictorkillerdamagebits) {
    if (
killer == victim)
    {    
        return 
HAM_IGNORED;
    }
    if (
enabled[killer] == && enabled[victim] == 1) {
        return 
HAM_IGNORED;
        
    }
    else {
        return 
HAM_SUPERCEDE
        
    
}
    return 
HAM_SUPERCEDE
}

public 
enable(idlevelcid) {
    if(!
cmd_access(idlevelcid2))
        return 
PLUGIN_HANDLED
    
    
new arg[32]
    
read_argv(1arg31)
    new 
player cmd_target(idargCMDTARGET_NO_BOTS CMDTARGET_ALLOW_SELF)
    if(
enabled[player] == 0) {
        
enabled[player] = 1
        client_print
(idprint_console"Ukljuceno.")
        return 
PLUGIN_HANDLED
    
}
    if(
enabled[player] == 1) {
        
enabled[player] = 0
        client_print
(idprint_console"Iskljuceno.")
    }
    return 
PLUGIN_HANDLED
}
public 
block_message() {
    if(
get_msg_argtype(2) == ARG_STRING) {
        new 
value[64];
        
get_msg_arg_string(value 63);
        if(
equali(value "#Game_teammate_attack")) {
            return 
PLUGIN_HANDLED;
        }
    }
    return 
PLUGIN_CONTINUE;

The code works but if the victim has no armor there will be blood and he gets pushed back and slowed if you hit him in the head. How can I prevent that (except giving 9999 armor )?

Last edited by Desikac; 08-15-2011 at 09:45.
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-13-2011 , 16:32   Re: Prevent shooting players
Reply With Quote #2

Code:
#include <fakemeta> #define m_LastHitGroup 75 public tk(victim, inflictor, killer, damage, bits) {     if (killer == victim)     {            return HAM_IGNORED;     }     if (enabled[killer] != enabled[victim]) {         set_pdata_int(victim, m_LastHitGroup, HIT_CHEST);         return HAM_SUPERCEDE;     }     return HAM_IGNORED }

That should work. If not, it stills looks better than what you had.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 08-13-2011 at 17:17.
Exolent[jNr] is offline
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 08-13-2011 , 17:14   Re: Prevent shooting players
Reply With Quote #3

Your code does the exact same thing as mine (but its better ).
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-13-2011 , 17:17   Re: Prevent shooting players
Reply With Quote #4

Edited my post.
Now attempts to change the hit box.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 08-13-2011 , 18:44   Re: Prevent shooting players
Reply With Quote #5

I have tested your code and there is no pushback/slowdown but the screen still shakes when you get hit in the head and there's still blood.

Last edited by Desikac; 08-13-2011 at 18:49.
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-13-2011 , 18:50   Re: Prevent shooting players
Reply With Quote #6

That's really odd, since returning HAM_SUPERCEDE should disable it completely, regardless of where you hit.
I've tested this myself in the past and it has always worked.

Try hooking Ham_TraceAttack instead.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 08-15-2011 , 09:44  
Reply With Quote #7

TraceAttack works perfectly.
PHP Code:
RegisterHam(Ham_TraceAttack"player""tk")

public 
tk(victimattackerFloat:damageFloat:direction[3], tracehandledamagebits) {
    if(!
is_user_connected(victim) || !is_user_connected(attacker) || victim == attacker)
        return 
HAM_IGNORED
        
    
if (enabled[attacker] == && enabled[victim] == 1) {
        return 
HAM_IGNORED
    
}
    return 
HAM_SUPERCEDE

Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
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 02:26.


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