Page 1 of 1

Crash when spawning entities from OnLevelInit

Posted: Sun Dec 17, 2017 12:34 am
by Hymns For Disco
It seems that trying to spawn entities from the OnLevelInit listener will crash the server.

Syntax: Select all

from commands.typed import TypedSayCommand
from entities._base import Entity
from players._base import Player
from listeners import OnLevelInit

from mathlib import Vector

@TypedSayCommand('add')
def on_add(command_info, classname:str):
ent = Entity.create(classname)
player = Player(command_info.index)

ent.origin = player.view_coordinates + Vector(0, 0, 32)
ent.spawn()

@OnLevelInit
def on_level(map_name):
ent = Entity.create('item_defuser')
ent.origin = Vector(500, 0, 100)
ent.spawn()


I need my plugin to be able to spawn several entities on map start before players are able to play. Is there another listener I can use that is called after the level is properly loaded and ready for entities?

Re: Crash when spawning entities from OnLevelInit

Posted: Sun Dec 17, 2017 1:27 am
by L'In20Cible
OnLevelInit probably fires too early, try OnServerActivate instead.

Re: Crash when spawning entities from OnLevelInit

Posted: Sun Dec 17, 2017 2:45 am
by iPlayer
Hold on a minute, why do you spawn those entities on level init? They'll get wiped out in the next round, unless they're entities like func_brush that don't get reset each round. Why don't you spawn them upon round_start event? Seems more correct way to do that, and it always worked perfectly.