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

[TF2] Dodge & Resist


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Tylerst
Veteran Member
Join Date: Oct 2010
Plugin ID:
2114
Plugin Version:
1.1.6
Plugin Category:
Fun Stuff
Plugin Game:
Team Fortress 2
Plugin Dependencies:
    Servers with this Plugin:
    3 
    Plugin Description:
    Set dodge chance and/or damage resistance of a target(s), specific classes, or all players
    Old 12-05-2010 , 11:28   [TF2] Dodge & Resist
    Reply With Quote #1

    TF2 Dodge & Resist (Requires SDKhooks!)
    Thanks to L.Duke for his particles via tempents thread and [AAA]Thrawn for the updated list of effects in this post

    Description:
    Set dodge chance and/or damage resistance of a target(s), specific classes, or all players

    Cvars(default values shown):

    sm_dodgeresist_version "1.1.6"

    sm_dodgeresist_chat "1" - Enable/Disable (1/0) Showing dodge/resist changes in chat
    sm_dodgeresist_log "1" - Enable/Disable (1/0) Logging of dodge/resist changes


    IMPORTANT:
    Class specific cvars override base dodge/resist for that class
    For both dodge and resistance priority order is
    Admin Command>Class Cvar>Base Cvar

    All following cvars are limited from 0-100(Just like the admin commands)

    sm_basedodge "0" - Set the default dodge chance for all players
    sm_baseresist "0" - Set the default damage resistance for all players

    sm_scoutdodge "0" - Set dodge chance of all scouts
    sm_scoutresist "0" - Set damage resistance of all scouts

    sm_soldierdodge "0" - Same as sbove,but for soldier
    sm_soldierresist "0" - Same as above, but for soldier

    sm_pyrododge "0" - Yeah, still the same, but for pyro
    sm_pyroresist "0" - Still the same, blah blah

    sm_demomandodge "0" - See the pattern yet?
    sm_demomanresist "0"

    sm_heavydodge "0"
    sm_heavyresist "0"

    sm_engineerdodge "0"
    sm_engineerresist "0"

    sm_medicdodge "0"
    sm_medicresist "0"

    sm_sniperdodge "0"
    sm_sniperresist "0"

    sm_spydodge "0"
    sm_spyresist "0"


    Commands:

    sm_dodge <target> <0-100> - Set dodge chance of a target(s), use -1 to reset to default- Default Slay Flag
    Will show "Miss" text when an attack misses
    sm_resist <target> <0-100> - Set damage resistance of a target(s), use -1 to reset to default -Default Slay Flag

    Examples:
    sm_dodge Thetarget 50 - 50% of attacks will miss Thetarget
    sm_resist Thetarget 75 - Attacks that hit Thetarget will only do 25% damage
    sm_dodge @me 100 - All attacks will miss you
    sm_resist @me 100 - Attacks that hit will not damage you
    sm_dodge @bots 75 - Bots will dodge 75% of attacks
    sm_resist @humans 100 - players won't take damage
    sm_dodge @red 25 - Red team will dodge 25% of attacks
    sm_resist @blue - Blue team will take 75% damage
    sm_dodge @all 10 - everyone will dodge 10% of attacks

    sm_dodge @all -1 - reset everyones dodge chance to default
    sm_resist @all -1 - reset everyones damage resistance to default

    Changelog:
    Code:
    Version 1.0.0 - December 5, 2010
    * Initial Release
    Version 1.0.1 - December 12, 2010
    * Added code to check for valid clients
    Version 1.1.0 - February 03, 2011
    * Added missing translation code
    * Added Cvars to change default values and per class values
    * Added separate functions to calculate dodge and resistance with new cvars
    * Added player loop in OnPluginStart to account for late loading
    * Lots of other minor coding changes
    Version 1.1.3 - April 4, 2011
    * Minor code change due to some errors
    Version 1.1.5 - August 6, 2011
    * Added code to allow rocket/sticky jumping, etc
    * Plugin now uses AskPluginLoad2 to check the game
    Version 1.1.6 - August 7, 2011
    * Small fix for not showing 'miss' text when hitting a bot that dodged
    Todo:
    Allow resistance values above 100 that heal the target hit, and values below 0 to increase the damage done to the target
    Will probably need to move resetting to an admin command instead of -1 on sm_resist, or maybe strcmp to allow something like sm_resist @all reset

    List of things I'm not adding:
    Admin Menu Integration
    I tried this out on my Set Class Plugin(for practice), and it ended up using more code than the actual plugin. Use the Custom Admin Menu, it's muuuuuuch easier.

    Allow the cvars for base dodge/resistance and classes to be admin only
    That's what the admin commands are for! Besides, it's open source. If you want it that badly noone is stopping you from coding it in for your server.
    Attached Files
    File Type: sp Get Plugin or Get Source (TF2 Dodge & Resist.sp - 560 views - 12.2 KB)
    File Type: smx TF2 Dodge & Resist.smx (9.4 KB, 556 views)

    Last edited by Tylerst; 08-07-2011 at 06:43. Reason: Update
    Tylerst is offline
    FlaminSarge
    Veteran Member
    Join Date: Jul 2010
    Old 12-07-2010 , 02:05   Re: [TF2] Dodge & Resist
    Reply With Quote #2

    " TF2only()
    CreateConVar("sm_dodgeresist_version", PLUGIN_VERSION, "Set dodge chance and/or damage resistance of a target(s)", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FC VAR_NOTIFY);"
    looks like you're missing a semicolon after TF2only() ?
    __________________
    Bread EOTL GunMettle Invasion Jungle Inferno will break everything. Don't even ask.

    All plugins: Randomizer/GiveWeapon, ModelManager, etc.
    Post in plugin threads with questions.
    Steam is for playing games.
    You will be fed to javalia otherwise.
    Psyduck likes replays.
    FlaminSarge is offline
    Tylerst
    Veteran Member
    Join Date: Oct 2010
    Old 12-07-2010 , 05:37   Re: [TF2] Dodge & Resist
    Reply With Quote #3

    Quote:
    Originally Posted by FlaminSarge View Post
    " TF2only()
    CreateConVar("sm_dodgeresist_version", PLUGIN_VERSION, "Set dodge chance and/or damage resistance of a target(s)", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FC VAR_NOTIFY);"
    looks like you're missing a semicolon after TF2only() ?
    I don't have #pragma semicolon 1 set, that shouldn't be a problem.
    (Or at least I've never had to do it before so I don't see why I'd need to here)

    If it's an error you're getting I don't know what to tell you.
    It's not giving me any errors when I compile it.
    Tylerst is offline
    Tylerst
    Veteran Member
    Join Date: Oct 2010
    Old 12-12-2010 , 11:01   Re: [TF2] Dodge & Resist
    Reply With Quote #4

    Plugin updated for an error I was getting
    Tylerst is offline
    FaTony
    Veteran Member
    Join Date: Aug 2008
    Old 12-12-2010 , 11:07   Re: [TF2] Dodge & Resist
    Reply With Quote #5

    God damn those RPG addicts.
    __________________
    FaTony is offline
    psychonic

    BAFFLED
    Join Date: May 2008
    Old 01-31-2011 , 09:51   Re: [TF2] Dodge & Resist
    Reply With Quote #6

    @ Tylerist

    Before it can be approved, you need to load the common phrases translation file on plugin start or there will be errors if the target cannot be found.
    Code:
    LoadTranslations("common.phrases");

    Some less-important stuff:
    Consider adding lateload support for when the plugin is (re)loaded mid game (should just have to add looping through all clients at plugin start, adding the hook for those that are InGame).

    Another suggestion, maybe add cvars for default dodge and default resistance (maybe even per class?)

    Code:
    if(!IsClientConnected(victim) || !IsClientInGame(victim)
    Not critical, but IsClientInGame will return false if not connected, and a return a true on it implies connected so you can leave one check off.

    Code:
    damage *= 0;
    Why not just = 0?

    Code:
    new Float:resist = 1.0 - (damageresist[victim]/100.0);
    Is this giving the intended result? You're dividing an integer by a float.
    I think it should be:
    Code:
    new Float:resist = 1.0 - (float(damageresist[victim])/100.0);
    psychonic is offline
    Tylerst
    Veteran Member
    Join Date: Oct 2010
    Old 02-01-2011 , 03:36   Re: [TF2] Dodge & Resist
    Reply With Quote #7

    Quote:
    @ Tylerst
    Before it can be approved, you need to load the common phrases translation file on plugin start or there will be errors if the target cannot be found.
    Doh, thats usually one of the first things I add to OnPluginStart, can't believe I missed it.

    Quote:
    Not critical, but IsClientInGame will return false if not connected, and a return a true on it implies connected so you can leave one check off.
    Ah, I'll have to remember that, thanks.

    Quote:
    Code:
    damage *= 0;
    Why not just = 0?
    Uh...good question?

    Quote:
    Code:
     
    new Float:resist = 1.0 - (damageresist[victim]/100.0);
    Is this giving the intended result? You're dividing an integer by a float.
    I think it should be:

    Code:
    new Float:resist = 1.0 - (float(damageresist[victim])/100.0);
    That had been working for us. Good point nonetheless, I changed it.






    Quote:
    Some less-important stuff:
    Consider adding lateload support for when the plugin is (re)loaded mid game (should just have to add looping through all clients at plugin start, adding the hook for those that are InGame).

    Another suggestion, maybe add cvars for default dodge and default resistance (maybe even per class?)
    Before I start working on adding cvars...
    Just to make sure, do you mean like this?
    PHP Code:
    public OnPluginStart()
    {  
         for (new 
    1<= MaxClientsi++)
         {
              if(
    IsClientInGame(i)) 
              { 
                    
    SDKHook(iSDKHook_OnTakeDamageOnTakeDamage)
              }  
         }  


    Unfortunately, my video card died last week, so I won't be able to test these changes for a little while, but I'll have it ready anyway.

    Last edited by Tylerst; 02-01-2011 at 03:38.
    Tylerst is offline
    psychonic

    BAFFLED
    Join Date: May 2008
    Old 02-01-2011 , 07:59   Re: [TF2] Dodge & Resist
    Reply With Quote #8

    Quote:
    Originally Posted by Tylerst View Post
    Just to make sure, do you mean like this?
    PHP Code:
    public OnPluginStart()
    {  
         for (new 
    1<= MaxClientsi++)
         {
              if(
    IsClientInGame(i)) 
              { 
                    
    SDKHook(iSDKHook_OnTakeDamageOnTakeDamage)
              }  
         }  

    Yup.
    psychonic is offline
    FlaminSarge
    Veteran Member
    Join Date: Jul 2010
    Old 02-01-2011 , 17:10   Re: [TF2] Dodge & Resist
    Reply With Quote #9

    I made some changes a bit back.

    Psy, if I use MAXPLAYERS + 1 instead of MaxClients, then I'm still good, right?

    Also, I renamed the smx so it has no spaces (for using /rcon to load/reload it)

    And when a client connects/disconnects, his dodge/resist settings are set back to 0 (so a client doesn't somehow gain another previous client's stuff).
    Attached Files
    File Type: sp Get Plugin or Get Source (tf2_dodge&resist.sp - 1041 views - 6.6 KB)
    __________________
    Bread EOTL GunMettle Invasion Jungle Inferno will break everything. Don't even ask.

    All plugins: Randomizer/GiveWeapon, ModelManager, etc.
    Post in plugin threads with questions.
    Steam is for playing games.
    You will be fed to javalia otherwise.
    Psyduck likes replays.
    FlaminSarge is offline
    Kevin_b_er
    SourceMod Donor
    Join Date: Feb 2009
    Old 02-01-2011 , 17:18   Re: [TF2] Dodge & Resist
    Reply With Quote #10

    Quote:
    Originally Posted by psychonic View Post
    @ Tylerist

    Code:
    new Float:resist = 1.0 - (damageresist[victim]/100.0);

    Is this giving the intended result? You're dividing an integer by a float.
    I think it should be:
    Code:
    new Float:resist = 1.0 - (float(damageresist[victim])/100.0);
    Not an issue.

    Code:
    stock Float:operator/(oper1, Float:oper2)
    {
        return FloatDiv(float(oper1), oper2);
    }
    What's more float/int or int/float will result in an int in most C-style languages. In this case, sourcepawn is no different.
    __________________
    Kevin_b_er 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 11:41.


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