Page 1 of 3

[HL2:DM] es_blood to sp blood

Posted: Thu Dec 29, 2016 4:46 am
by Painkiller
Hi all,

I can not say exactly what it does.

I know but the one explosion near a person an effect triggers smoke overlay.

It would nevertheless be very nice if the complete script could be rewritten.

Syntax: Select all

}


block fragcloud
{

es_setinfo fragcloudtype 0
es_rand fragcloudtype 2 2
es_give event_var(userid) env_ar2explosion

if (server_var(fragcloudtype) == 1) do
{
es_fire event_var(userid) env_ar2explosion addoutput "Material smoke/smokeball-11-4.vmt"
}

if (server_var(fragcloudtype) == 2) do
{
es_fire event_var(userid) env_ar2explosion addoutput "Material smoke/smokeball-11-4.vmt"
}

es_delayed 0.01 es_fire event_var(userid) env_ar2explosion explode
es_delayed 8 es_fire event_var(userid) env_ar2explosion Kill
es_delayed 10 es_xcreateentitylist clouds env_ar2explosion
es_delayed 10 es_foreachkey cloud in clouds "es_fire event_var(userid) server_var(cloud) Kill"
es_delayed 10 es_xkeygroupdelete clouds

Re: [HL2:DM] es_blood to sp blood

Posted: Thu Dec 29, 2016 10:53 am
by Ayuto
est_blood isn't used anywhere in that script. Also, the script isn't complete. It's just a fragment that doesn't do anything if it doesn't get called.

Re: [HL2:DM] es_blood to sp blood

Posted: Thu Dec 29, 2016 11:48 am
by L'In20Cible
I assume "es_blood" is the name of the script.

Re: [HL2:DM] es_blood to sp blood

Posted: Thu Dec 29, 2016 1:31 pm
by Painkiller
delete

Re: [HL2:DM] es_blood to sp blood

Posted: Thu Dec 29, 2016 2:17 pm
by Ayuto
After talking with Painkiller via Steam it seems like something like this was requested.

Syntax: Select all

import memory
from entities.entity import Entity
from events import Event
from players.entity import Player

PLAYER_HURT_TRIGGERS = [
'weapon_frag',
'weapon_smg1',
'weapon_rpg',
'weapon_slam',
]

@Event('player_hurt')
def player_hurt(event):
attacker_id = event['attacker']
if attacker_id == 0:
return

attacker = Player.from_userid(attacker_id)
weapon = attacker.active_weapon.classname
if weapon in PLAYER_HURT_TRIGGERS:
fragcloud(Player.from_userid(event['userid']))

def fragcloud(victim):
entity = memory.make_object(Entity, victim.give_named_item('env_ar2explosion'))
entity.set_key_value_string('material', 'smoke/smokeball-11-4.vmt')
entity.call_input('Explode')
entity.delay(8, entity.remove)

Re: [HL2:DM] es_blood to sp blood

Posted: Thu Dec 29, 2016 3:23 pm
by Painkiller
Ok i have test it but no work.

Re: [HL2:DM] es_blood to sp blood

Posted: Thu Dec 29, 2016 5:12 pm
by satoon101
What exactly doesn't work? We need details to help fix it.

Re: [HL2:DM] es_blood to sp blood

Posted: Thu Dec 29, 2016 5:47 pm
by Painkiller
It does not work
Loads normally but no error message

Re: [HL2:DM] es_blood to sp blood

Posted: Thu Dec 29, 2016 9:52 pm
by L'In20Cible
According to the SDK, the following line:

Syntax: Select all

entity.call_input('explode')
Should be:

Syntax: Select all

entity.call_input('Explode')

Re: [HL2:DM] es_blood to sp blood

Posted: Fri Dec 30, 2016 1:36 am
by Painkiller
L'In20Cible wrote:According to the SDK, the following line:

Syntax: Select all

entity.call_input('explode')
Should be:

Syntax: Select all

entity.call_input('Explode')


No chance not work. loads again good.
I have test with standart overlay, its from the game.

Syntax: Select all

from entities.entity import Entity
from events import Event
from players.entity import Player

PLAYER_HURT_TRIGGERS = [
'rpg_missile',
'tank',
'grenade_frag',
'smg1_grenade',
]

PLAYER_DEATH_TRIGGERS = [
'physics',
'rpg_missile',
'grenade_frag',
'smg1_grenade',
]

@Event('player_hurt')
def player_hurt(event):
if event['weapon'] in PLAYER_HURT_TRIGGERS:
fragcloud(Player.from_userid(event['userid']))

@Event('player_death')
def player_death(event):
if event['weapon'] in PLAYER_DEATH_TRIGGERS:
fragcloud(Player.from_userid(event['userid']))

def fragcloud(victim):
entity = memory.make_object(Entity, victim.give_named_item('env_ar2explosion'))
entity.set_key_value_string('material', 'particle/particle_smokegrenade1.vmt')
entity.spawn()
entity.call_input('Explode')
entity.delay(8, entity.remove)

Re: [HL2:DM] es_blood to sp blood

Posted: Fri Dec 30, 2016 1:38 pm
by Ayuto
L'In20Cible was right about the upper and lower case. I also fixed the missing memory import.

I guess the reason why you didn't see any exceptions is that I made a small mistake when I updated the logging format two weeks ago. Due to this mistake exceptions were only shown like this:

Code: Select all

2016-12-30 14:20:33 - sp   -   EXCEPTION   {message}
Please update your Source.Python installation and the plugin I have updated above. Then restart your server and test again.

Re: [HL2:DM] es_blood to sp blood

Posted: Fri Dec 30, 2016 2:10 pm
by satoon101
I think having the same functionality in player_death as in player_hurt is a bit redundant. If someone dies from one of those weapons, they were obviously hurt by that weapon to cause their death.

Also, I'm not sure that those are the proper trigger names. It has been a long time since I tested, so I don't fully remember, but I believe that the projectile weapons in our data are the weapons in player_hurt/death:
https://github.com/Source-Python-Dev-Te ... mp.ini#L6-#L11

physics is probably correct for the weapon when using the physcannon.

The best way to test this is for you to use each weapon and kill an enemy while the following plugin is loaded, and post the output here:

Syntax: Select all

from events import Event

@Event('player_hurt', 'player_death')
def _print_weapon(game_event):
print(
'{event}: {weapon}'.format(
event=game_event.name,
weapon=game_event['weapon']
)
)

Re: [HL2:DM] es_blood to sp blood

Posted: Fri Dec 30, 2016 2:55 pm
by Ayuto
Well, that also what the old script did, but Painkiller just told me that he doesn't need it in player_death. However, there was also an issue with the player_hurt event, because the "weapon" data doesn't exist in HL2:DM, which caused another error. I have updated the plugin again to work around that issue.

Re: [HL2:DM] es_blood to sp blood

Posted: Fri Dec 30, 2016 2:59 pm
by satoon101
I was wondering about that, but couldn't remember. Well, it would probably be better to use a hook for OnTakeDamage then, because by the time a frag explodes, the player could have changed weapons.

Re: [HL2:DM] es_blood to sp blood

Posted: Fri Dec 30, 2016 3:27 pm
by Ayuto
Feel free to do that. :grin: I hate writing things you can't test.

Re: [HL2:DM] es_blood to sp blood

Posted: Fri Dec 30, 2016 3:42 pm
by satoon101
When I get home next week, I can work on this further. For now, using this post as a guide, the following might work:

Syntax: Select all

from entities import TakeDamageInfo
from entities.entity import Entity
from entities.hooks import EntityCondition, EntityPreHook
from memory import make_object
from players.entity import Player
from weapons.manager import weapon_manager


DAMAGE_TRIGGERS = [
'weapon_frag',
'weapon_smg1',
'weapon_rpg',
'weapon_slam',
]

@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def _pre_take_damage(stack_data):
victim = make_object(Entity, stack_data[0])
if not victim.is_player():
return

info = make_object(TakeDamageInfo, stack_data[1])

# World damage?
if info.attacker == 0:
return

# Was a projectile used?
if info.attacker != info.inflictor:
weapon = Entity(info.inflictor).classname

# Not sure if this line is necessary, but just in case
weapon = weapon_manager[weapon].name

# Not a projectile
else:
weapon = Player(info.attacker).active_weapon.classname

if weapon in DAMAGE_TRIGGERS:
fragcloud(Player(victim.index))


def fragcloud(victim):
entity = make_object(Entity, victim.give_named_item('env_ar2explosion'))
entity.set_key_value_string('material', 'smoke/smokeball-11-4.vmt')
entity.call_input('Explode')
entity.delay(8, entity.remove)

Re: [HL2:DM] es_blood to sp blood

Posted: Fri Dec 30, 2016 4:18 pm
by Ayuto
I just remembered that we have added a neat property to simplify this part:

Syntax: Select all

# Was a projectile used?
if info.attacker != info.inflictor:
weapon = Entity(info.inflictor).classname

# Not sure if this line is necessary, but just in case
weapon = weapon_manager[weapon].name

# Not a projectile
else:
weapon = Player(info.attacker).active_weapon.classname
It could simply be:

Syntax: Select all

weapon_index = info.weapon

https://github.com/Source-Python-Dev-Te ... #L105-L124

Re: [HL2:DM] es_blood to sp blood

Posted: Fri Dec 30, 2016 10:13 pm
by Painkiller
satoon101 wrote:When I get home next week, I can work on this further. For now, using this post as a guide, the following might work:

Syntax: Select all

from entities import TakeDamageInfo
from entities.entity import Entity
from entities.hooks import EntityCondition, EntityPreHook
from memory import make_object
from players.entity import Player
from weapons.manager import weapon_manager


DAMAGE_TRIGGERS = [
'weapon_frag',
'weapon_smg1',
'weapon_rpg',
'weapon_slam',
]

@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def _pre_take_damage(stack_data):
victim = make_object(Entity, stack_data[0])
if not victim.is_player():
return

info = make_object(TakeDamageInfo, stack_data[1])

# World damage?
if info.attacker == 0:
return

# Was a projectile used?
if info.attacker != info.inflictor:
weapon = Entity(info.inflictor).classname

# Not sure if this line is necessary, but just in case
weapon = weapon_manager[weapon].name

# Not a projectile
else:
weapon = Player(info.attacker).active_weapon.classname

if weapon in DAMAGE_TRIGGERS:
fragcloud(Player(victim.index))


def fragcloud(victim):
entity = make_object(Entity, victim.give_named_item('env_ar2explosion'))
entity.set_key_value_string('material', 'smoke/smokeball-11-4.vmt')
entity.call_input('Explode')
entity.delay(8, entity.remove)


Ok Satoon,
it works grenade, rpg, smg1_grenade but not for slam and barrels.
No Errors.

Re: [HL2:DM] es_blood to sp blood

Posted: Wed Jan 04, 2017 12:36 pm
by Painkiller
Its Done thanks on all.

Re: [HL2:DM] es_blood to sp blood

Posted: Mon Jan 23, 2017 5:16 pm
by Painkiller
Hello with the newest SP update broke this plugin.

Syntax: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/plugins/explosive/explosive.py", line 43, in _pre_take_damage
weapon = Player(info.attacker).active_weapon.classname
File "../addons/source-python/packages/source-python/entities/_base.py", line 116, in __getattr__
raise AttributeError('Attribute "{0}" not found'.format(attr))

AttributeError: Attribute "active_weapon" not found


Syntax: Select all

[SP] Caught an Exception:
Traceback (most recent call last):
File "../addons/source-python/plugins/explosive/explosive.py", line 39, in _pre_take_damage
weapon = weapon_manager[weapon].name

AttributeError: 'NoneType' object has no attribute 'name'


Current code:

Syntax: Select all

from stringtables.downloads import Downloadables

dl = Downloadables()
dl.add('materials/smoke/smokeball-11-4.vmt')


from entities import TakeDamageInfo
from entities.entity import Entity
from entities.hooks import EntityCondition, EntityPreHook
from memory import make_object
from players.entity import Player
from weapons.manager import weapon_manager


DAMAGE_TRIGGERS = [
'weapon_frag',
'smg1_grenade',
'weapon_rpg',
'weapon_slam',
]

@EntityPreHook(EntityCondition.is_player, 'on_take_damage')
def _pre_take_damage(stack_data):
victim = make_object(Entity, stack_data[0])
if not victim.is_player():
return

info = make_object(TakeDamageInfo, stack_data[1])

# World damage?
if info.attacker == 0:
return

# Was a projectile used?
if info.attacker != info.inflictor:
weapon = Entity(info.inflictor).classname

# Not sure if this line is necessary, but just in case
weapon = weapon_manager[weapon].name

# Not a projectile
else:
weapon = Player(info.attacker).active_weapon.classname

if weapon in DAMAGE_TRIGGERS:
fragcloud(Player(victim.index))


def fragcloud(victim):
entity = make_object(Entity, victim.give_named_item('env_ar2explosion'))
entity.set_key_value_string('material', 'smoke/smokeball-11-4.vmt')
entity.call_input('Explode')
entity.delay(8, entity.remove)