Raised This Month: $12 Target: $400
 3% 

CS_RespawnPlayer CSGO become ghost.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shortguy
Member
Join Date: Jul 2009
Old 08-04-2015 , 05:52   CS_RespawnPlayer CSGO become ghost.
Reply With Quote #1

So I'm having an interesting timing issue with CS:GO and CS_RespawnPlayer.

I am hooking the "player_death" event in order to respawn players immediately after they die.
However, if I run the RespawnPlayer command from the death event hook, the player respawns but are in the floor and are sort of a ghost player (not alive, no weapons but can move around kind of).

However I can get around this by using CreateTimer and any amount of time works.

For instance I can use a 0.000001 timer and it will respawn immediately and works wonderfully.

Is there something I am doing wrong? I am already using PostHook.
shortguy is offline
jonitaikaponi
Senior Member
Join Date: Nov 2014
Location: Finland
Old 08-04-2015 , 06:25   Re: CS_RespawnPlayer CSGO become ghost.
Reply With Quote #2

Sounds like a problem with the players team. Try to check that they are set to a valid team.

But why don't you just use mp_respawn_on_death_ct 1;mp_respawn_on_death_t 1 ?

Last edited by jonitaikaponi; 08-04-2015 at 06:28.
jonitaikaponi is offline
shortguy
Member
Join Date: Jul 2009
Old 08-04-2015 , 07:23   Re: CS_RespawnPlayer CSGO become ghost.
Reply With Quote #3

I eventually wont be using it for an instant respawn system, just wanted to find out what the requirements were for a valid spawn.

I guess, Valid Team and Is Dead?
shortguy is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 08-04-2015 , 07:45   Re: CS_RespawnPlayer CSGO become ghost.
Reply With Quote #4

Show your code in pm or here.
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker is offline
shortguy
Member
Join Date: Jul 2009
Old 08-04-2015 , 08:07   Re: CS_RespawnPlayer CSGO become ghost.
Reply With Quote #5

Works Fine

Code:
public OnPluginStart() {
  HookEvent("player_death", Event_PlayerDeath);
}

public Action Timer_RespawnClient(Handle timer, int client) {
  CS_RespawnPlayer(client);
}

public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast) 
{
  int userID = GetEventInt(event, "userid");
  int client = GetClientOfUserId(userID);
  if (!IsPlayerAlive(client)) {
    CreateTimer(0.000001, Timer_RespawnClient, client);    
  }
  return Plugin_Continue;
}
Fails to spawn correctly:

Code:
public OnPluginStart() {
  HookEvent("player_death", Event_PlayerDeath);
}

public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast) 
{
  int userID = GetEventInt(event, "userid");
  int client = GetClientOfUserId(userID);
  if (!IsPlayerAlive(client)) {
    CS_RespawnPlayer(client);
  }
  return Plugin_Continue;
}
shortguy is offline
jonitaikaponi
Senior Member
Join Date: Nov 2014
Location: Finland
Old 08-04-2015 , 08:17   Re: CS_RespawnPlayer CSGO become ghost.
Reply With Quote #6

Quote:
Originally Posted by shortguy View Post
I eventually wont be using it for an instant respawn system, just wanted to find out what the requirements were for a valid spawn.

I guess, Valid Team and Is Dead?
Yeah. I've noticed that player's that get spawned without a valid team, spawn in the way you described. I guess what is happening here, is that the player gets spawned when he is on the spectator team or being changed to it.

Try to use ChangeClientTeam(client, team) before respawning the player.
1 = Spectate
2 = Terrorists
3 = Counter-Terrorists

Last edited by jonitaikaponi; 08-04-2015 at 08:20.
jonitaikaponi is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 08-04-2015 , 08:29   Re: CS_RespawnPlayer CSGO become ghost.
Reply With Quote #7

Quote:
Originally Posted by shortguy View Post
Works Fine

Code:
public OnPluginStart() {
  HookEvent("player_death", Event_PlayerDeath);
}

public Action Timer_RespawnClient(Handle timer, int client) {
  CS_RespawnPlayer(client);
}

public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast) 
{
  int userID = GetEventInt(event, "userid");
  int client = GetClientOfUserId(userID);
  if (!IsPlayerAlive(client)) {
    CreateTimer(0.000001, Timer_RespawnClient, client);    
  }
  return Plugin_Continue;
}
Fails to spawn correctly:

Code:
public OnPluginStart() {
  HookEvent("player_death", Event_PlayerDeath);
}

public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast) 
{
  int userID = GetEventInt(event, "userid");
  int client = GetClientOfUserId(userID);
  if (!IsPlayerAlive(client)) {
    CS_RespawnPlayer(client);
  }
  return Plugin_Continue;
}
From coding side it looks good but i think the thing that make this bug is because you need to create timer for 1.0 that check who dead and respawn him... (it checks every 1.0 second who dead and respawn)
Create the timer outside the event(maybe on plugin start or map start).
I think i got more reason but no way to explain it sorry so when i back i will fix it..
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker is offline
shortguy
Member
Join Date: Jul 2009
Old 08-04-2015 , 08:47   Re: CS_RespawnPlayer CSGO become ghost.
Reply With Quote #8

Quote:
Originally Posted by jonitaikaponi View Post
Yeah. I've noticed that player's that get spawned without a valid team, spawn in the way you described. I guess what is happening here, is that the player gets spawned when he is on the spectator team or being changed to it.

Try to use ChangeClientTeam(client, team) before respawning the player.
1 = Spectate
2 = Terrorists
3 = Counter-Terrorists
Thanks for the suggestion, just tried it then using a flat ChangeClientTeam(client, 2), the team change goes ahead but I'm still in the floor. Very strange.

Code:
public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast) 
{
  int userID = GetEventInt(event, "userid");
  int client = GetClientOfUserId(userID);

  bool alive = IsPlayerAlive(client);
  int team = GetClientTeam(client);

  PrintToChat(client, "Alive: %b, Team: %d", alive, team);

  if (!IsPlayerAlive(client)) {
    ChangeClientTeam(client, 2);
    CS_RespawnPlayer(client);
  }
  return Plugin_Continue;
}
Returns Alive: 0, Team: 3 (Counter Terrorists).

Last edited by shortguy; 08-04-2015 at 08:50.
shortguy is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 08-04-2015 , 08:56   Re: CS_RespawnPlayer CSGO become ghost.
Reply With Quote #9

some things just need a delay
Miu is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 08-04-2015 , 09:14   Re: CS_RespawnPlayer CSGO become ghost.
Reply With Quote #10

Quote:
Originally Posted by Miu View Post
some things just need a delay
As i explain before =)
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode