Raised This Month: $32 Target: $400
 8% 

Weapon-Specific Spawn Protection


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Counter-Strike        Category:   Gameplay        Approver:   Arkshine (91)
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-12-2011 , 14:22   Weapon-Specific Spawn Protection
Reply With Quote #1

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:
Attached Files
File Type: sma Get Plugin or Get Source (weapon_spawn_protection.sma - 1240 views - 4.7 KB)
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 07-07-2012 at 00:04.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-12-2011 , 14:33   Re: Weapon-Specific Spawn Protection
Reply With Quote #2

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

- my plugins -
ConnorMcLeod is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 10-12-2011 , 14:39   Re: Weapon-Specific Spawn Protection
Reply With Quote #3

- You never check if iFile is not zero.
- You don't need to read file after you just created it.
__________________
xPaw is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-12-2011 , 15:05   Re: Weapon-Specific Spawn Protection
Reply With Quote #4

Also, compare attacker index with get_maxplayers value instead of MAX_PLAYERS.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-12-2011 , 15:39   Re: Weapon-Specific Spawn Protection
Reply With Quote #5

Quote:
Originally Posted by ConnorMcLeod View Post
- 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 View Post
- 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 View Post
Also, compare attacker index with get_maxplayers value instead of MAX_PLAYERS.
Done.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-12-2011 , 17:06   Re: Weapon-Specific Spawn Protection
Reply With Quote #6

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

- my plugins -
ConnorMcLeod is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-12-2011 , 17:18   Re: Weapon-Specific Spawn Protection
Reply With Quote #7

Quote:
Originally Posted by ConnorMcLeod View Post
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.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-13-2011 , 00:38   Re: Weapon-Specific Spawn Protection
Reply With Quote #8

TraceAttack is sent with weapons (knife included), but not with hegrenades ;)
Seems that you need to hook both TraceAttack and TakeDamage.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
nikhilgupta345
Veteran Member
Join Date: Aug 2009
Location: Virginia
Old 10-13-2011 , 20:38   Re: Weapon-Specific Spawn Protection
Reply With Quote #9

Aww, that's annoying. I'll do it in a bit.

EDIT: Done.
__________________
Quote:
Originally Posted by DarkGod View Post
nikhilgupta generates his plugins using sheer awesome.
If you like my work, please

Last edited by nikhilgupta345; 10-13-2011 at 20:49.
nikhilgupta345 is offline
Send a message via ICQ to nikhilgupta345 Send a message via Yahoo to nikhilgupta345
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-14-2011 , 00:53   Re: Weapon-Specific Spawn Protection
Reply With Quote #10

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

- my plugins -

Last edited by ConnorMcLeod; 10-14-2011 at 00:55.
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 04:04.


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