Raised This Month: $23 Target: $400
 5% 

[Solved] Prevent damage w/o Godmode


Post New Thread Reply   
 
Thread Tools Display Modes
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-27-2020 , 13:23   Re: Prevent damage w/o Godmode
Reply With Quote #11

Code:
#include <amxmodx> #include <cstrike> #include <hamsandwich> public plugin_init() {     register_plugin("Godmode", "1.0", "OciXCrom")     RegisterHam(Ham_TakeDamage, "player", "PreTakeDamage", 0) } public PreTakeDamage(iVictim, iInflictor, iAttacker, Float:fDamage, iDamageBits) {     return cs_get_user_team(iVictim) == cs_get_user_team(iAttacker) ? HAM_SUPERCEDE : HAM_IGNORED }
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-27-2020 , 20:07   Re: Prevent damage w/o Godmode
Reply With Quote #12

Quote:
Originally Posted by OciXCrom View Post
Code:
#include <amxmodx> #include <cstrike> #include <hamsandwich> public plugin_init() {     register_plugin("Godmode", "1.0", "OciXCrom")     RegisterHam(Ham_TakeDamage, "player", "PreTakeDamage", 0) } public PreTakeDamage(iVictim, iInflictor, iAttacker, Float:fDamage, iDamageBits) {     return cs_get_user_team(iVictim) == cs_get_user_team(iAttacker) ? HAM_SUPERCEDE : HAM_IGNORED }
That'll throw an error if attacker is worldspawn, or any non player
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>

#define IsPlayer(%1)    (1<=%1<=g_iMaxPlayers)

new g_iMaxPlayers;

public 
plugin_init()
{
    
register_plugin("Godmode""1.0""OciXCrom")
    
RegisterHam(Ham_TakeDamage"player""PreTakeDamage"0)

    
g_iMaxPlayers get_maxplayers();
}

public 
PreTakeDamage(iVictimiInflictoriAttackerFloat:fDamageiDamageBits)
{
    return 
IsPlayeriAttacker ) && ( cs_get_user_team(iVictim) == cs_get_user_team(iAttacker) ) ? HAM_SUPERCEDE HAM_IGNORED

__________________

Last edited by Bugsy; 06-27-2020 at 20:26.
Bugsy is offline
MaNaReaver
Member
Join Date: Apr 2020
Old 06-28-2020 , 22:36   Re: Prevent damage w/o Godmode
Reply With Quote #13

Quote:
Originally Posted by Bugsy View Post
That'll throw an error if attacker is worldspawn, or any non player
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>

#define IsPlayer(%1)    (1<=%1<=g_iMaxPlayers)

new g_iMaxPlayers;

public 
plugin_init()
{
    
register_plugin("Godmode""1.0""OciXCrom")
    
RegisterHam(Ham_TakeDamage"player""PreTakeDamage"0)

    
g_iMaxPlayers get_maxplayers();
}

public 
PreTakeDamage(iVictimiInflictoriAttackerFloat:fDamageiDamageBits)
{
    return 
IsPlayeriAttacker ) && ( cs_get_user_team(iVictim) == cs_get_user_team(iAttacker) ) ? HAM_SUPERCEDE HAM_IGNORED

Sorry for the delay in getting back. I tested this, and it still does damage to opposite team members. Just in case if this is not an override from my side, can you test it out and let me know? Again, can't be thankful enough for all of your help with this.
MaNaReaver is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-29-2020 , 08:11   Re: Prevent damage w/o Godmode
Reply With Quote #14

There's really no need to test. The code is pretty straight forward. It's a snippet that I use in all my plugins so there's nothing different here. You probably have another plugin that's blocking it. Try moving it in the beginning of plugins.ini.
__________________

Last edited by OciXCrom; 06-29-2020 at 08:11.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-29-2020 , 10:41   Re: Prevent damage w/o Godmode
Reply With Quote #15

There is no other plugin blocking it, I tried it on my server (max 1.9, no other plugins, all modules enabled), and it doesn't work for some reason. Debug doesn't show anything.
And I tried making my own version that didn't work, I couldn't find why
PHP Code:
#include <amxmodx>
#include <hamsandwich>

#define VERSION "2.0"

public plugin_init()
{
    
register_plugin("Something like a GodMode"VERSION"Mr. Boopsy");
    
RegisterHamHam_TakeDamage "player" "hp_reset" );
}

public 
hp_reset(iVictimiInflictoriAttackerfloat:fDamageDmgTypeBits)
{
    if(
iInflictor == iAttacker && iVictim != iAttacker)
    {
        return 
HAM_SUPERCEDE
    
}
    else
    {
        return 
HAM_IGNORED
    
}

__________________
Contact! || Discord:
Mr_Boopsy_#2066
supertrio17 is offline
MaNaReaver
Member
Join Date: Apr 2020
Old 06-29-2020 , 13:33   Re: Prevent damage w/o Godmode
Reply With Quote #16

Quote:
Originally Posted by supertrio17 View Post
There is no other plugin blocking it, I tried it on my server (max 1.9, no other plugins, all modules enabled), and it doesn't work for some reason. Debug doesn't show anything.
And I tried making my own version that didn't work, I couldn't find why
PHP Code:
#include <amxmodx>
#include <hamsandwich>

#define VERSION "2.0"

public plugin_init()
{
    
register_plugin("Something like a GodMode"VERSION"Mr. Boopsy");
    
RegisterHamHam_TakeDamage "player" "hp_reset" );
}

public 
hp_reset(iVictimiInflictoriAttackerfloat:fDamageDmgTypeBits)
{
    if(
iInflictor == iAttacker && iVictim != iAttacker)
    {
        return 
HAM_SUPERCEDE
    
}
    else
    {
        return 
HAM_IGNORED
    
}

Yeah, I disabled all plugins and tried again, but have no idea why it's still damaging others.
MaNaReaver is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 06-29-2020 , 14:04   Re: Prevent damage w/o Godmode
Reply With Quote #17

Quote:
Originally Posted by OciXCrom View Post
There's really no need to test. The code is pretty straight forward. It's a snippet that I use in all my plugins so there's nothing different here. You probably have another plugin that's blocking it. Try moving it in the beginning of plugins.ini.
The code you provided will block damage only if the victim team is same as attacker team, which means Friendly fire? Am i right?

He wants to block damage for everyone besides the bot
so it should be
Code:
#include <amxmodx> #include <cstrike> #include <hamsandwich> #define IsPlayer(%1)    (1<=%1<=g_iMaxPlayers) new g_iMaxPlayers; public plugin_init() {     register_plugin("Godmode", "1.0", "OciXCrom")     RegisterHam(Ham_TakeDamage, "player", "PreTakeDamage", 0)     g_iMaxPlayers = get_maxplayers(); } public PreTakeDamage(iVictim, iInflictor, iAttacker, Float:fDamage, iDamageBits) {     return IsPlayer( iAttacker ) ? HAM_SUPERCEDE : HAM_IGNORED }

Last edited by ZaX; 06-29-2020 at 19:25. Reason: edited IsPlayer according to post #21
ZaX is offline
MaNaReaver
Member
Join Date: Apr 2020
Old 06-29-2020 , 17:49   Re: Prevent damage w/o Godmode
Reply With Quote #18

Quote:
Originally Posted by ZaX View Post
The code you provided will block damage only if the victim team is same as attacker team, which means Friendly fire? Am i right?

He wants to block damage for everyone besides the bot
so it should be
Code:
#include <amxmodx> #include <cstrike> #include <hamsandwich> #define IsPlayer(%1)    (1<=%1<=g_iMaxPlayers) new g_iMaxPlayers; public plugin_init() {     register_plugin("Godmode", "1.0", "OciXCrom")     RegisterHam(Ham_TakeDamage, "player", "PreTakeDamage", 0)     g_iMaxPlayers = get_maxplayers(); } public PreTakeDamage(iVictim, iInflictor, iAttacker, Float:fDamage, iDamageBits) {     return IsPlayer( iVictim ) ? HAM_SUPERCEDE : HAM_IGNORED }
Hey ZaX, I tried out this, and it prevented damage to players, but the bots were unable to inflict damage. I just tweaked out Oci's plugin, and now it does as it was intended to do. Thank you everyone for taking your time out and helping me with this

PHP Code:
#include <amxmodx>
#include <cstrike>
#include <hamsandwich>

#define IsPlayer(%1)    (1<=%1<=g_iMaxPlayers)

new g_iMaxPlayers;

public 
plugin_init()
{
    
register_plugin("Godmode""1.0""OciXCrom")
    
RegisterHam(Ham_TakeDamage"player""PreTakeDamage"0)

    
g_iMaxPlayers get_maxplayers();
}

public 
PreTakeDamage(iVictimiInflictoriAttackerFloat:fDamageiDamageBits)
{
    return 
cs_get_user_team(iVictim) != cs_get_user_team(iAttacker) ? HAM_SUPERCEDE HAM_IGNORED

MaNaReaver is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-29-2020 , 18:05   Re: [Solved] Prevent damage w/o Godmode
Reply With Quote #19

Looks like I misread the request. The code blocked damage from the same team, not different. The above code does the job, but add the IsPlayer check as well.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
MaNaReaver
Member
Join Date: Apr 2020
Old 06-29-2020 , 18:20   Re: [Solved] Prevent damage w/o Godmode
Reply With Quote #20

Quote:
Originally Posted by OciXCrom View Post
Looks like I misread the request. The code blocked damage from the same team, not different. The above code does the job, but add the IsPlayer check as well.
Yeah, will do Should that be for the Victim or the Attacker?

Last edited by MaNaReaver; 06-29-2020 at 18:21.
MaNaReaver 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:01.


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