[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:

Re: [CSGO] Howto respawn a player?

Postby kalle » Thu Jul 07, 2016 11:27 am

Okay thank you all. Very active community. It's working quite well now :) no problems so far.
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 » Thu Jul 07, 2016 12:51 pm

iPlayer wrote:

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.

Just wanted to mention that you shouldn't pass the Player instance to the Delay class. If the player left the server during the delay, you are probably going to crash. An alternative would be to cancel the delay when the player left the server.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 72 guests