Help on getting spawn point

All other Source.Python topics and issues.
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Help on getting spawn point

Postby existenz » Tue May 16, 2017 7:15 pm

Hey !

I want to know if it's possible to generate and get all info_deathmatch_spawn coordinate in vector ?

Sincerly Existenz.
User avatar
satoon101
Project Leader
Posts: 2452
Joined: Sat Jul 07, 2012 1:59 am

Re: Help on getting spawn point

Postby satoon101 » Tue May 16, 2017 8:41 pm

Untested, but I believe this is correct:

Syntax: Select all

from engines.server import global_vars
from filters.entities import EntityIter
from listeners import OnLevelInit
from mathlib import Vector


# This will be called on both OnLevelInit and "sp plugin load <this_plugin>"
@OnLevelInit
def load(map_name=None):
# This happens when the plugin is loaded via autoexec.cfg or server.cfg
if global_vars.map_name is None:
return

all_spawn_coords = [
Vector(*entity.origin) for entity in EntityIter('info_deathmatch_spawn')
]
Image
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Help on getting spawn point

Postby existenz » Tue May 16, 2017 9:02 pm

Cool :D.
Thanks
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Help on getting spawn point

Postby existenz » Wed May 17, 2017 5:36 pm

I have try it's always empty even if i had mp_randomspawn 1 (https://developer.valvesoftware.com/wik ... atch_spawn).
I have try on de_dust2.
User avatar
satoon101
Project Leader
Posts: 2452
Joined: Sat Jul 07, 2012 1:59 am

Re: Help on getting spawn point

Postby satoon101 » Wed May 17, 2017 5:50 pm

One of two things is likely the issue.

  1. You have to wait 1 tick till those are on the server after map start
  2. That is not the correct entity name, and instead you have to use info_player_terrorist and info_player_counterterrorist
Image
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Help on getting spawn point

Postby existenz » Wed May 17, 2017 6:37 pm

I use it at round_start so no tick problem.
And info_player_terrorist and info_player_counterterrorist are for default t or ct spawn no ?
User avatar
satoon101
Project Leader
Posts: 2452
Joined: Sat Jul 07, 2012 1:59 am

Re: Help on getting spawn point

Postby satoon101 » Wed May 17, 2017 6:55 pm

Correct. Those are the entity names used in GunGame's Random Spawn sub-plugin.
Image
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Help on getting spawn point

Postby existenz » Wed May 17, 2017 7:02 pm

But i don't want to use ct and t default spawn, i need a real random spawn normaly generate by info_deathmatch_spawn :s
User avatar
satoon101
Project Leader
Posts: 2452
Joined: Sat Jul 07, 2012 1:59 am

Re: Help on getting spawn point

Postby satoon101 » Wed May 17, 2017 11:20 pm

Well, what do you get when you use the following:

Syntax: Select all

print(len(EntityIter('info_deathmatch_spawn')))


Also, if there is at least 1 of those, would you let me know the output of this, as well:

Syntax: Select all

print([server_class.__name__ for server_class in Entity.find('info_deathmatch_spawn').server_classes])
Image
User avatar
satoon101
Project Leader
Posts: 2452
Joined: Sat Jul 07, 2012 1:59 am

Re: Help on getting spawn point

Postby satoon101 » Thu May 18, 2017 2:59 am

Ooooooh, I just remembered that those 2 entities aren't networked on CS:GO. I bet info_deathmatch_spawn isn't, either. That means you have to use BaseEntityIter. BaseEntity objects don't have the added capabilities that Entity objects do, so you will have to use BaseEntity.get_key_value_vector directly.
Image
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Help on getting spawn point

Postby existenz » Thu May 18, 2017 8:23 am

Okay :) Thanks i will try at the end of the day.

And what does that mean networked entity ?
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Help on getting spawn point

Postby existenz » Thu May 18, 2017 5:06 pm

Hey !
I try that and it doesn't work :S

Syntax: Select all

SayText2(str(BaseEntityIter('info_deathmatch_spawn'))).send() 
# <filters.entities.BaseEntityIter object at 0xea94d14c>

SayText2(str(len(BaseEntityIter('info_deathmatch_spawn')))).send()
# 0

SayText2(str([server_class.__name__ for server_class in BaseEntity.find('info_deathmatch_spawn').server_classes])).send()
# AttributeError: 'NoneType' object has no attribute 'server_classes'
User avatar
satoon101
Project Leader
Posts: 2452
Joined: Sat Jul 07, 2012 1:59 am

Re: Help on getting spawn point

Postby satoon101 » Thu May 18, 2017 5:59 pm

That means it didn't find any of those entities on the server. To help figure it out, maybe use the following to find all entity types on the server:

Syntax: Select all

for classname in sorted({base_entity.classname for base_entity in BaseEntityIter()}):
print(classname)
Image
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Help on getting spawn point

Postby existenz » Thu May 18, 2017 7:30 pm

Ok i don't find it yes.
But if i add mp_randomspawn 1 it appear so how i can get the vector ?

Syntax: Select all

SayText2(str(len(BaseEntityIter('info_deathmatch_spawn')))).send()
# 21
for entity in BaseEntityIter('info_deathmatch_spawn'):
SayText2(str(entity.get_key_value_vector('angles'))).send() # Always 0,0,0
User avatar
satoon101
Project Leader
Posts: 2452
Joined: Sat Jul 07, 2012 1:59 am

Re: Help on getting spawn point

Postby satoon101 » Thu May 18, 2017 7:53 pm

Use 'origin' not 'angles'.
Image
existenz
Senior Member
Posts: 111
Joined: Thu Feb 09, 2017 3:33 pm
Location: France
Contact:

Re: Help on getting spawn point

Postby existenz » Thu May 18, 2017 8:11 pm

Ah i understand, It's the same like player.origin or entity.origin. I was looking on https://developer.valvesoftware.com/wik ... atch_spawn and i have just see angles so i don't know that have an origin :)
It works fine !
Thanks :)
User avatar
satoon101
Project Leader
Posts: 2452
Joined: Sat Jul 07, 2012 1:59 am

Re: Help on getting spawn point

Postby satoon101 » Thu May 18, 2017 8:21 pm

Yeah, player.origin and entity.origin automatically call get_key_value_vector internally.
Image
EdgardB
Junior Member
Posts: 1
Joined: Tue Jul 11, 2017 11:11 am

Re: Help on getting spawn point

Postby EdgardB » Tue Jul 18, 2017 8:01 am

satoon101 wrote:Use 'origin' not 'angles'.


Yes!! Thanks Satoon, that works.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest