Respawn player (csgo)

Please post any questions about developing your plugin here. Please use the search function before posting!
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:11 pm

Apparently, it's weirder than I thought. When I type kill in my client console, I actually get respawned, but I'm not visible to other players and my name is greyed out in the scoreboard.

EDIT: <PlayerEntity>.dead_flag returns 0..
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Sep 10, 2015 8:47 pm

Ayuto wrote:If yes, <godmode> is no longer available and should raise an error.

This is not true when setting an attribute, because we allow inheriting classes to set unknown attributes. Retrieving one, if it has not already been defined, on the other hand, will raise an error.

Using PlayerEntity.respawn() should work fine, unless you are using a class that inherits from PlayerEntity that defines its own respawn method. PlayerEntity's utilizes the CCSPlayer::RoundRespawn dynamic function, which does not require you to set any network properties:
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/data/source-python/entities/orangebox/cstrike/CCSPlayer.ini#L27
Image
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Thu Sep 10, 2015 9:41 pm

Actually, now that I think about it, I am not 100% sure you can respawn directly after dying. Try using a 1 tick delay:

Syntax: Select all

from entities.constants import INVALID_ENTITY_INDEX
from events import Event
from listeners.tick import tick_delays
from players.entity import PlayerEntity
from players.helpers import index_from_userid


@Event('player_death')
def respawn_on_death(game_event):
tick_delays.delay(0, respawn_player, game_event.get_int('userid'))


def respawn_player(userid):
index = index_from_userid(userid, False)
if index != INVALID_ENTITY_INDEX:
PlayerEntity(index).respawn()
Image
User avatar
BackRaw
Senior Member
Posts: 537
Joined: Sun Jul 15, 2012 1:46 am
Location: Germany
Contact:

Postby BackRaw » Fri Sep 11, 2015 4:25 pm

satoon101 wrote:Actually, now that I think about it, I am not 100% sure you can respawn directly after dying. Try using a 1 tick delay:

Syntax: Select all

from entities.constants import INVALID_ENTITY_INDEX
from events import Event
from listeners.tick import tick_delays
from players.entity import PlayerEntity
from players.helpers import index_from_userid


@Event('player_death')
def respawn_on_death(game_event):
tick_delays.delay(0, respawn_player, game_event.get_int('userid'))


def respawn_player(userid):
index = index_from_userid(userid, False)
if index != INVALID_ENTITY_INDEX:
PlayerEntity(index).respawn()


You're right, it needed a delay. Everything's fine now. Thanks y'all :)
My Github repositories:

Source.Python: https://github.com/backraw
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Mon Jan 04, 2016 4:21 pm

Hey guys, since I can't seem to find a respawn function anywhere, how would you go about respawning a player now?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jan 04, 2016 4:40 pm

That depends on the game, I guess. Apparently, we only have respawn added to the data for CS:S, currently. I will get that added to CS:GO here shortly.
Image
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Mon Jan 04, 2016 4:41 pm

Ah okay. The game would be hl2dm. So is there currently no way to respawn someone outside of CSS?
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jan 04, 2016 4:53 pm

Wait, I'm a bit confused as to why you need a respawn function in a game that automatically always respawns players. Whatever your reasons are, maybe try the following:

Syntax: Select all

from entities.helpers import spawn_entity

def respawn_player(index):
spawn_entity(index)


If I remember right, that same functionality used to work for TF2 and DOD:S. Though, I don't know if I ever saw it confirmed to work with HL2:DM. With CS:S, it was a little more complicated than that without using a signature:
http://forums.sourcepython.com/showthread.php?121&p=799&viewfull=1#post799 - that code no longer works, but it's the jist of what you have to do extra in CS:S compared to other games.
Image
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Postby Kami » Mon Jan 04, 2016 5:00 pm

Awesome, this worked! I am trying to create a killcam (which due to a bug hl2dm seems to have with observer mode works quite well). But changing the observer mode seems to remove the players ability to press buttons and respawning in hl2dm requires you to press attack. Thank you very much!
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Mon Jan 04, 2016 5:12 pm

I should also note that if you already have a Player instance, you can just use the spawn method, which is a wrapper that uses the exact same code.
https://github.com/Source-Python-Dev-Team/Source.Python/blob/master/addons/source-python/packages/source-python/entities/entity.py#L201
Image
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Mon Jan 04, 2016 6:11 pm

satoon101 wrote:With CS:S, it was a little more complicated than that without using a signature:
http://forums.sourcepython.com/showthread.php?121&p=799&viewfull=1#post799 - that code no longer works, but it's the jist of what you have to do extra in CS:S compared to other games.
I actually think that we shouldn't use the signature method if we can achieve the same thing without memory hacking.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 151 guests