point_hurt: cs go

Please post any questions about developing your plugin here. Please use the search function before posting!
MrMalina
Member
Posts: 53
Joined: Mon Apr 08, 2013 2:40 pm
Location: Russian Federation

point_hurt: cs go

Postby MrMalina » Tue Apr 07, 2015 5:00 pm

I use the following code to damage:

Syntax: Select all

@Event
def player_jump(args):

index=index_from_userid(args.get_int("userid"))

player=PlayerEntity(index)

player.add_output("targetname Nyan")

point = BaseEntity(create_entity("point_hurt"))

point.add_output("DamageTarget Nyan")
point.add_output("damage 5")
point.add_output("radius 5")
point.add_output("damagetype 2")
point.add_output("classname point_hurt")

spawn_entity(point.index)

point.call_input("Hurt")
point.call_input("Kill")

player.add_output("targetname NotNyan")


How to deal damage to the player from another player?

ps. I saw examples of suursepavn to write this code, so maybe he is not too perfect.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Tue Apr 07, 2015 5:03 pm

You need to define the attacker as the caller:

Syntax: Select all

point.call_input("Hurt", caller=attacker.index)
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Tue Apr 07, 2015 5:53 pm

I would also like to mention that we have a method to cause damage. player.damage(...)
MrMalina
Member
Posts: 53
Joined: Mon Apr 08, 2013 2:40 pm
Location: Russian Federation

Postby MrMalina » Tue Apr 07, 2015 6:32 pm

I'm using the latest version of the source python (April 4). If you use the following code, I have an error.

Syntax: Select all

@Event
def player_jump(args):

index=index_from_userid(args.get_int("userid"))

player=PlayerEntity(index)

player.damage(5, DamageTypes.BULLET)


Error:
The attachment 1.jpg is no longer available
Attachments
1.jpg
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Tue Apr 07, 2015 6:44 pm

Oh, yeah. We haven't added that to CS:GO. Sorry. :)
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Tue Apr 07, 2015 6:51 pm

Hm, yeah. Also added as a signature for orangebox but we can certainly add it as a virtual method.

Replace the virtual_function section of your ../data/source-python/entities/managers/engines/csgo/CBaseEntity.ini file to the following:

Syntax: Select all

[virtual_function]

# _ZN11CBaseEntity18PassesDamageFilterERK15CTakeDamageInfo
[[take_damage]]
offset_linux = 65
offset_windows = 64
arguments = POINTER

# _ZN11CBaseEntity9SetParentEPS_i
[[set_parent]]
offset_linux = 39
offset_windows = 38
arguments = POINTER, INT
MrMalina
Member
Posts: 53
Joined: Mon Apr 08, 2013 2:40 pm
Location: Russian Federation

Postby MrMalina » Thu Apr 09, 2015 6:17 pm

When using this code, when you deal damage, the player at the beginning of dying himself, and then he dies from a player.
code:

Syntax: Select all

def damage(victim_index, attacker_index, damage=-1, damage_type=DamageTypes.FALL):

victim = BaseEntity(victim_index)

if damage == -1:
damage = 2**16

victim.add_output("targetname mrdamage")

point = BaseEntity(create_entity("point_hurt"))

point.add_output("DamageTarget mrdamage")
point.add_output("damage "+str(damage))
point.add_output("damagetype "+str(damage_type))
point.add_output("classname point_hurt")

point.call_input("Hurt", caller=attacker_index)
point.call_input("Kill")

victim.add_output("targetname mrhuman")


The attachment 2015-04-09_00003.jpg is no longer available


What is the problem?
Attachments
2015-04-09_00003.jpg
Predz
Senior Member
Posts: 158
Joined: Wed Aug 08, 2012 9:05 pm
Location: Bristol, United Kingdom

Postby Predz » Sat Apr 11, 2015 9:09 pm

Malina, every time you force damage using a point_hurt entity the engine will fire another player_hurt event. So therefore if you have the point_hurt being activated upon a take damage event, then you will cause an infinite loop until the player dies. You need to check the "weapon" argument inside the GameEvent instance provided, and stop running if it is a point_hurt entity causing the damage.
MrMalina
Member
Posts: 53
Joined: Mon Apr 08, 2013 2:40 pm
Location: Russian Federation

Postby MrMalina » Sun Apr 12, 2015 9:56 am

Yes, I use this code in player_hurt, but it can not be called twice, because I have a check for weapons, with which was damaged.
I use the following code to cause damage to the CS:GO of, as the other options do not work.

It does not cause any errors, just does not work. (I added virtual_function in ../engines/csgo/CBaseEntity.ini).

Syntax: Select all

def damage(victim_index, attacker_index, damage=-1, damage_type=32):
victim = BaseEntity(victim_index)

if damage == -1:
damage=victim.health

victim.damage(damage = int(damage), damage_type = damage_type, attacker = attacker_index, inflictor = victim_index)


Work, but a player dies from suicide.

Syntax: Select all

def damage(victim_index, attacker_index, damage=-1, damage_type=32):

victim = BaseEntity(victim_index)

if damage == -1:
damage = 2**16

victim.add_output("targetname mrdamage")

point = BaseEntity(create_entity("point_hurt"))

point.add_output("DamageTarget mrdamage")
point.add_output("damage "+str(damage))
point.add_output("damagetype "+str(damage_type))
point.add_output("classname weapon_awp")

point.call_input("Hurt", caller = attacker_index)
point.call_input("Kill")

victim.add_output("targetname mrhuman")



I tested this code in css, the player also die from suicide.

Code:

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================

# Source Python
from events import Event

from players.helpers import index_from_userid
from players.entity import PlayerEntity

from entities.helpers import spawn_entity
from entities.helpers import create_entity

from entities.entity import BaseEntity

# =============================================================================
# >> EVENTS
# =============================================================================
@Event
def player_hurt(args):
vindex = index_from_userid(args.get_int("userid"))
aindex = args.get_int("attacker")

print("weapon ->", args.get_string("weapon"))

if aindex:
aindex = index_from_userid(aindex)

damage(vindex, aindex)

# =============================================================================
# >> FUNCTIONS
# =============================================================================
def damage(victim_index, attacker_index, damage=-1, damage_type=32):

victim = BaseEntity(victim_index)

if damage == -1:
damage = 2**16

victim.add_output("targetname mrdamage")

point = BaseEntity(create_entity("point_hurt"))

point.add_output("DamageTarget mrdamage")
point.add_output("damage "+str(damage))
point.add_output("damagetype "+str(damage_type))
point.add_output("classname weapon_awp")

point.call_input("Hurt", caller = attacker_index)
point.call_input("Kill")

victim.add_output("targetname mrhuman")


console:
cons_er1.jpg


Game:
cons_er1.jpg
Attachments
game_er1.jpg
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Apr 12, 2015 1:16 pm

Instead of using player_hurt, you should just pre-hook OnTakeDamage and increase the damage amount.
Image
MrMalina
Member
Posts: 53
Joined: Mon Apr 08, 2013 2:40 pm
Location: Russian Federation

Postby MrMalina » Sun Apr 12, 2015 1:19 pm

There are cases where i need to inflict damage "out of nowhere", such as lightning in wcs.
When i can i do not use point_hurt, i use prehook system.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Apr 12, 2015 1:24 pm

Well, in those specific cases, then yes, you would need to create your own damage. However, anytime you just want to use player_hurt, you should instead hook OnTakeDamage. Either that or use a global variable to store a True/False value to make sure you don't continue damaging the player until they die. I do plan on adding a hurt method to BaseEntity, which will be just like the damage method except it will use a point_hurt entity. I also am still planning changes to the damage method to cause damage to the instance and not from the instance.
Image
MrMalina
Member
Posts: 53
Joined: Mon Apr 08, 2013 2:40 pm
Location: Russian Federation

Postby MrMalina » Sun Apr 12, 2015 1:31 pm

Great thanks for the reply. I'll be waiting for your updates, but also continue to experiment with my code.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Apr 12, 2015 6:20 pm

I don't think a hurt method is necessary. That entity itself calls TakeDamage on the activator. Would be pointless to increment the entity count when not needed. ^^
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Wed May 27, 2015 2:00 pm

Code: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
  File '..\addons\source-python\packages\source-python\listeners\tick\delays.py', line 60, in __call__
    self.callback(*self.args, **self.kwargs)
  File '..\addons\source-python\packages\source-python\listeners\tick\repeat.py', line 294, in _execute
    self.callback(*self.args, **self.kwargs)
  File '..\addons\source-python\plugins\dnd\dnd.py', line 591, in safeDamage
    point.add_output('DamageTarget DND_POINT_HURT_VICTIM')

AttributeError: 'BaseEntity' object has no attribute 'add_output'


Syntax: Select all

def safeDamage(victim, attacker, amount):

msg("%s is hurting %s for %s damage"%(attacker.name, victim.name, amount))

victim.add_output("targetname DND_POINT_HURT_VICTIM")
point = BaseEntity(create_entity("point_hurt"))

point.add_output("DamageTarget DND_POINT_HURT_VICTIM")
point.add_output("damage %s"%amount)
point.add_output("radius 5")
point.add_output("damagetype 2")
point.add_output("classname point_hurt")

spawn_entity(point.index)

point.call_input("Hurt", caller=attacker.index)
point.call_input("Kill")

player.add_output("targetname NOT_DND_POINT_HURT_VICTIM")


add_output is in CBaseEntity.ini but that looks like the only spot. Is this the correct syntax?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed May 27, 2015 2:14 pm

Don't use BaseEntity directly anymore. We have changed that classes name to Entity, since BaseEntity is now the internal CBaseEntity object. Also, Entity now has a create method, so you can just use:

Syntax: Select all

from entities.entity import Entity

point_hurt = Entity.create('point_hurt')


However, you should just be using the Entity.take_damage method to do damage anyway. The entity itself is now the 'victim' and you provide the attacker (if there is one).
Image
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Wed May 27, 2015 2:52 pm

I'd love to use Entity.take_damage in a prehook or player_hurt event. Is there a different way to do this to not cause infinite loops or is the entity creation the only real way?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed May 27, 2015 3:00 pm

If you are hooking on_take_damage, just adjust the damage of the TakeDamageInfo instance instead of dealing out more damage.
Image
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Wed May 27, 2015 3:09 pm

The damage isn't all dealt at once.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed May 27, 2015 3:16 pm

Well, deal what should be dealt at that time by modifying the TakeDamageInfo's damage value and then call <entity>.take_damage later to deal more damage. Just don't call <entity>.take_damage inside the on_take_damage hook or player_hurt. You 'could' also use a global variable to know when the script is dealing damage. Though, this is not recommended for most situations (if any):

Syntax: Select all

_dealing_damage = False


@Event
def player_hurt(game_event):
global _dealing_damage

if _dealing_damage:
_dealing_damage = False
return

# If you need to deal damage
_dealing_damage = True
<entity>.take_damage(...)
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 30 guests