Page 1 of 4

[HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 6:01 pm
by Painkiller
Good day all,

I have a plugin here is slightly older.

Cologne could help me to bring it on better in ES or also in SP code.
Perhaps also better in one plugin.

Thanks in advance

Orientation:

It causes a headshot + Sound and Overlay
And the head is bursting.


Syntax: Select all

import es
import gamethread
import playerlib

info = es.AddonInfo()
info.name = "RocKs Headshot"
info.version = "3.0"
info.author = "DMW"
info.url = "www.rocks-clan.de"
info.description = "RocKs Headshot"

es.ServerVar(info.name, info.version, info.description).makepublic()

#>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#>>>>>>>>>>>>>>>>>>>>>> C O N F I G <<<<<<<<<<<<<<<<<<<<<<<<<<<<
#>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

REMOVE_OVERLAY_TIME = 1.5
HEADSHOT_OVERLAY_VMT = "exae/rocksheadshot1.vmt"
HEADSHOT_OVERLAY_VTF = "exae/rocksheadshot1.vtf"

# Headshot but not dead sound + path
HEADSHOT_SOUND = "exae/quake/human-hit-4.mp3"

# <weapon> : <headshot_sound>
WEAPON_FILES = {
'weapon_crossbow_bolt': 'exae/quake/headshot2.mp3',
'weapon_357' : 'exae/quake/headshot-2.mp3',
'weapon_smg1' : 'exae/quake/wife-headshot.mp3',
'weapon_ar2' : 'exae/quake/boomheadshot.mp3',
'weapon_pistol' : 'exae/quake/headshot-1.mp3',
'weapon_shotgun' : 'exae/quake/headshot2.mp3'
}

#>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#>>>>>>>>>>>>>> E N D O F C O N F I G <<<<<<<<<<<<<<<<<<<<<
#>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

def event_hitgroup(event_var):
hitgroup = int(event_var['hitgroup'])
weapon = event_var['weapon']
health = int(event_var['health'])
attacker = int(event_var['attacker'])
victim = event_var['victim']
if attacker in (victim, None, 0):
return
if hitgroup == 1 and health == 0 and weapon in WEAPON_FILES: # Player is dead
es.cexec(attacker, "r_screenoverlay %s" %HEADSHOT_OVERLAY_VMT)
es.emitsound('player', attacker, WEAPON_FILES[weapon], 1.0, 0.0)
gamethread.delayed(REMOVE_OVERLAY_TIME, es.cexec, args=(attacker, "r_screenoverlay 0"))
doEffect(attacker, victim)
elif hitgroup == 1 and health > 0: # Headshot but player still alive
es.playsound(attacker, HEADSHOT_SOUND, 1.0)



def doEffect(attacker, victim):
x,y,z = es.getplayerlocation(victim)
z += 70
es.server.queuecmd("es est_effect 11 #a 0 exae/headshot/headshot_gore1.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.delayed(0.12, "es est_effect 11 #a 0 exae/headshot/headshot_gore2.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.delayed(0.18, "es est_effect 11 #a 0 exae/headshot/headshot_gore3.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.delayed(0.24, "es est_effect 11 #a 0 exae/headshot/headshot_gore4.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.delayed(0.30, "es est_effect 11 #a 0 exae/headshot/headshot_gore5.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.delayed(0.36, "es est_effect 11 #a 0 exae/headshot/headshot_gore6.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.delayed(0.42, "es est_effect 11 #a 0 exae/headshot/headshot_gore7.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.delayed(0.48, "es est_effect 11 #a 0 exae/headshot/headshot_gore8.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.delayed(0.54, "es est_effect 11 #a 0 exae/headshot/headshot_gore9.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.delayed(0.60, "es est_effect 11 #a 0 exae/headshot/headshot_gore10.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.delayed(0.66, "es est_effect 11 #a 0 exae/headshot/headshot_gore11.vmt %s %s %s 0.06 0.3 255" % (x, y, z))
es.server.queuecmd("es playerset model event_var(userid) headless_body/metrocop.mdl")


def player_spawn(ev):
is_spawned = getUser(ev['userid'], "is_spawned")
if is_spawned == 0:
setUser(ev['userid'], "is_spawned", 1)
model = playerlib.getPlayer(ev['userid']).model
setUser(ev['userid'], "model", model)
if is_spawned == 1:
playerlib.getPlayer(ev['userid']).setModel(getUser(ev['userid'], "model"))


def make_loadable():
for file in WEAPON_FILES.values():
es.stringtable("downloadables", 'sound/'+file)
es.stringtable("downloadables", 'sound/'+HEADSHOT_SOUND)
es.stringtable("downloadables", 'materials/'+HEADSHOT_OVERLAY_VMT)
es.stringtable("downloadables", 'materials/'+HEADSHOT_OVERLAY_VTF)

def load():
make_loadable()

def es_map_start(event_var):
make_loadable()

keys = {}


def addUser(userid):
userid = str(userid)
if not userid in keys:
keys[userid] = {}

def delUser(userid):
userid = str(userid)
if userid in keys:
del keys[userid]

def existsUser(userid):
userid = str(userid)
return userid in keys

def setUser(userid, key, value):
userid = str(userid)
addUser(userid)
keys[userid][key] = value

def getUser(userid, key):
userid = str(userid)
addUser(userid)
if key in keys[userid]:
value = str(keys[userid][key])
if value.isdigit():
return int(value)
return value
return None




Syntax: Select all

import spe
import es

from spe import HookAction
from spe import HookType
from spe import Conventions

PATH_RES = 'addons/eventscripts/custom_events/custom_events.res'

def load():
es.loadevents('declare', PATH_RES)
es.loadevents(PATH_RES)
spe.hookFunction(FUNC, 'piS)v', Conventions.CDECL, HookType.Pre,
preHook)

def unload():
spe.unHookFunction(FUNC, HookType.Pre, preHook)

def es_map_start(event_var):
es.loadevents(PATH_RES)


#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>> Bullet Impact
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# event_var['x']
# event_var['y']
# event_var['z']

FUNC = spe.findSymbol('_Z16UTIL_ImpactTraceP10CGameTraceiPKc')

def preHook(args):
x = spe.makeObject('Vector', args[0] + 12)
es.event('initialize', "event_bullet_impact")
es.event('setfloat', "event_bullet_impact", "x", x.x)
es.event('setfloat', "event_bullet_impact", "y", x.y)
es.event('setfloat', "event_bullet_impact", "z", x.z)
es.event('fire', "event_bullet_impact")
return (HookAction.Continue, 0)


#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>> Hitgroups
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# event_var['hitgroup']
# event_var['attacker']
# event_var['victim']
# event_var['weapon']
# event_var['health']

OFFSET_HITGROUP = 1708 if spe.platform == 'nt' else 1728

def player_hurt(ev):
player = spe.getPlayer(int(ev['userid']))
hitgroup = spe.getLocVal('i', player + OFFSET_HITGROUP)
fire_event(hitgroup, ev['userid'], ev['attacker'], ev['es_attackerweapon'], ev['health'])

def fire_event(hitgroup, userid, attacker, weapon, health):
es.event('initialize', "event_hitgroup")
es.event('setint', "event_hitgroup", "hitgroup", hitgroup)
es.event('setint', "event_hitgroup", "attacker", attacker)
es.event('setint', "event_hitgroup", "victim", userid)
es.event('setstring', "event_hitgroup", "weapon", weapon)
es.event('setint', "event_hitgroup", "health", health)
es.event('fire', "event_hitgroup")
#http://www.eventscripts.com/pages/Hit_Groups

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 7:24 pm
by satoon101
This should be everything except for the effect. I'm not sure what est_effect11 does, and I'm not in a position to check at this moment. Note that this is untested, so please let us know if you have issues/errors.

Syntax: Select all

from contextlib import suppress

from engines.precache import Model
from engines.sound import Sound
from entities import TakeDamageInfo
from entities.entity import Entity
from entities.hooks import EntityCondition, EntityPreHook
from events import Event
from listeners.tick import Delay
from memory import make_object
from players.constants import HitGroup
from players.entity import Player
from stringtables.downloads import Downloadables


# =============================================================================
# >> CONFIGURATION
# =============================================================================
REMOVE_OVERLAY_TIME = 1.5
HEADSHOT_OVERLAY_VMT = "exae/rocksheadshot1.vmt"
HEADSHOT_OVERLAY_VTF = "exae/rocksheadshot1.vtf"

# Headshot but not dead sound + path
HEADSHOT_SOUND = 'exae/quake/human-hit-4.mp3'

# <weapon> : <headshot_sound>
WEAPON_FILES = {
'weapon_crossbow': 'exae/quake/headshot2.mp3',
'weapon_357' : 'exae/quake/headshot-2.mp3',
'weapon_smg1' : 'exae/quake/wife-headshot.mp3',
'weapon_ar2' : 'exae/quake/boomheadshot.mp3',
'weapon_pistol' : 'exae/quake/headshot-1.mp3',
'weapon_shotgun' : 'exae/quake/headshot2.mp3'
}

DEAD_MODEL = 'headless_body/metrocop.mdl'
# =============================================================================
# >> END OF CONFIGURATION
# =============================================================================


HEADSHOT_SOUND = Sound(HEADSHOT_SOUND, download=True)
WEAPON_FILES = {x: Sound(y, download=True) for x, y in WEAPON_FILES.items()}
downloads = Downloadables()
for item in (HEADSHOT_OVERLAY_VMT, HEADSHOT_OVERLAY_VTF):
downloads.add('materials/' + item)
DEAD_MODEL = Model(
path=DEAD_MODEL,
preload=True,
download=True,
)

_old_models = {}
_damage_weapons = {}


@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

victim = Player(victim.index)
info = make_object(TakeDamageInfo, stack_data[1])

# World damage?
if info.attacker == 0:
_damage_weapons[victim.userid] = 'worldspawn'

# Was a projectile used?
elif info.attacker != info.inflictor:
_damage_weapons[victim.userid] = Entity(info.inflictor).classname

# Not a projectile
else:
_damage_weapons[victim.userid] = Player(info.attacker).active_weapon.classname


@Event('player_hurt')
def player_hurt(game_event):
victim = Player.from_userid(game_event['userid'])
attacker = game_event['attacker']

# Suicide?
if attacker in (victim.userid, 0):
return

# Not a headshot?
if victim.hitgroup != HitGroup.HEAD:
return

# Victim still alive?
if game_event['health']:
HEADSHOT_SOUND.index = victim.index
HEADSHOT_SOUND.play(victim.index)
return

weapon_sound = WEAPON_FILES.get(_damage_weapons.get(victim.userid))
if weapon_sound is None:
return

# Play weapon specific headshot sound
weapon_sound.index = victim.index
weapon_sound.play()

# Set the victim's overlay
victim.client_command(
'r_screenoverlay {overlay}'.format(
overlay= HEADSHOT_OVERLAY_VMT
)
)
Delay(REMOVE_OVERLAY_TIME, _remove_overlay, [victim.userid])

# Set the victim's model
_old_models[victim.userid] = victim.model
victim.model = DEAD_MODEL


@Event('player_spawn')
def _reset_model(game_event):
userid = game_event['userid']
old_model = _old_models.pop(userid, None)
if old_model is not None:
Player.from_userid(userid).model = old_model


def _remove_overlay(userid):
with suppress(Exception):
Player.from_userid(userid).client_command('r_screenoverlay 0')

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 10:27 pm
by satoon101
Actually, I just realized there are 2 issues with the plugin I posted, both have to do with the weapon check. I updated the first post with a new version that I think fixes both of those issues.

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 10:42 pm
by Painkiller

Code: Select all

[SP] Unable to unload plugin 'headshot' as it is not currently loaded.
[SP] Loading plugin 'headshot'...

[SP] Caught an Exception:
Traceback (most recent call last):  File "../addons/source-python/packages/source-python/plugins/manager.py", line 75, in __missing__
    instance = self.instance(plugin_name, self.base_import)  File "../addons/source-python/packages/source-python/plugins/instance.py", line 82, in __init__
    self._plugin = import_module(import_name)
  File "../addons/source-python/plugins/headshot/headshot.py", line 93
    if game_event['health']
                          ^

SyntaxError: invalid syntax


[SP] Plugin 'headshot' was unable to be loaded.

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 10:54 pm
by satoon101
Sorry, it was missing a :

I updated the plugin above.

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 10:55 pm
by Painkiller
NP

Code: Select all

[SP] Plugin 'headshot' was unable to be loaded.
sp relo
Sub command "relo" not found.
sp plugin reload headshot
[SP] Unable to unload plugin 'headshot' as it is not currently loaded.
[SP] Loading plugin 'headshot'...

[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/source-python/plugins/manager.py", line 75, in __missing__
    instance = self.instance(plugin_name, self.base_import)
  File "../addons/source-python/packages/source-python/plugins/instance.py", line 82, in __init__
    self._plugin = import_module(import_name)
  File "../addons/source-python/plugins/headshot/headshot.py", line 11, in <module>
    from player.constants import HitGroup

ImportError: No module named 'player'


[SP] Plugin 'headshot' was unable to be loaded.



OFFSET_HITGROUP = 1708 if spe.platform == 'nt' else 1728

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 10:56 pm
by satoon101
Fixed above.

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 11:07 pm
by Painkiller
Ok it works partially.

i see no overlays,Sound comes only at 357, ar2, smg 1, pistol.
Not shotgun and crossbow sounds and the corpse disappears

Code: Select all

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

AttributeError: Attribute "active_weapon" not found


Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 11:15 pm
by iPlayer
Are you sure you're running the latest Source.Python build?

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 11:17 pm
by Painkiller
oO i see 16 October

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 11:19 pm
by satoon101
That error makes no sense to me, as Player.active_weapon certainly does exist. Which version of Source.Python are you running? And, when you're updating your SP version on the server, make sure to follow the updating instructions:
http://wiki.sourcepython.com/general/updating.html

I will have to run some tests to find out why shotgun isn't working. I think I might know why crossbow isn't, but I'll have to run some tests for that, too. I won't have time to do any of that until tomorrow night after work at the earliest.

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 11:32 pm
by Painkiller
I have updating SP and i have delete in steam folder
exae/rocksheadshot1.vtf
exae/rocksheadshot1.vmt

and join the server but no downloaded the files.

Thanks Satoon

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 11:35 pm
by satoon101
Ahhh, I misspelled it, sorry. I had material instead of materials when adding them to the Downloadables. Updated the plugin above.

Re: [HL2:DM] Headshot Help

Posted: Sun Oct 16, 2016 11:41 pm
by Painkiller
Ok it`s the same problem I can not see any overlay.

But the files downloaded ok.

Re: [HL2:DM] Headshot Help

Posted: Mon Oct 17, 2016 4:29 am
by iPlayer
Because, from my experience, you should not include the .vmt extension in r_screenoverlay command.

And by the way, to turn the overlay off, it's r_screenoverlay off.
r_screenoverlay 0 would probably start searching for materials/0.vmt to display.

Re: [HL2:DM] Headshot Help

Posted: Mon Oct 17, 2016 4:46 am
by satoon101
I'm fairly certain I have typically (if not always) seen the extension included with the command and using 0 as an 'off' value. I believe the code in the first post (an ES script) works (or at least worked) previously, though I don't fully know cause it isn't my code. r_screenoverlay isn't something I have ever used myself and have a tremendous amount of knowledge about, but I have helped others with their scripts/plugins that utilized it.

Re: [HL2:DM] Headshot Help

Posted: Mon Oct 17, 2016 6:42 am
by L'In20Cible
If I remember correctly, you need to emulate the command server-side using server_side=True otherwise you tell the client to execute it which requires sv_cheats enabled for him to do so.

EDIT: Just made some testing, and this is not right. Emulating it server-side won't work, while server_side=False will work as the command has the server_can_execute flag. As for the value to turn it off, any invalid value will do so. I'm pretty sure 0 would work if it was a valid file, just like off would too. Not sure why the code above is not working.

Re: [HL2:DM] Headshot Help

Posted: Mon Oct 17, 2016 4:05 pm
by Painkiller
Hello i have updated today "source-python-hl2dm-October-17-2016.zip"
and now, I hear no more sound.

I find it strange

Every time I update SP does not work any more or several things.

Re: [HL2:DM] Headshot Help

Posted: Wed Oct 19, 2016 6:58 am
by Painkiller
Hello ,
Are there any new insights?

Re: [HL2:DM] Headshot Help

Posted: Wed Oct 19, 2016 10:53 am
by Painkiller
Sorry but I'm not very good in English.

I have probably not understood everything.

What the nice scripters said when it comes to code language, it brakes with me but something more.