Respawn player (csgo)

Please post any questions about developing your plugin here. Please use the search function before posting!
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Respawn player (csgo)

Postby stonedegg » Thu Sep 04, 2014 7:35 pm

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()
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Sep 04, 2014 7:51 pm

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?
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Thu Sep 04, 2014 7:58 pm

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Sep 04, 2014 9:40 pm

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.
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Fri Sep 05, 2014 12:26 am

What is the name of that package? I can't find anything under tools.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Fri Sep 05, 2014 12:46 am

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
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Fri Sep 05, 2014 12:31 pm

Ah okay, thanks. I thought it would be a python libary, so I looked in the wrong place. Will try it out soon.
stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Sat Sep 06, 2014 12:07 pm

That worked fine, except that it's ServerTools, not server_tools. Maybe you want to edit your post in case anyone tries the same.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Sep 06, 2014 12:09 pm

stonedegg
Senior Member
Posts: 141
Joined: Sun Aug 12, 2012 11:45 am

Postby stonedegg » Sun Sep 07, 2014 1:04 pm

Oh well, I haven't compiled it myself for csgo, I just used the precompiled download ;)
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Mon Sep 08, 2014 6:15 am

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?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Sep 08, 2014 6:49 am

None of the code in the post you quoted requires signatures. It works fine for CS:S, as well.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Mon Sep 08, 2014 8:54 am

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.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Sep 08, 2014 9:11 am

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'))))
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Mon Sep 08, 2014 9:14 am

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 :)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Sep 08, 2014 9:18 am

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
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Mon Sep 08, 2014 1:00 pm

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.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Thu Sep 10, 2015 6:09 pm

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()
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Thu Sep 10, 2015 6:31 pm

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.
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Thu Sep 10, 2015 7:06 pm

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..
My Github repositories:

Source.Python: https://github.com/backraw

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 149 guests