[Cs:s] OnTakeDamage

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

[Cs:s] OnTakeDamage

Postby cssbestrpg » Sun Sep 27, 2020 1:18 pm

Hi, i have small issue OnTakeDamage code

Syntax: Select all

@EntityPreHook(EntityCondition.is_human_player, 'on_take_damage')
@EntityPreHook(EntityCondition.is_bot_player, 'on_take_damage')
def pre_damage(args):
index = index_from_pointer(args[0])
info = make_object(TakeDamageInfo, args[1])
chcc = C_CHANCE.get_float()

if info.attacker == info.inflictor:
_damage = info.damage

if info.type & 2:

try:
userid = rpglib.useridFromIndex(index)
except:
userid = None

if userid:
attacker = userid_from_inthandle(info.attacker)
attackerteam = rpglib.getTeam(attacker)

if attacker and attackerteam != rpglib.getTeam(userid):

if players[attacker]['m_iDamage']:
_damage += (_damage / 100.0) * players[attacker]['m_iDamage']
if players[attacker]['m_iCri']:
chcc = players[attacker]['m_iCri']
if random.randint(0, 100) <= chcc:
chcd = C_DMG.get_float()
if players[attacker]['critdamage']:
chcd = players[attacker]['critdamage']
_damage += (_damage / 100.0) * chcd
rpglib.playgamesound(attacker, 'weapons/fx/rics/ric%s.wav' % random.randint(1,4))
Delay(0, critical, (attacker,))
if players[userid]['m_iDamageReduction']:
_damage -= (_damage / 100.0) * players[userid]['m_iDamageReduction']

if players[attacker]['m_iLifesteal']:
_lifesteal = int((_damage / 100.0) * players[attacker]['m_iLifesteal'])
_current = rpglib.getHealth(attacker)
_max = players[attacker]['maxHealth']
if _current < _max:
_current += _lifesteal
if _current > _max:
_current = _max
rpglib.setHealth(attacker, _current)

if rpglib.isFrozen(userid):
_damage -= (_damage / 100.0) * 45
info.damage = _damage


In my rpgmod player have m_iDamage and enemy have m_iDamageReduction, the damage doesn't work correctly.
Tested at enemy had 30% m_iDamageReduction and i had 80% m_iDamage, i made under 400 dmg which doesn't make any sense.
I should make over 500 - 600 dmg, but why it made under 400dmg at awp at hs shot.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [Cs:s] OnTakeDamage

Postby L'In20Cible » Sun Sep 27, 2020 1:37 pm

Your target's helmet likely tanked a portion of the damage. Try on_take_damage_alive instead of on_take_damage.
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] OnTakeDamage

Postby cssbestrpg » Sun Sep 27, 2020 3:32 pm

At on_take_damage_alive no work at all, now even the damage doesn't change
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [Cs:s] OnTakeDamage

Postby VinciT » Sun Sep 27, 2020 6:17 pm

I'm pretty sure changing damage should work in the on_take_damage_alive hook. That's usually how I modify damage.

Syntax: Select all

# ../on_take_damage/on_take_damage.py

# Source.Python
from entities import TakeDamageInfo
from entities.hooks import EntityPreHook, EntityCondition


@EntityPreHook(EntityCondition.is_player, 'on_take_damage_alive')
def on_take_damage_alive_pre(stack_data):
info = TakeDamageInfo._obj(stack_data[1])
# Make all damage lethal.
info.damage = 100
Load this script and try shooting at bots/players - you'll notice that they die in one hit. I believe the only thing that doesn't change is the damage reported to the player (Damage Given to/Damage Taken from), as that is done in the OnTakeDamage() function.
ImageImageImageImageImage
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] OnTakeDamage

Postby cssbestrpg » Sun Sep 27, 2020 6:29 pm

VinciT wrote:I'm pretty sure changing damage should work in the on_take_damage_alive hook. That's usually how I modify damage.

Syntax: Select all

# ../on_take_damage/on_take_damage.py

# Source.Python
from entities import TakeDamageInfo
from entities.hooks import EntityPreHook, EntityCondition


@EntityPreHook(EntityCondition.is_player, 'on_take_damage_alive')
def on_take_damage_alive_pre(stack_data):
info = TakeDamageInfo._obj(stack_data[1])
# Make all damage lethal.
info.damage = 100
Load this script and try shooting at bots/players - you'll notice that they die in one hit. I believe the only thing that doesn't change is the damage reported to the player (Damage Given to/Damage Taken from), as that is done in the OnTakeDamage() function.


It seem work as separate plugin, but when tested with my rpgmod, it didn't modify damage at all, when had damage upgrade awp made hs 448 even suppose do 800
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] OnTakeDamage

Postby cssbestrpg » Sun Sep 27, 2020 6:38 pm

This is current code now i use

#=========================
# OnTakeDamage
#=========================

Syntax: Select all

@EntityPreHook(EntityCondition.is_human_player, 'on_take_damage_alive')# on_take_damage
@EntityPreHook(EntityCondition.is_bot_player, 'on_take_damage_alive')
def pre_damage(args):
index = index_from_pointer(args[0])
info = make_object(TakeDamageInfo, args[1])
chcc = C_CHANCE.get_float()

if info.attacker == info.inflictor:
_damage = info.damage

if info.type & 2:

try:
userid = rpglib.useridFromIndex(index)
except:
userid = None

if userid:
attacker = userid_from_inthandle(info.attacker)
attackerteam = rpglib.getTeam(attacker)

if attacker and attackerteam != rpglib.getTeam(userid):

if players[attacker]['m_iDamage']:
_damage += (_damage / 100.0) * players[attacker]['m_iDamage']
if players[attacker]['m_iCri']:
chcc = players[attacker]['m_iCri']
if random.randint(0, 100) <= chcc:
chcd = C_DMG.get_float()
if players[attacker]['critdamage']:
chcd = players[attacker]['critdamage']
_damage += (_damage / 100.0) * chcd
rpglib.playgamesound(attacker, 'weapons/fx/rics/ric%s.wav' % random.randint(1,4))
Delay(0, critical, (attacker,))
if players[userid]['m_iDamageReduction']:
_damage -= (_damage / 100.0) * players[userid]['m_iDamageReduction']

if players[attacker]['m_iLifesteal']:
_lifesteal = int((_damage / 100.0) * players[attacker]['m_iLifesteal'])
_current = rpglib.getHealth(attacker)
_max = players[attacker]['maxHealth']
if _current < _max:
_current += _lifesteal
if _current > _max:
_current = _max
rpglib.setHealth(attacker, _current)

if rpglib.isFrozen(userid):
_damage -= (_damage / 100.0) * 45
info.damage = _damage

when i shoot and have m_iDamage it shows at awp 448, thought it should increase it
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [Cs:s] OnTakeDamage

Postby VinciT » Tue Sep 29, 2020 2:03 am

cssbestrpg wrote:when i shoot and have m_iDamage it shows at awp 448, thought it should increase it
That's very strange.. Can you show me where you're setting the m_iDamage value?

And could you add this after the damage has been finalized?

Syntax: Select all

print(info.damage)
ImageImageImageImageImage
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] OnTakeDamage

Postby cssbestrpg » Tue Sep 29, 2020 9:32 am

This is the skill code that set m_iDamage

Syntax: Select all

SKILL_DETERIORA_PERCENT	= 2.0

@Event('rpg_playerspawn')
def rpg_playerspawn(args):
set_damage(args.get_int('userid'))

@Event('rpg_skillupgrade')
def rpg_skillupgrade(args):
if args.get_string('skill') == SKILL_NAME:
set_damage(args.get_int('userid'), 'add')

@Event('rpg_skilldowngrade')
def rpg_skilldowngrade(args):
if args.get_string('skill') == SKILL_NAME:
set_damage(args.get_int('userid'), 'remove')

def set_damage(userid, modify='spawn'):
if rpglib.isAlive(userid):
player = rpg.players[userid]
level = player[SKILL_NAME]

if modify == 'spawn':
player['m_iDamage'] += (SKILL_DETERIORA_PERCENT * level)
elif modify == 'add':
player['m_iDamage'] += SKILL_DETERIORA_PERCENT
elif modify == 'remove':
player['m_iDamage'] -= SKILL_DETERIORA_PERCENT


In console it prints this when i get hurted and i shoot back
435.0
609.0

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 13 guests