[CSGO] Howto respawn a player?

Please post any questions about developing your plugin here. Please use the search function before posting!
kalle
Junior Member
Posts: 26
Joined: Sun Jun 26, 2016 9:48 am
Contact:

[CSGO] Howto respawn a player?

Postby kalle » Sun Jun 26, 2016 9:54 am

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!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: [CSGO] Howto respawn a player?

Postby decompile » Sun Jun 26, 2016 10:24 am

For your second question, there is a cvar who prevents that. I think it was 'mp_ignore_round_win_conditions', atleast in CS:S.
kalle
Junior Member
Posts: 26
Joined: Sun Jun 26, 2016 9:48 am
Contact:

Re: [CSGO] Howto respawn a player?

Postby kalle » Sun Jun 26, 2016 10:25 am

Thanks. Is also available in CS:GO :)
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CSGO] Howto respawn a player?

Postby Ayuto » Sun Jun 26, 2016 10:51 am

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()
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CSGO] Howto respawn a player?

Postby L'In20Cible » Sun Jun 26, 2016 2:55 pm

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.
kalle
Junior Member
Posts: 26
Joined: Sun Jun 26, 2016 9:48 am
Contact:

Re: [CSGO] Howto respawn a player?

Postby kalle » Sun Jun 26, 2016 3:04 pm

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

Re: [CSGO] Howto respawn a player?

Postby satoon101 » Sun Jun 26, 2016 3:06 pm

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.
Image
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: [CSGO] Howto respawn a player?

Postby iPlayer » Sun Jun 26, 2016 3:08 pm

Try this maybe

Syntax: Select all

from players.constants import LifeState

...

player.player_state = 0
player.life_state = LifeState.ALIVE
player.spawn()
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
kalle
Junior Member
Posts: 26
Joined: Sun Jun 26, 2016 9:48 am
Contact:

Re: [CSGO] Howto respawn a player?

Postby kalle » Sun Jun 26, 2016 6:15 pm

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.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CSGO] Howto respawn a player?

Postby L'In20Cible » Sun Jun 26, 2016 6:49 pm

What OS? And do you run any other plugins?
kalle
Junior Member
Posts: 26
Joined: Sun Jun 26, 2016 9:48 am
Contact:

Re: [CSGO] Howto respawn a player?

Postby kalle » Mon Jun 27, 2016 4:35 am

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.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CSGO] Howto respawn a player?

Postby L'In20Cible » Mon Jun 27, 2016 10:47 am

I'm not able to reproduce your issue. Always able to move once respawned using Player.respawn().
kalle
Junior Member
Posts: 26
Joined: Sun Jun 26, 2016 9:48 am
Contact:

Re: [CSGO] Howto respawn a player?

Postby kalle » Mon Jun 27, 2016 11:35 am

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!
User avatar
La Muerte
Administrator
Posts: 180
Joined: Sun Jul 15, 2012 1:48 pm
Location: Belgium
Contact:

Re: [CSGO] Howto respawn a player?

Postby La Muerte » Mon Jun 27, 2016 6:53 pm

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).
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [CSGO] Howto respawn a player?

Postby Ayuto » Mon Jun 27, 2016 8:10 pm

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:
kalle
Junior Member
Posts: 26
Joined: Sun Jun 26, 2016 9:48 am
Contact:

Re: [CSGO] Howto respawn a player?

Postby kalle » Wed Jul 06, 2016 2:58 pm

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.
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: [CSGO] Howto respawn a player?

Postby iPlayer » Wed Jul 06, 2016 4:02 pm

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: [CSGO] Howto respawn a player?

Postby satoon101 » Wed Jul 06, 2016 4:46 pm

We should probably add your dead and team checks to the respawn method itself.
Image
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CSGO] Howto respawn a player?

Postby L'In20Cible » Wed Jul 06, 2016 8:39 pm

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.
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: [CSGO] Howto respawn a player?

Postby iPlayer » Thu Jul 07, 2016 5:37 am

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.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 130 guests