Crash when spawning entities from OnLevelInit

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Hymns For Disco
Junior Member
Posts: 15
Joined: Wed Nov 22, 2017 7:18 am

Crash when spawning entities from OnLevelInit

Postby Hymns For Disco » Sun Dec 17, 2017 12:34 am

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?
User avatar
L'In20Cible
Project Leader
Posts: 1095
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Crash when spawning entities from OnLevelInit

Postby L'In20Cible » Sun Dec 17, 2017 1:27 am

OnLevelInit probably fires too early, try OnServerActivate instead.
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Crash when spawning entities from OnLevelInit

Postby iPlayer » Sun Dec 17, 2017 2:45 am

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 10 guests