Page 1 of 2

Respawn player (csgo)

Posted: Thu Sep 04, 2014 7:35 pm
by stonedegg
So I'm trying to respawn the player and I finally found out how to do it (I guess).
In ..\csgo\addons\source-python\data\source-python\entities\functions\player\csgo.ini I found the respawn function.
In my script, I'm using it this way:

Syntax: Select all

from players.entity import PlayerEntity

# ...

player = PlayerEntity(index)
player.set_prop_int('m_iPlayerState', 0)
player.set_prop_int('m_lifeState', 512)
player.respawn()


When the .respawn() function is being run I'm getting lots of errors and srcds.exe crashes.
I assume the signature is outdated, or is that a bigger problem?

Edit: Just found out that the same goes for .give_named_item()

Posted: Thu Sep 04, 2014 7:51 pm
by satoon101
CS:GO's give_named_item requires an argument of a type we currently don't have access to. Have you tried using dispatch_spawn instead of spawn?

Posted: Thu Sep 04, 2014 7:58 pm
by stonedegg
Okay, thanks.

Using .dispatch_spawn() gives the following error: AttributeError: Attribute 'dispatch_spawn' not found
I tried .DispatchSpawn() earlier as well (found in the addon Respawn Waves), giving the same error.

Posted: Thu Sep 04, 2014 9:40 pm
by satoon101
Sorry, on my phone so couldn't fully remember. dispatch_spawn is a part of server tools which you can import from the tools package. You pass the entity's (player's) index as the only argument.

Posted: Fri Sep 05, 2014 12:26 am
by stonedegg
What is the name of that package? I can't find anything under tools.

Posted: Fri Sep 05, 2014 12:46 am
by satoon101
We haven't figured out exactly where that is going to be housed in the future, but for now, you can just look here:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/src/core/modules/tools/tools_wrap_python.cpp

DispatchSpawn can be found here:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/src/core/modules/tools/tools_wrap_python.cpp#L78

So, to use it:

Syntax: Select all

from tools import server_tools
from players.entity import PlayerEntity

player = PlayerEntity(index)
player.set_prop_int('m_iPlayerState', 0)
player.set_prop_int('m_lifeState', 512)
server_tools.spawn_entity(index)


Also, instead of setting m_lifeState to 512, you can set godmode to False. It's a little easier to remember this way:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/data/source-python/entities/properties/player/csgo.ini#L77

Syntax: Select all

player.godmode = False

Posted: Fri Sep 05, 2014 12:31 pm
by stonedegg
Ah okay, thanks. I thought it would be a python libary, so I looked in the wrong place. Will try it out soon.

Posted: Sat Sep 06, 2014 12:07 pm
by stonedegg
That worked fine, except that it's ServerTools, not server_tools. Maybe you want to edit your post in case anyone tries the same.

Posted: Sat Sep 06, 2014 12:09 pm
by Ayuto

Posted: Sun Sep 07, 2014 1:04 pm
by stonedegg
Oh well, I haven't compiled it myself for csgo, I just used the precompiled download ;)

Posted: Mon Sep 08, 2014 6:15 am
by BackRaw
satoon101 wrote:So, to use it:

Syntax: Select all

from tools import server_tools
from players.entity import PlayerEntity

player = PlayerEntity(index)
player.set_prop_int('m_iPlayerState', 0)
player.set_prop_int('m_lifeState', 512)
server_tools.spawn_entity(index)


Also, instead of setting m_lifeState to 512, you can set godmode to False. It's a little easier to remember this way:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/data/source-python/entities/properties/player/csgo.ini#L77

Syntax: Select all

player.godmode = False

What about css? I guess there are no sinbatures yet are there?

Posted: Mon Sep 08, 2014 6:49 am
by satoon101
None of the code in the post you quoted requires signatures. It works fine for CS:S, as well.

Posted: Mon Sep 08, 2014 8:54 am
by BackRaw
satoon101 wrote:None of the code in the post you quoted requires signatures. It works fine for CS:S, as well.


That's good news. I tried the code you provided using tick_delays:

Syntax: Select all

from events import Event
from listeners.tick import tick_delays

from players.entities import PlayerEntity
from players.helpers import index_from_userid

from tools.server import server_tools

@Event
def player_say(game_event):
player = PlayerEntity(index_from_userid(game_event.get_int("userid"))

player.godmode = False
tick_delays.delay(2.0, server_tools.respawn, player.index)
There are no errors, but it doesn't spawn the player neither.

Posted: Mon Sep 08, 2014 9:11 am
by satoon101
Well, you aren't setting m_iPlayerState in that code. It would be better to set both of the properties right before using server_tools to respawn the player anyway.

Also, I'm not sure how you don't get an error. server_tools has no "respawn" attribute. Not only that, but there is no tools.server module, so your plugin shouldn't even be loading successfully. You should be importing server_tools directly from tools. That will probably change in the near future, but for now that is where it is imported from.

Syntax: Select all

from events import Event
from listeners.tick import tick_delays
from players.entity import PlayerEntity
from players.helpers import index_from_userid
from tools import server_tools


def respawn_player(player):
player.set_prop_int('m_iPlayerState', 0)
player.godmode = False
server_tools.spawn_entity(player.index)


@Event
def player_say(game_event):
if game_event.get_string('text') == 'respawn':
tick_delays.delay(2.0, respawn_player, PlayerEntity(index_from_userid(game_event.get_int('userid'))))

Posted: Mon Sep 08, 2014 9:14 am
by BackRaw
satoon101 wrote:Well, you aren't setting m_iPlayerState in that code. It would be better to set both of the properties right before using server_tools to respawn the player anyway.

Also, I'm not sure how you don't get an error. server_tools has no "respawn" attribute. Not only that, but there is no tools.server module, so your plugin shouldn't even be loading successfully. You should be importing server_tools directly from tools. That will probably change in the near future, but for now that is where it is imported from.

Syntax: Select all

from events import Event
from listeners.tick import tick_delays
from players.helpers import index_from_userid
from tools server_tools


def respawn_player(player):
player.set_prop_int('m_iPlayerState', 0)
player.godmode = False
server_tools.spawn_entity(player.index)


@Event
def player_say(game_event):
if game_event.get_string('text') == 'respawn':
tick_delays.delay(2.0, respawn_player, index_from_userid(game_event.get_int('userid')))


I wrote the code from my head, I wasn't quite sure lol. I looked at the script and it's server_tools.spawn_entity and from tools import server_tools, sorry for confusion and the mistakes... But I wasn't setting m_iPlayerState to 0, that's true - I thought player.godmode = False would care about that, too.
Clear now :)

Posted: Mon Sep 08, 2014 9:18 am
by satoon101
For the godmode, it uses the property m_lifeState:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/data/source-python/entities/properties/player/csgo.ini#L77

When setting a property that has True and False values in the data, we str() the boolean to get the value to set it to. Thus, player.godmode = False is just setting the player's m_lifeState prop to 512.

We are working on updating BaseEntity to a much better system than the current one, so the data files will be changing fairly soon. To see the progress of these updates, look at the entities_changes branch of the repository:
https://github.com/Source-Python-Dev-Team/Source.Python/tree/entities_changes

Posted: Mon Sep 08, 2014 1:00 pm
by BackRaw
satoon101 wrote:For the godmode, it uses the property m_lifeState:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/data/source-python/entities/properties/player/csgo.ini#L77

When setting a property that has True and False values in the data, we str() the boolean to get the value to set it to. Thus, player.godmode = False is just setting the player's m_lifeState prop to 512.

We are working on updating BaseEntity to a much better system than the current one, so the data files will be changing fairly soon. To see the progress of these updates, look at the entities_changes branch of the repository:
https://github.com/Source-Python-Dev-Team/Source.Python/tree/entities_changes


Thanks! I'll keep an eye on it.

Posted: Thu Sep 10, 2015 6:09 pm
by BackRaw
I know this thread is old, and my question is about css again, but still, it's about respawning :grin:

How come, on a Windows server, this code does nothing at all?

Syntax: Select all

# game_mode is a config.cvar object which holds a value of 1

def get_player(game_event, idtype):
userid = game_event.get_int(idtype)
index = index_from_userid(userid)

return PlayerEntity(index)

@Event('player_death')
def on_death(game_event):
if game_mode.get_int(): # it is, the code below definitely gets executed, since the console outputs 'RESPAWN'
print('RESPAWN')

victim = get_player(game_event, 'userid')

victim.player_state = 0
victim.godmode = False

victim.spawn()

Posted: Thu Sep 10, 2015 6:31 pm
by Ayuto
Is <victim> a PlayerEntity and are you using the latest version? If yes, <godmode> is no longer available and should raise an error. Try <PlayerEntity>.respawn() instead.

Posted: Thu Sep 10, 2015 7:06 pm
by BackRaw
Ayuto wrote:Is <victim> a PlayerEntity and are you using the latest version? If yes, <godmode> is no longer available and should raise an error. Try <PlayerEntity>.respawn() instead.


Yes, victim is a PlayerEntity instance as you can see in the code. I already tried .respawn() - I'll try again.

EDIT: Oh, I'm using the September 9 release. And I tried again, it does nothing..