AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   CS_RespawnPlayer CSGO become ghost. (https://forums.alliedmods.net/showthread.php?t=268058)

shortguy 08-04-2015 05:52

CS_RespawnPlayer CSGO become ghost.
 
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.

jonitaikaponi 08-04-2015 06:25

Re: CS_RespawnPlayer CSGO become ghost.
 
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 ?

shortguy 08-04-2015 07:23

Re: CS_RespawnPlayer CSGO become ghost.
 
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?

TheUnderTaker 08-04-2015 07:45

Re: CS_RespawnPlayer CSGO become ghost.
 
Show your code in pm or here.

shortguy 08-04-2015 08:07

Re: CS_RespawnPlayer CSGO become ghost.
 
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;
}


jonitaikaponi 08-04-2015 08:17

Re: CS_RespawnPlayer CSGO become ghost.
 
Quote:

Originally Posted by shortguy (Post 2328193)
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

TheUnderTaker 08-04-2015 08:29

Re: CS_RespawnPlayer CSGO become ghost.
 
Quote:

Originally Posted by shortguy (Post 2328213)
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..

shortguy 08-04-2015 08:47

Re: CS_RespawnPlayer CSGO become ghost.
 
Quote:

Originally Posted by jonitaikaponi (Post 2328217)
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).

Miu 08-04-2015 08:56

Re: CS_RespawnPlayer CSGO become ghost.
 
some things just need a delay

TheUnderTaker 08-04-2015 09:14

Re: CS_RespawnPlayer CSGO become ghost.
 
Quote:

Originally Posted by Miu (Post 2328229)
some things just need a delay

As i explain before =)


All times are GMT -4. The time now is 20:28.

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