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

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Senior Member
Posts: 722
Joined: Sun Mar 01, 2015 8:09 am
Location: Germany

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

Postby Painkiller » Tue Feb 15, 2022 6:55 am

Helloe People,
i found this error in the logs.

Code: Select all

2022-02-14 23:25:50 - sp   -   EXCEPTION   
[SP] Caught an Exception:
Traceback (most recent call last):
  File "../addons/source-python/packages/custom/hl2mp_event_npc_death/", line 86, in _on_entity_output
    if activator.is_player():

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

Syntax: Select all

from entities import TakeDamageInfo
from entities.entity import Entity
from entities.hooks import EntityCondition, EntityPreHook, EntityPostHook
from events.custom import CustomEvent
from events.variable import ShortVariable, StringVariable
from events.resource import ResourceFile
from listeners import OnEntityOutput, OnNetworkedEntityDeleted
from memory import make_object
from memory.hooks import use_pre_registers
from players.helpers import userid_from_index

# Used to match entity classnames to weapons used by player_death
'npc_grenade_frag': 'grenade_frag',
'prop_physics_multiplayer': 'physics',
'prop_physics': 'physics',
'func_physbox_multiplayer': 'physics',
'func_physbox': 'physics',
'npc_tripmine': 'slam', # Planted on the surface
'npc_satchel': 'slam', # Dropped on the floor
'crossbow_bolt': 'crossbow_bolt',
'grenade_ar2': 'smg1_grenade',
'prop_combine_ball': 'combine_ball',
'rpg_missile': 'rpg_missile',

_take_damage_contexts = {}

def _add_take_damage_context(index, info):
_take_damage_contexts.setdefault(index, []).append(info)

def _remove_take_damage_context(index):
except KeyError:

def get_take_damage_context(index):
return _take_damage_contexts[index][-1]
except (KeyError, IndexError):
return None

def _on_entity_deleted(entity):
_take_damage_contexts.pop(entity.index, None)

@EntityPreHook(EntityCondition.equals_entity_classname('npc_zombie'), 'on_take_damage')
def _pre_on_take_damage(args):
entity = make_object(Entity, args[0])
if not entity.classname.startswith('npc_'):

info = make_object(TakeDamageInfo, args[1])
_add_take_damage_context(entity.index, info)

@EntityPostHook(EntityCondition.equals_entity_classname('npc_zombie'), 'on_take_damage')
def _post_on_take_damage(args, ret_val):
with use_pre_registers(args, True):
entity = make_object(Entity, args[0])
if not entity.classname.startswith('npc_'):


def _on_entity_output(output_name, activator, caller, value, delay):
if output_name != 'OnDeath' or not caller.classname.startswith('npc_'):

info = get_take_damage_context(caller.index)

with NPC_Death() as event:
event.npc_index = caller.index
event.npc_classname = caller.classname

if activator.is_player():
event.attacker = userid_from_index(activator.index)
event.attacker = 0

event.weapon = ''
event.weapon_classname = ''

if info is not None:
weapon = Entity(info.weapon)
except (ValueError, OverflowError):
weapon = Entity(info.inflictor)
except (ValueError, OverflowError):
weapon = None

if weapon is not None:
if weapon.classname.startswith('weapon_'):
event.weapon = weapon.classname[7:]
event.weapon = WEAPON_ENTITY_TO_EVENT_WEAPON.get(weapon.classname, '')

event.weapon_classname = weapon.classname

class NPC_Death(CustomEvent):
npc_index = ShortVariable("index of the NPC")
attacker = ShortVariable("userid of the player who killed the NPC")
npc_classname = StringVariable("classname of the NPC")
weapon = StringVariable("weapon used to kill the NPC (as in player_death)")
weapon_classname = StringVariable("classname of the weapon used to kill the NPC")

res_file = ResourceFile('hl2mp_event_npc_death', NPC_Death)

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 2 guests