Archived copy of war3source.com, the War3Source forum (2009–2020), rebuilt from the Internet Archive by wc3mods.net. This page was captured on 2013-01-25 (original capture). Forum · All archived topics · Wiki · Bug tracker · Blog
Chat

War3:Source
January 24, 2013, 07:06:37 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Download: http://war3source.com/index.php?board=9.0
What is War3Source?: http://war3source.com/index.php?topic=200.0
Sample Stats: http://war3source.com/war3stats
Steam Community Group: http://steamcommunity.com/groups/war3source
War3Source SVN Checkout: http://ownageclan.com/svn/war3source/
War3Source servers: http://www.game-monitor.com/search.php?vars=war3_version=
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: War3_GetRandomPlayer  (Read 160 times)
Remy Lebeau
Full Member
***
Posts: 172


View Profile
« on: November 08, 2012, 05:19:47 PM »

In the course of updating a number of races, I've found that some of them (that use haaaxfunctions include) call the function War3_GetRandomPlayer.

I've assumed that most of what was in the haaaxfunctions include has now been incorporated into the main code (and have commented that include out), however I still get errors that the function War3_GetRandomPlayer is undefined.

Has this function been replaced?  I can't seem to find an equivalent.

Thanks for any help!
Logged
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2169



View Profile WWW
« Reply #1 on: November 08, 2012, 05:20:51 PM »

idk man. old races are ollllld
Logged

DarkEnergy
Remy Lebeau
Full Member
***
Posts: 172


View Profile
« Reply #2 on: November 08, 2012, 05:50:21 PM »

Let me rephrase the question then ... is there a function that can will return a random player

Code:
stock War3_GetRandomPlayer( const String:type[] = "#a", bool:check_alive = false, bool:check_immunity = false )
{
new targettable[MaxClients];
new target = 0;
new bool:all;
new x = 0;
new team;
if( StrEqual( type, "#t" ) )
{
team = TEAM_T;
all = false;
}
else if( StrEqual( type, "#ct" ) )
{
team = TEAM_CT;
all = false;
}
else if( StrEqual( type, "#a" ) )
{
team = 0;
all = true;
}
for( new i = 1; i <= MaxClients; i++ )
{
if( i > 0 && i <= MaxClients && IsClientConnected( i ) && IsClientInGame( i ) )
{
if( check_alive && !IsPlayerAlive( i ) )
continue;
if( check_immunity && W3HasImmunity( i, Immunity_Ultimates ) )
continue;
if( !all && GetClientTeam( i ) != team )
continue;
targettable[x] = i;
x++;
}
}
for( new y = 0; y <= x; y++ )
{
if( target == 0 )
{
target = targettable[GetRandomInt( 0, x - 1 )];
}
else if( target != 0 && target > 0 )
{
return target;
}
}
return 0;
}

That's the code that it used to use... I'm happy to just reuse that, however if there is already a function in the interface that will do this, I'd prefer to not have to include another dependency.
Logged
Revan
Sr. Member
****
Posts: 346



View Profile
« Reply #3 on: November 09, 2012, 01:02:27 PM »

You could also use the colors.inc FindRandomPlayer function:
http://ownageclan.com/war3source/functionreference/
CFindRandomPlayerByTeam

nevertheless:
I've added(update svn) a new W3GetRandomPlayer stock which is able to check lifestate and w3immunity(for future usage).
« Last Edit: November 09, 2012, 01:24:25 PM by Revan » Logged

#war3source
Remy Lebeau
Full Member
***
Posts: 172


View Profile
« Reply #4 on: November 09, 2012, 02:14:26 PM »

Fantastic! Thanks Revan.

I just recompiled using haaaxfunctions for now, but will def rework it in the future.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!