• Print

Author Topic: Help With Respawn Command  (Read 5295 times)

0 Members and 1 Guest are viewing this topic.

Offline Valor

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Help With Respawn Command
« on: October 14, 2014, 08:45:16 pm »
I'm attempting to create a respawn command for Chessnut Jailbreak, but I have had no luck. I've spent hours searching for tutorials and pieces of code with no success. The code I'm trying to spawn the player with is this:


function ulx.respawn( calling_ply, target_ply )
   if (target_ply:Team() == TEAM_GUARD_DEAD) then
      target_ply:SetTeam(TEAM_GUARD)
      target_ply:Spawn()
      ulx.fancyLogAdmin( calling_ply, true, "#A respawned #T", target_ply )
   elseif (target_ply:Team() == TEAM_PRISONER_DEAD) then
      target_ply:SetTeam(TEAM_PRISONER)
      target_ply:Spawn()
      ulx.fancyLogAdmin( calling_ply, true, "#A respawned #T", target_ply )
   end
end
 
local respawn = ulx.command( "RespawnMe", "ulx respawn", ulx.respawn, "!respawn", false )
respawn:addParam{ type=ULib.cmds.PlayerArg }
respawn:defaultAccess( ULib.ACCESS_ADMIN )
respawn:help( "Respawns a player" )



There were many respawn commands I found, but this one seemed to almost work. Credit for it goes to the people in this thread: /index.php/topic,7675.0.html#msg39074 />
The problem with this command is it teleports the player to a spawn point, but it does not change their team to an alive guard or an alive prisoner. When I removed the target_ply:Spawn(), it changed the player's team to an alive guard/prisoner, but it did not spawn the player or teleport the player to a spawn point. I searched through the gamemode files and found nothing that could help me with this problem except  this:

function GM:ShouldPlayerSpectate()
   return JB_ROUND_STATE == ROUND_ACTIVE or JB_ROUND_STATE == ROUND_DEAD or JB_ROUND_STATE == ROUND_END;
end;


Could this be blocking the player from spawning in? If so how would I fix it? Also, this was found in sv_rounds.lua.

I'm not sure if a respawn command is possible for this gamemode, but I would really appreciate it if someone could help me.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Help With Respawn Command
« Reply #1 on: October 14, 2014, 09:11:54 pm »
Spawn first, then set team.
Out of the Garry's Mod business.

Offline Valor

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Help With Respawn Command
« Reply #2 on: October 14, 2014, 09:32:12 pm »
I changed it to this.

function ulx.respawn( calling_ply, target_ply )
   if (target_ply:Team() == TEAM_GUARD_DEAD) then
      target_ply:Spawn()
      target_ply:SetTeam(TEAM_GUARD)
            ulx.fancyLogAdmin( calling_ply, true, "#A respawned #T", target_ply )
   elseif (target_ply:Team() == TEAM_PRISONER_DEAD) then
      target_ply:Spawn()
      target_ply:SetTeam(TEAM_PRISONER)
      ulx.fancyLogAdmin( calling_ply, true, "#A respawned #T", target_ply )
   end
end

Now it sets the team to alive and teleports the player to a spawn point, but it does not spawn them.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Help With Respawn Command
« Reply #3 on: October 14, 2014, 10:31:25 pm »
Code: Lua
  1. function ulx.respawn( calling_ply, target_ply )
  2.         if target_ply:Team() == TEAM_GUARD_DEAD then
  3.                 target_ply:Spawn()
  4.                 target_ply:SetTeam( TEAM_GUARD )
  5.                 ulx.fancyLogAdmin( calling_ply, true, "#A respawned #T", target_ply )
  6.         elseif target_ply:Team() == TEAM_PRISONER_DEAD then
  7.                 target_ply:Spawn()
  8.                 target_ply:SetTeam( TEAM_PRISONER )
  9.                 ulx.fancyLogAdmin( calling_ply, true, "#A respawned #T", target_ply )
  10.         end
  11. end
  12. local respawn = ulx.command( "RespawnMe", "ulx respawn", ulx.respawn, "!respawn" )
  13. respawn:addParam{ type=ULib.cmds.PlayersArg }
  14. respawn:defaultAccess( ULib.ACCESS_ADMIN )
  15. respawn:help( "Respawn a target player." )

From what this looks like, based on your given code, this should be working.
A third party is at play here if this doesn't work. Check installed addons/plugins.
Out of the Garry's Mod business.

Offline Valor

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Help With Respawn Command
« Reply #4 on: October 15, 2014, 07:21:55 pm »
I think this was blocking the command from working:

function GM:ShouldPlayerSpectate()
   return JB_ROUND_STATE == ROUND_ACTIVE or JB_ROUND_STATE == ROUND_DEAD or JB_ROUND_STATE == ROUND_END;
end;

I removed JB_ROUND_STATE == ROUND_ACTIVE and the command does successfully revive someone. The only problem is players now automatically spawn upon joining the server, and players auto respawn when they are killed. How could I fix this issue? Would I use GM:PlayerInitialSpawn and GM:PlayerDeath in this function?

  • Print