AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Approved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=8)
-   -   Weapon-Specific Spawn Protection (https://forums.alliedmods.net/showthread.php?t=169434)

nikhilgupta345 10-12-2011 14:22

Weapon-Specific Spawn Protection
 
4 Attachment(s)
Weapon-Specific Spawn Protection

By: nikhilgupta345

Description:
This plugin allows you to protect a player from a certain weapon for the first X seconds after he spawns. A .ini file is created where you can place the weapon names that you want to be blocked.


CVars:
    • wssp_protect_time - How long players are protected for after they spawn.

Installation:
    • Click 'Get Plugin' link below
    • Place 'weapon_spawn_protection.amxx' in addons/amxmodx/plugins/ folder
    • Open addons/amxmodx/configs/plugins.ini
    • Add the line 'weapon_spawn_protection.amxx' at the bottom
    • Either create 'spawn_protect_weapons.ini' on your own in the configs folder or allow the plugin to run once and it'll create it for you.
    • Add weapon names to it (weapon_awp, weapon_deagle, weapon_usp). Full list can be found here: http://wiki.amxmodx.org/CS_Weapons_Information
    • Restart server or change map

Example:
  • Example of 'spawn_protect_weapons.ini'
    • Code:

      ;Use this file to configure which weapons players are protected from on spawn.
      weapon_awp
      weapon_deagle
      weapon_knife
      weapon_usp
      ;weapon_aug

    • In the above code, awp, deagle, knife, and usp will be blocked, but not aug. Using ';', or '//' at the beginning of the line will comment it out completely. If something is not working, make sure that you see the 'Weapon Loaded: WEAPON_NAME' in console when you restart the server. If it's there and it is not working, let me know.

Changelog:

  • Code:

    October 12, 2011
    • -v1.0-
      • Initial Release


    • -v1.0.1-
      • Turn off weapons if no plugins were registered

      • Don't read from file if file was just created

      • Change from boolean + task to gametime


    October 14, 2011
    • -v1.1-
      • Optimized Ham_TakeDamage and Ham_TraceAttack function calls

      • Credits to ConnorMcLeod for these optimizations.


    July 07, 2011
    • -v1.1.1-
      • Closed file handle after use (xPaw)

      • Disabled some Ham forwards if they were not needed (Arkshine)




Credits:

ConnorMcLeod 10-12-2011 14:33

Re: Weapon-Specific Spawn Protection
 
- If you let TakeDamage enabled all the time, then remove the task system it is useless, use gametime instead.
- You can't detect hegrenade with your code
- If you also want to prevent blood from appearing, you have to hook TraceAttack

It could be usefull to have a specific time for each weapon, even if i don't really see the utility of this plugin ;)

xPaw 10-12-2011 14:39

Re: Weapon-Specific Spawn Protection
 
- You never check if iFile is not zero.
- You don't need to read file after you just created it.

ConnorMcLeod 10-12-2011 15:05

Re: Weapon-Specific Spawn Protection
 
Also, compare attacker index with get_maxplayers value instead of MAX_PLAYERS.

nikhilgupta345 10-12-2011 15:39

Re: Weapon-Specific Spawn Protection
 
Quote:

Originally Posted by ConnorMcLeod (Post 1573639)
- If you let TakeDamage enabled all the time, then remove the task system it is useless, use gametime instead.
- You can't detect hegrenade with your code
- If you also want to prevent blood from appearing, you have to hook TraceAttack

It could be usefull to have a specific time for each weapon, even if i don't really see the utility of this plugin ;)

Changed to TraceAttack + used get_gametime. I also added he grenade support. Not sure what you meant by the last comment though. Could you please clarify? Thanks.

Quote:

Originally Posted by xPaw (Post 1573641)
- You never check if iFile is not zero.
- You don't need to read file after you just created it.

Done.

Quote:

Originally Posted by ConnorMcLeod (Post 1573657)
Also, compare attacker index with get_maxplayers value instead of MAX_PLAYERS.

Done.

ConnorMcLeod 10-12-2011 17:06

Re: Weapon-Specific Spawn Protection
 
Have i missed something or isn't cstrike module used ?
Also if no weapon registered, it is not required to let the plugin run, or at least to register forwards.

nikhilgupta345 10-12-2011 17:18

Re: Weapon-Specific Spawn Protection
 
Quote:

Originally Posted by ConnorMcLeod (Post 1573713)
Have i missed something or isn't cstrike module used ?
Also if no weapon registered, it is not required to let the plugin run, or at least to register forwards.

No it wasn't used. I thought I Would need it initially and forgot to remove it. Thanks for catching that.

Also prevented forward registration if no weapons were registered.

ConnorMcLeod 10-13-2011 00:38

Re: Weapon-Specific Spawn Protection
 
TraceAttack is sent with weapons (knife included), but not with hegrenades ;)
Seems that you need to hook both TraceAttack and TakeDamage.

nikhilgupta345 10-13-2011 20:38

Re: Weapon-Specific Spawn Protection
 
Aww, that's annoying. I'll do it in a bit.

EDIT: Done.

ConnorMcLeod 10-14-2011 00:53

Re: Weapon-Specific Spawn Protection
 
You can remove grenade check from TraceAttack (never called).

Code:
        else if( get_gametime() - g_flSpawnTime[ iVictim ] < get_pcvar_float( g_pProtectionTime ) )             return HAM_IGNORED;                 if( iBits & DMG_HEGRENADE && g_iProtectWeapons & ( 1<<CSW_HEGRENADE ) )             return HAM_SUPERCEDE;

You don't need an "else" because you already return the previous statement.
Those 2 highlighted checks should be proceded in the other way.
1st check for bit and iProtectWeapons, and the if that check is passed, then do the gametime and cvar checks that need to use natives.
I would put all checks in a row but that's your choice :
PHP Code:

    public Ham_PlayerTakeDamage_PreiVictimiInflictoriAttackerFloat:flDamageiBits )
    {
        if( 
<= iAttacker <= g_iMaxPlayers
        
&&  iBits DMG_HEGRENADE
        
&& g_iProtectWeapons & ( 1<<CSW_HEGRENADE )
        && 
get_gametime() - g_flSpawnTimeiVictim ] > get_pcvar_floatg_pProtectionTime )    )
        {
            return 
HAM_SUPERCEDE;
        }
        return 
HAM_IGNORED;
    } 

Remember that when you can, you should first put checks that doesn't need any native calls, and then other checks.
TraceAttack and TakeDamage are not sent very often, but that's a good habit to take.


All times are GMT -4. The time now is 20:32.

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