Author Topic: Setting a person's team  (Read 1218 times)

How would I do this?
Code: [Select]
function serverCmdSetKing(%client, %name)
{
if(%client.isAdmin)
{
%target = findClientByName(%name);
if(isObject(%target))
{
messageall('', "\c6The king was killed and his place was taken.");
%target.Isking = 1;
                        //Now what would I do to set %target's team to team 3.
}
}
else
{
messageClient(%client, '', "\c6You must be an admin to use this command.");
}
}

%target.setTeam(2);, assuming you mean Team Deathmatch. They have to be in a TDM-using minigame, though. It's 2 not 3 because the numbering starts from 0. (-1 = no team, 0 = team 1, 1 = team 2, etc.)

Thanks. How would I make it so the current player(s) in team 3 are put into team 2?

Do a loop through the minigame's members, check if(client.tdmTeam == 2) then setTeam(1).

function CheckKing(%client)
{
   for(%i=0;%i<clientGroup.GetCount();%i++)
   {
      %CurKing = clientgroup.getobject(%i); 
      if(%CurKing.tdmTeam == 2)
      {   
         %CurKing.setTeam(1);
         %client.setTeam(2);
      }
   }
}


function serverCmdKing(%client, %name)
{
   if(%client.isAdmin)
   {
      %target = findClientByName(%name);
      if(isObject(%target))
      {
         CheckKing(%client);   
      }
   }
   else
   {
      messageClient(%client, '', "\c6You must be an admin to use this command.");
   }
}
Doesn't seem to work. No console errors.

Code: [Select]
     if(isObject(%target))
      {
         CheckKing(%client);  
      }
If you've picked a valid target, it'll try to set the client who triggered the function as a king rather than the actual target.

Plus you're using clientgroup rather than minigame checks which makes it bad...

function CheckKing(%client)
{
   for(%i=0;%i<clientGroup.GetCount();%i++)
   {
      %CurKing = clientgroup.getobject(%i); 
      if(%CurKing.tdmTeam == 2)
      {   
         %CurKing.setTeam(1);
         %client.setTeam(2);
         //add break; here
      }
   }
}


function serverCmdKing(%client, %name)
{
   if(%client.isAdmin)
   {
      %target = findClientByName(%name);
      if(isObject(%target))
      {
         CheckKing(%client);   
      }
   }
   else
   {
      messageClient(%client, '', "\c6You must be an admin to use this command.");
   }
}
Doesn't seem to work. No console errors.

"CheckKing(%client); "
Should probably be
"CheckKing(%target); "


Also it wont work unless there's a king to begin with.
Code: [Select]
function CheckKing(%client)
{
   for(%i=0;%i<clientGroup.GetCount();%i++)
   {
      %CurKing = clientgroup.getobject(%i);
      %client.setTeam(2);
      if(%CurKing.tdmTeam == 2)
      {   
         %CurKing.setTeam(1);
         //add break; here
      }
   }
}
Try that.

"CheckKing(%client); "
Should probably be
"CheckKing(%target); "


Also it wont work unless there's a king to begin with.
Code: [Select]
function CheckKing(%client)
{
   for(%i=0;%i<clientGroup.GetCount();%i++)
   {
      %CurKing = clientgroup.getobject(%i);
      %client.setTeam(2);
      if(%CurKing.tdmTeam == 2)
      {   
         %CurKing.setTeam(1);
         //add break; here
      }
   }
}
Try that.


Actually %client.setTeam(2); should be after the loop.

Actually %client.setTeam(2); should be after the loop.
Right. Might be better just to
Code: [Select]
function CheckKing(%client)
{
   for(%i=0;%i<clientGroup.GetCount();%i++)
   {
      %CurKing = clientgroup.getobject(%i);
      %client.setTeam(2);
      if(%CurKing.tdmTeam == 2 && %CurKing != %client)
      {   
         %CurKing.setTeam(1);
         //add break; here
      }
   }
}

If the %client.setTeam(2); is outside of the loop, then it wont be called like 6 or 7 times.

Right. Might be better just to
Code: [Select]

function CheckKing(%client)
{
   %client.setTeam(2);
   for(%i=0;%i<clientGroup.GetCount();%i++)
   {
      %CurKing = clientgroup.getobject(%i);
      if(%CurKing.tdmTeam == 2 && %CurKing != %client)
      {   
         %CurKing.setTeam(1);
         //add break; here
      }
   }
}

It might be more helpful to not have the break statement in case they've used the teams menu to force more than one player as a 'King' that round.


It might be more helpful to not have the break statement in case they've used the teams menu to force more than one player as a 'King' that round.
Once again onto the fold
Code: [Select]
function CheckKing(%client)
{
   %client.setTeam(2);
   for(%i=0;%i<clientGroup.GetCount();%i++)
   {
      %CurKing = clientgroup.getobject(%i);
      if(%CurKing.tdmTeam == 2 && %CurKing != %client)
      {   
         %CurKing.setTeam(1);
         //don't add break; here
      }
   }
}