Auto spawn

Please post any questions about developing your plugin here. Please use the search function before posting!
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Auto spawn

Postby nullable » Sun Mar 29, 2015 1:40 pm

Hi,

Please help me. My code doesn't set a team.

Syntax: Select all

from players.helpers import index_from_userid
from players.entity import PlayerEntity
from entities.helpers import spawn_entity
from events import Event

@Event
def player_activate(game_event):
userid = game_event.get_int('userid')
index = index_from_userid(userid)
player = PlayerEntity(index)
player.team = 3
spawn_entity(player.index)
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sun Mar 29, 2015 2:51 pm

The real problem here is that you are only defining the m_nTeamNum property of the player. You need to tell the specific team manager by adding the player to it. I think I would try a different approach to achieve what you are trying to do:

Syntax: Select all

from commands import CommandReturn
from commands.client import ClientCommand
from engines.server import engine_server
from entities.helpers import spawn_entity
from players.constants import LifeState
from players.entity import PlayerEntity
from players.helpers import edict_from_playerinfo
from players.helpers import index_from_playerinfo

@ClientCommand('joingame')
def joingame_callback(player_info, command):
"""The 'joingame' command is executed by the clients when they click on
the [OK] button of the MOTD."""

# Simulate the player choosing a team...
engine_server.client_command(
edict_from_playerinfo(player_info), 'jointeam 3')

# We don't want the server to send the team menu so stop the process...
return CommandReturn.BLOCK


@ClientCommand('joinclass')
def joinclass_callback(player_info, command):
"""The player is selecting a class from the class menu."""

# Get the PlayerEntity instance from the PlayerInfo...
player = PlayerEntity(index_from_playerinfo(player_info))

# Make sure the player is in the connection process...
if not player.player_state:
return CommandReturn.CONTINUE

# Mark the player as respawnable...
player.player_state = 0
player.life_state = LifeState.RESPAWNABLE

# Spawn the player...
spawn_entity(player.index)

# Make sure the player won't spawn twice in case he join the server few
# seconds after the round starts...
return CommandReturn.BLOCK
User avatar
satoon101
Project Leader
Posts: 2725
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Mar 29, 2015 4:55 pm

L'In20Cible wrote:The real problem here is that you are only defining the m_nTeamNum property of the player.
That is not accurate. PlayerEntity has a defined property for team to get and set a player's team.
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/players/entity.py#L120
Image
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Sun Mar 29, 2015 5:21 pm

satoon101 wrote:
L'In20Cible wrote:The real problem here is that you are only defining the m_nTeamNum property of the player.
That is not accurate. PlayerEntity has a defined property for team to get and set a player's team.
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/players/entity.py#L120


Yes, but my code stopped working properly after the upgrade source-python (8 march 2015 release).
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Mar 30, 2015 1:43 am

satoon101 wrote:That is not accurate. PlayerEntity has a defined property for team to get and set a player's team.
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/players/entity.py#L120
It is, since "team" is also declared as a keyvalue which point to CBaseEntity::ChangeTeam. Changing the team of a player requires more work than an entity and that keyvalue is found first in the resolution order.
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Mon Mar 30, 2015 4:23 am

I tried change my code next:

Syntax: Select all

from players.helpers import index_from_userid
from players.entity import PlayerEntity
from players.constants import LifeState
from entities.helpers import spawn_entity
from events import Event

@Event
def player_activate(game_event):
userid = game_event.get_int('userid')
index = index_from_userid(userid)
player = PlayerEntity(index)
# Mark the player as respawnable...
player.player_state = 0
player.life_state = LifeState.RESPAWNABLE
player.team = 3
spawn_entity(player.index)


But it didn't help me. Please tell me is what wrong?

P.S. The game is CSGO
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Mon Mar 30, 2015 8:28 pm

Is any ideas how can I change team without callbacks?
User avatar
L'In20Cible
Project Leader
Posts: 1536
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Tue Mar 31, 2015 2:28 am

Syntax: Select all

player.playerinfo.change_team(3)
I still think the proper approach, for the clients, is to wait they accept the MOTD first.
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Wed Apr 01, 2015 5:49 am

Thanks. The problem has been resolved.
User avatar
satoon101
Project Leader
Posts: 2725
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Wed Apr 01, 2015 1:52 pm

Image
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Mon Jun 29, 2015 6:53 pm

The problem is that all the players die if I run this code in round_end event:
[PYTHON]def switch_teams():
for player in PlayerIter(return_types='player'):
if player.name in TV_BOTS:
continue
team_id = Team.CT.value if player.team == Team.TF.value else Team.TF.value
player.playerinfo.change_team(team_id)[/PYTHON]

Is there a way to solve the problem is not killing all the players? I would like to make a similar change in the period when mp_halftme 1.
User avatar
satoon101
Project Leader
Posts: 2725
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jun 29, 2015 7:03 pm

Use switch_team instead.

[python] player.switch_team(team_id)[/python]
This method is added dynamically through the data system:

CS:GO's CCSPlayer::SwitchTeam
CS:S' CCSPlayer::SwitchTeam


Also, there is no need to use player.playerinfo directly. We handle that automatically in __getattr__:

https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/entities/entity.py#L74

The above line loops through the base instances for the entity/player and gets whether the instance has the given attribute. For PlayerEntity, the playerinfo is the first instance that is checked against:

https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/players/entity.py#L66
Image
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Mon Jun 29, 2015 7:16 pm

I have an error when I use player.switch_team

Syntax: Select all

[SP] Caught an Exception:    
Traceback (most recent call last):
File '../addons/source-python/packages/source-python/events/listener.py', line 93, in fire_game_event
callback(game_event)
File '../addons/source-python/plugins/test/test.py', line 262, in round_end
switch_teams()
File '../addons/source-python/plugins/test/test.py', line 145, in switch_teams
player.switch_team(team_id)
File '../addons/source-python/packages/source-python/entities/entity.py', line 87, in __getattr__
if hasattr(server_class, attr):
File '../addons/source-python/packages/source-python/memory/manager.py', line 610, in __get__
binary = find_binary(cls._binary, cls._srv_check)

OSError: Unable to find ../bin/server_srv.so
User avatar
satoon101
Project Leader
Posts: 2725
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Jun 30, 2015 4:07 am

I just had time to work on that error, and it is now fixed:
https://github.com/Source-Python-Dev-Team/Source.Python/commit/4e716a963aac732db3628d1bd05097dc61f0c425

We will get a new release posted hopefully sometime this week.
Image
nullable
Senior Member
Posts: 137
Joined: Sat Nov 08, 2014 7:22 pm

Postby nullable » Tue Jun 30, 2015 4:50 am

OFFTOP: Will it be possible to change the nickname like player.name to the new release?
User avatar
satoon101
Project Leader
Posts: 2725
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Jun 30, 2015 4:55 am

I personally don't think that would be a good idea to add directly into the API for multiple reasons. It's fine to use in your own plugin(s), though.
Image
necavi
Developer
Posts: 129
Joined: Wed Jan 30, 2013 9:51 pm

Postby necavi » Tue Jun 30, 2015 6:39 am

I'd be curious as to what those reasons are, especially when there's completely different ways of changing the name in CS:S and CS:GO, seems better to support that all at one point rather than making everyone have their own method of doing it. (Unless there's already a method on the player to do it that I'm forgetting and you're just referring to setting the variable)
User avatar
Ayuto
Project Leader
Posts: 2210
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Tue Jun 30, 2015 11:01 am

Yeah, I also think that we should include that. That would prevent people from copying and pasting the script I have made into every plugin.
User avatar
satoon101
Project Leader
Posts: 2725
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Jun 30, 2015 1:16 pm

I don't really like the idea of changing a players name without their permission, and I am sure I am not alone in that. This functionality will require multiple symbols/signatures that need to be maintained. Not to mention, if a player did not like the fact that a server changed their name, they would either blacklist the server or have a key bound to reset their name. I know that the resetting can be prevented, and I wonder if either of you would advocate implementing that into the API. That would seem to be a huge overstepping to me.

Having said all of that, I think this would be a perfect candidate for a custom package. That way, any plugin that wishes to be able to change a players name can just require the custom package and utilize its functionality. I know that people would want to use this functionality. I just don't think it belongs in the API itself.
Image
User avatar
Ayuto
Project Leader
Posts: 2210
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Tue Jun 30, 2015 5:22 pm

One could argue that people also don't want that servers change their clan tags, health or speed. But that's one of the basic features of SP.

Actually, we just need the signature/symbol of the SetName method and the sv pointer. The offset for ClientCommand will be available through the new memory branch and GetClient can be exposed.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 44 guests