Author Topic: Help With Respawn Command  (Read 2443 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: http://forums.ulyssesmod.net/index.php/topic,7675.msg39074.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.

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given