Author Topic: Passing immunity type to another function  (Read 332 times)

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Passing immunity type to another function
« on: May 06, 2016, 06:11:39 AM »
Hi guys,
What's the best way to pass immunity from a call to a function?

i.e. NewFunction(client,targets,Immunity_Ultimates)

Cheers :)

Revan

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Passing immunity type to another function
« Reply #1 on: May 06, 2016, 06:15:41 AM »
Just do it like w3s does:
Code: [Select]
stock W3GetRandomPlayer(team,bool:check_alive=false,War3Immunity:check_immunity=Immunity_None) {

  new clients[MaxClients+1], clientCount;
  for (new i = 1; i <= MaxClients; i++)
    if (IsClientInGame(i) && (GetClientTeam(i) == team) && (!check_alive || IsPlayerAlive(i)) && (!W3HasImmunity(i,check_immunity)))
      clients[clientCount++] = i;
  return (clientCount == 0) ? -1 : clients[GetRandomInt(0, clientCount-1)];
}

like so

Code: [Select]
void NewFunction(int client, int targets[MAXPLAYERSCUSTOM],War3Immunity immunity)
{
   // do stuff
}

NewFunction(client, targets, Immunity_Ultimates);
#war3source on gamesurge

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Passing immunity type to another function
« Reply #2 on: May 06, 2016, 07:56:08 AM »
Yep - im an idiot hahaha

Thanks Revan - just having a mindblock