[CSGO/HL2DM] OnEntityCreated called twice?

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

[CSGO/HL2DM] OnEntityCreated called twice?

Postby VinciT » Thu Apr 27, 2017 10:09 pm

Is there a reason OnEntityCreated is called twice?

Syntax: Select all

#on_entity_created_test.py
from listeners import OnEntityCreated


@OnEntityCreated
def on_entity_created(base_entity):
try:
index = base_entity.index
except:
return

if index is None:
return

print('entity with index {} created'.format(index))
Output:

Code: Select all

entity with index 76 created
entity with index 76 created
entity with index 77 created
entity with index 77 created
entity with index 78 created
entity with index 78 created
entity with index 79 created
entity with index 79 created
entity with index 80 created
entity with index 80 created
entity with index 81 created
entity with index 81 created
entity with index 82 created
entity with index 82 created
entity with index 83 created
entity with index 83 created
entity with index 88 created
entity with index 88 created
entity with index 89 created
entity with index 89 created
entity with index 139 created
entity with index 139 created
entity with index 140 created
entity with index 140 created
entity with index 142 created
entity with index 142 created
entity with index 143 created
entity with index 143 created
entity with index 144 created
entity with index 144 created
entity with index 145 created
entity with index 145 created
entity with index 147 created
entity with index 147 created
entity with index 148 created
entity with index 148 created
entity with index 149 created
entity with index 149 created
entity with index 150 created
entity with index 150 created
entity with index 151 created
entity with index 151 created
entity with index 152 created
entity with index 152 created
entity with index 153 created
entity with index 153 created
entity with index 154 created
entity with index 154 created
entity with index 155 created
entity with index 155 created
entity with index 156 created
entity with index 156 created
entity with index 157 created
entity with index 157 created
entity with index 158 created
entity with index 158 created
entity with index 159 created
entity with index 159 created
entity with index 160 created
entity with index 160 created
entity with index 161 created
entity with index 161 created
entity with index 162 created
entity with index 162 created
entity with index 163 created
entity with index 163 created
entity with index 164 created
entity with index 164 created
entity with index 165 created
entity with index 165 created
entity with index 166 created
entity with index 166 created
entity with index 167 created
entity with index 167 created
entity with index 168 created
entity with index 168 created
entity with index 169 created
entity with index 169 created
entity with index 170 created
entity with index 170 created
entity with index 171 created
entity with index 171 created
entity with index 172 created
entity with index 172 created
entity with index 173 created
entity with index 173 created
entity with index 174 created
entity with index 174 created
entity with index 175 created
entity with index 175 created
entity with index 176 created
entity with index 176 created
entity with index 177 created
entity with index 177 created
entity with index 178 created
entity with index 178 created
entity with index 179 created
entity with index 179 created
entity with index 88 created
entity with index 88 created
entity with index 90 created
entity with index 90 created


The way I've been getting around this is by making a list and adding the index to that list the first time OnEntityCreated is called, and removing the index once the entity has been deleted. I'm just wondering if this is intended behavior.

Syntax: Select all

#on_entity_created_test2.py
from listeners import OnEntityCreated, OnEntityDeleted


already_created = []

@OnEntityCreated
def on_entity_created(base_entity):
try:
index = base_entity.index
except:
return

if index is None:
return

if index not in already_created:
already_created.append(index)
print('entity with index {} created'.format(index))


@OnEntityDeleted
def on_entity_deleted(base_entity):
if base_entity.index in already_created:
already_created.remove(base_entity.index)
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CSGO/HL2DM] OnEntityCreated called twice?

Postby L'In20Cible » Thu Apr 27, 2017 10:20 pm

Could you post the result of sp info?
User avatar
VinciT
Senior Member
Posts: 331
Joined: Thu Dec 18, 2014 2:41 am

Re: [CSGO/HL2DM] OnEntityCreated called twice?

Postby VinciT » Thu Apr 27, 2017 10:38 pm

Here you go:

Code: Select all

Date          : 2017-04-27 22:37:45.550819
OS            : Windows-8.1-6.3.9600
Game          : csgo
SP version    : 573
Server plugins:
   00: Source.Python, (C) 2012-2016, Source.Python Team.
SP plugins:
   00: on_entity_created_test

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 33 guests