AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] Prevent shooting players (https://forums.alliedmods.net/showthread.php?t=164596)

Desikac 08-13-2011 11:23

[SOLVED] Prevent shooting players
 
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 :))?

Exolent[jNr] 08-13-2011 16:32

Re: Prevent shooting players
 
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.

Desikac 08-13-2011 17:14

Re: Prevent shooting players
 
Your code does the exact same thing as mine (but its better :)).

Exolent[jNr] 08-13-2011 17:17

Re: Prevent shooting players
 
Edited my post.
Now attempts to change the hit box.

Desikac 08-13-2011 18:44

Re: Prevent shooting players
 
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.

Exolent[jNr] 08-13-2011 18:50

Re: Prevent shooting players
 
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.

Desikac 08-15-2011 09:44

TraceAttack works perfectly. :D
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




All times are GMT -4. The time now is 03:26.

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