= $Team2.numPlayers) { $b"> Does this work? | Technical Issues | Forums | Community | GarageGames.com

Game Development Community

Does this work?

by Christian Weber · in Technical Issues · 08/26/2002 (8:40 am) · 13 replies

Hi all!

I want that my bots join a team after I added them, I made this:

Quote:
$botCounter = 0;
function serverCmdAddBot(%client) {
$bots[$botCounter] = aiAddPlayer("Bot" @ $botCounter);
if ($Team1.numPlayers >= $Team2.numPlayers)
{
$bots[$botCOunter].joinTeam(1);
}
else
{
$bots[$botCOunter].joinTeam(1);
}
MissionCleanup.add($bots[$botCounter]);
$botCounter++;
}

Will this work, or what do I have to change.

thx for your help,
Chris

#1
08/26/2002 (8:51 am)
Try it out - then ask yourself if it works?
#2
08/26/2002 (10:18 am)
Sorry couldnt test it, ok it doesnt work correct. It just adds the bot to team #1 not #2. How can I fix that?

thx,
Chris
#3
08/26/2002 (10:32 am)
You almost answered your own question. You made a simple copy & paste error.

Quote: {
$bots[$botCOunter].joinTeam(1);
}
else
{
$bots[$botCOunter].joinTeam(1);
}

Both lines add the player to team 1. One of these needs to be changed to joinTeam(2).
#4
08/26/2002 (10:48 am)
Ooops :) Thx. But it still doesnt work. They alway go in team #1. I changed it now that way, but it didnt help:

Quote:
function serverCmdAddBot(%client) {
$bots[$botCounter] = aiAddPlayer("Bot" @ $botCounter);
if ($botCounter == 1 || 3 || 5 || 7 || 9 || 11 || 13 || 15 ||17)
{
$bots[$botCOunter].joinTeam(1);
}
else
{
$bots[$botCOunter].joinTeam(2);
}
MissionCleanup.add($bots[$botCounter]);
$botCounter++;
}
#5
08/26/2002 (10:51 am)
Do you know what values $botCounter contains? There's a chance that the value returned from aiAddPlayer isn't a number as low as 1 or 3.

Quote:
$botCounter = 0;
function serverCmdAddBot(%client) {
$bots[$botCounter] = aiAddPlayer("Bot" @ $botCounter);
echo ("botcounter = " @ $bots[$botCounter]);
if ($Team1.numPlayers >= $Team2.numPlayers)
{
$bots[$botCOunter].joinTeam(1);
}
else
{
$bots[$botCOunter].joinTeam(1);
}
MissionCleanup.add($bots[$botCounter]);
$botCounter++;
}
#6
08/26/2002 (11:03 am)
Thx for that tip. The first bot starts with 1603 the second has 1610 then 1617 and so on. I made this script but it still doesnt work, but I think this should work. Does someone see the mistake, cause I dont.

Quote:
function serverCmdAddBot(%client) {
$bots[$botCounter] = aiAddPlayer("Bot" @ $botCounter);
echo ("botcounter = " @ $bots[$botCounter]);
if ($bots[$botCounter] == 1603 || 1617 || 1631 || 1645 || 1659 || 1673 || 1687 || 1701)
{
$bots[$botCOunter].joinTeam(1);
}
else
{
$bots[$botCOunter].joinTeam(2);
}
MissionCleanup.add($bots[$botCounter]);
$botCounter++;
}
#7
08/26/2002 (11:23 am)
I don't think you can assume that the first bot's number will be 1603. It's a very bad idea to hard code this into the scripts.

You need to write some code to determine if a bot's number is odd or even and then choose a team accordingly.
#8
08/26/2002 (11:33 am)
I restarted the game a few times and tested it on 2 computers, the first was always 1603. Is it this what you mean?
#9
08/26/2002 (11:36 am)
Yes it is.
#10
08/26/2002 (12:07 pm)
why not do a little model math? if # of bots added to the game is a model of 2 put them on the second team else toss them on the first team.

after you aiAddPlayer(blahahaha)
do something like
$botCount++

if $botCount % 2 then assign to the second team else first team the slacker.

Regards,

Ron
#11
08/26/2002 (12:34 pm)
*give himself a headnut* Sure, thats simple and works great:

Quote:
$botCounter = 0;
$botCount = 0;
function serverCmdAddBot(%client) {
$bots[$botCounter] = aiAddPlayer("Bot" @ $botCounter);
echo ("botcounter = " @ $bots[$botCounter]);
if ($botCount % 2)
{
$bots[$botCounter].joinTeam(1);
}
else
{
$bots[$botCounter].joinTeam(2);
}
MissionCleanup.add($bots[$botCounter]);
$botCounter++;
$botCount++;
}

Thx to all of you, maybe Ill come back to this thread when I have more question to the bots. ;)

chris
#12
08/28/2002 (5:32 pm)
By the way, the reason your old script was always adding the bots to team one is because of the if statement

if ($bots[$botCounter] == 1603 || 1617 || 1631 || 1645 || 1659 || 1673 || 1687 || 1701)

This will always be true regardless of the value of "$bots[$botCounter]" because 1617 or, 1631, etc. is always true. It would have to be changed to the below to work as expected -- although hard coding these numbers will not work for the a different mission file. The way you have it coded now should be perfect for all cases.

if ($bots[$botCounter] == 1603 || 
    $bots[$botCounter] == 1617 || 
    $bots[$botCounter] == 1631 || 
    $bots[$botCounter] == 1645 || 
    $bots[$botCounter] == 1659 || 
    $bots[$botCounter] == 1673 || 
    $bots[$botCounter] == 1687 || 
    $bots[$botCounter] == 1701)
#13
08/29/2002 (5:34 am)
Thx, now I understand it, it was a too simple mistake. *give himself a headnut again*