Page 1 of 2

[CSGO] Howto respawn a player?

Posted: Sun Jun 26, 2016 9:54 am
by kalle
Dear Community,

I searched several hours the forum and your wiki about how to simply respawn a player. I just followed all older topics (from 2012 to 2015) and tried to get it working with the latest prebuilt binary files (downloaded today). All I got so far is a simply none working respawn (or a server crash at all).

This is the last code I tried (copied from other threads around here):

Code: Select all

   def respawnPlayer(self, player):
      playerEnt = Player(player)
      playerEnt.set_property_int('m_iPlayerState', 0)
      playerEnt.set_property_int('m_lifeState', 512)
      playerEnt.respawn()


Would be great if someone could help me :)

At least I got another question directly related to this one: If only two players on the server and one dies the round will end. But I wanted an "endless" round only end after round time limit. Is there a way to get that stuff working (without having to spawn 2 bots and keep them hidden under the map or somewhere else)?

Thanks!

Re: [CSGO] Howto respawn a player?

Posted: Sun Jun 26, 2016 10:24 am
by decompile
For your second question, there is a cvar who prevents that. I think it was 'mp_ignore_round_win_conditions', atleast in CS:S.

Re: [CSGO] Howto respawn a player?

Posted: Sun Jun 26, 2016 10:25 am
by kalle
Thanks. Is also available in CS:GO :)

Re: [CSGO] Howto respawn a player?

Posted: Sun Jun 26, 2016 10:51 am
by Ayuto
In order to respawn a player you just need to get an instance of the Player class and call its respawn() method.

Example:

Syntax: Select all

# Respawns a player everytime he says something in chat

from players.entity import Player
from events import Event

@Event('player_say')
def player_say(event):
player = Player.from_userid(event['userid'])
player.respawn()

Re: [CSGO] Howto respawn a player?

Posted: Sun Jun 26, 2016 2:55 pm
by L'In20Cible
He mentionned a server crash, maybe we need to update the signature of CCSPlayer::RoundRespawn. Though, we could see if we can replace it with Player.spawn() - less signatures to maintain, the better.

Re: [CSGO] Howto respawn a player?

Posted: Sun Jun 26, 2016 3:04 pm
by kalle
Server crash came suddenly. I'm sorry that I've no source code. But it was some code around this forum. Respawn is working. Sorry that I didn't figured it out myself. The documentation is not good readable for me.

I can't move afterwards. I tried to use player.set_property_uchar('m_iPlayerState', 0) but hadn't any luck.

Re: [CSGO] Howto respawn a player?

Posted: Sun Jun 26, 2016 3:06 pm
by satoon101
I think we discussed implementing a Player.spawn override for CS:S and CS:GO previously. That makes the most sense to me. The regular Entity.spawn should work for most other games to spawn players. That was one change I was planning to implement/test on the player_weapons_update2 branch when I go back into it in a week or so.

Re: [CSGO] Howto respawn a player?

Posted: Sun Jun 26, 2016 3:08 pm
by iPlayer
Try this maybe

Syntax: Select all

from players.constants import LifeState

...

player.player_state = 0
player.life_state = LifeState.ALIVE
player.spawn()

Re: [CSGO] Howto respawn a player?

Posted: Sun Jun 26, 2016 6:15 pm
by kalle
Thanks but nothing happens in CS:GO :/

the other code from Ayuto does respawn me but I'm not able to move (even if I set stuck/frozen to false). And even after my respawn I'm showed as "dead". So Life State doesn't change anything.

Re: [CSGO] Howto respawn a player?

Posted: Sun Jun 26, 2016 6:49 pm
by L'In20Cible
What OS? And do you run any other plugins?

Re: [CSGO] Howto respawn a player?

Posted: Mon Jun 27, 2016 4:35 am
by kalle
Windows 10 Pro 64Bit with latest source.python and no other running plugins. Fresh installation of CS:GO Server via SteamCMD. If the plugin will work I will run it for production on Ubuntu 16.04 64Bit.

Re: [CSGO] Howto respawn a player?

Posted: Mon Jun 27, 2016 10:47 am
by L'In20Cible
I'm not able to reproduce your issue. Always able to move once respawned using Player.respawn().

Re: [CSGO] Howto respawn a player?

Posted: Mon Jun 27, 2016 11:35 am
by kalle
Okay,

then I'll start from scratch again and also try a fresh Ubuntu 16.04 VM installation, too. I will reply if I got something new.

Thank you all very much!

Re: [CSGO] Howto respawn a player?

Posted: Mon Jun 27, 2016 6:53 pm
by La Muerte
kalle wrote:Okay,

then I'll start from scratch again and also try a fresh Ubuntu 16.04 VM installation, too. I will reply if I got something new.

Thank you all very much!


Does Ubuntu 16.04 come with glibc v2.23?

Source.Python requires at least glibc v2.7 in order to run properly on linux (I run my servers on Centos 7).

Re: [CSGO] Howto respawn a player?

Posted: Mon Jun 27, 2016 8:10 pm
by Ayuto
La Muerte wrote:Does Ubuntu 16.04 come with glibc v2.23?

I'm pretty sure it comes with a sufficient version. My Ubuntu VM (14.04) runs 2.19.

Edit: The required version is 2.17. You forgot the "1". :tongue:

Re: [CSGO] Howto respawn a player?

Posted: Wed Jul 06, 2016 2:58 pm
by kalle
Hey gus,

okay it's now working fine with the chat command example from Ayuto. But thats not what I primary want to do... I wan't the player to respawn at any time the script want's.

Code: Select all

@Event('player_death')
def player_death(event):
   player = Player.from_userid(event['userid'])
   player.respawn()


The above code works but I'm not able to move at all... and I don't want an instant respawn. So I tried the code down here. It's just a simple Thread that's waiting for a few seconds. The server itself will crash after waiting with "time.sleep". I have no clue why that happens. I saw an automatic respawn script for an older version thats not working any more and I thought I could at least revive it. But nevermind I didn't get it to work.

Code: Select all

def thread_respawnplayer(userID):
   SayText2('Prepare for respawn!').send([index_from_userid(userID)])
   time.sleep(6)
   player = Player.from_userid(userID)
   player.respawn()

@Event('player_death')
def player_death(event):
   t = Thread(target=thread_respawnplayer, args=(event['userid'],))
   t.start()


The parameters are correct because I see the message "Prepare for respawn!". And I can count to six after that and then immediately the server crashes.

Another Idea how to implement some kind of delayed respawn? I know Python a little bit because of other projects but I never had these kind of problems at all..

Thanks for any help.

Re: [CSGO] Howto respawn a player?

Posted: Wed Jul 06, 2016 4:02 pm
by iPlayer

Syntax: Select all

from listeners.tick import Delay
from messages import SayText2
from players.entity import Player


# Create message only once, use it multiple times
respawn_message = SayText2('Prepare for respawn!')


def respawn(player):
# Player might have been respawned already by some reason
if not player.dead:
return

# Also, specs (or unassigneds, I don't remember) are never dead
if player.team not in (2, 3):
return

player.respawn()


@Event('player_death')
def on_player_death(game_event):
player = Player.from_userid(game_event['userid'])
Delay(6, respawn, player) # Use Delay class to delay something
respawn_message.send(player.index)



Again, use Delay class if you want to delay something.

Even if you need threading for reason, use GameThread from listeners.tick module. It's a subclass of threading.Thread, so it accepts the same arguments and works the same way.

Re: [CSGO] Howto respawn a player?

Posted: Wed Jul 06, 2016 4:46 pm
by satoon101
We should probably add your dead and team checks to the respawn method itself.

Re: [CSGO] Howto respawn a player?

Posted: Wed Jul 06, 2016 8:39 pm
by L'In20Cible
satoon101 wrote:We should probably add your dead and team checks to the respawn method itself.

I don't think we should take care of those checks to be honnest. Respawning should works on all players (teleported back to spawn, ammo reset, etc.) whether they are already spawned or not.

Re: [CSGO] Howto respawn a player?

Posted: Thu Jul 07, 2016 5:37 am
by iPlayer
Should've probably removed the team check, got a bit confused. As I said, specs/unassigned are never dead, so the first if not player.dead check will filter them out.

Though, I'm not sure if both specs and unassigned return False from player.dead.