Coding bots for call of duty

ZER0X

VIP Member
addBotClients()
{
wait 5;

for(;;)
{
if(getCvarInt("scr_numbots") > 0)
break;
wait 1;
}

iNumBots = getCvarInt("scr_numbots");
for(i = 0; i < iNumBots; i++)
{
ent = addtestclient();
wait 0.5;

if(isPlayer(ent))
{
if(i & 1)
{
ent notify("menuresponse", game["menu_team"], "axis");
wait 0.5;
ent notify("menuresponse", game["menu_weapon_axis"], "kar98k_mp");
}
else
{
ent notify("menuresponse", game["menu_team"], "allies");
wait 0.5;
ent notify("menuresponse", game["menu_weapon_allies"], "springfield_mp");

}
}
}
}


Above is a code written in I think C++ for Call of Duty and it's a way to get bots in multiplayer

what I need help with is as you can see they only choose (Axis: Kar98k)(Allies: Springfield) I would like them to choose a gun out of random guns :o eg allies: springfield thompson etc axis: Kar98k scoped and kar98k not scoped

You can change the gun that they spawn with but not make them choose a gun randomly I've tried for hours to figure it out, not as simple as I assumed :rolleyes:

*yawn*
 
You will probably have to use a Random Array type function but we need to know what language its in..
 
Have you tried looking at the source code of other games based on the quake 3 engine such as RTCW or Quake 3 itself?
 
}
else
{
ent notify("menuresponse", game["menu_team"], "allies");
wait 0.5;
ent notify("menuresponse", game["menu_weapon_allies"], "springfield_mp");

}
{
ent notify("menuresponse", game["menu_team"], "allies");
wait 0.5;
ent notify("menuresponse", game["menu_weapon_allies"], "thompson_mp");
}
}
}
}


Tried that aswell didn't even appear that time :P

it's probably the most simplest thing
 
LMAO I acually figured it out had to remove one space

}
else
{
ent notify("menuresponse", game["menu_team"], "allies");
wait 0.5;
ent notify("menuresponse", game["menu_weapon_allies"], "springfield_mp");
<---------------------------------remove
}
{
ent notify("menuresponse", game["menu_team"], "allies");
wait 0.5;
ent notify("menuresponse", game["menu_weapon_allies"], "thompson_mp");
}
}
}
}
 
Have you tried looking at the source code of other games based on the quake 3 engine such as RTCW or Quake 3 itself?

RTCW Don't have built in bots like CoD so I can't get help from that although When I get quake 3 I'll surely look into that :)

LOL you'll get it one day

I hope :P
 
Okay I was working through some code... There are some variables in there that are not defined, at least in the piece of code you posted. And I am not sure if it is C++ ..


But in C++ there is a function called rand() It allows you to randomly pick an interger. I was thinking if you save that to a variable and then test either by case or if/then...



Code:
[/color]
[color=blue]if(isPlayer(ent[i]))
{[/color]
 
[color=black]str aWeapons1 = "springfield_mp";[/color]
[color=black]str aWeapons2 = "thompson_mp";[/color]
[color=black]str aWeapons3 = "kar98k_mp";[/color]
 
[color=black]for(iControl = 0; iControl < 2 ; iControl++)
{
int iRand=rand(3);
sWeapon= "aWeapons" & iRand;[/color]
[color=black]if (iControl =0)[/color]
[color=blue]{[/color]
[color=blue]ent[i] notify("menuresponse", game["menu_team"], "axis");
wait 0.5;
ent[i] notify("menuresponse", game["menu_weapon_axis"], [/color][color=red]sWeapon[/color][color=blue]);
}[/color]
[color=blue]else
{
ent[i] notify("menuresponse", game["menu_team"], "allies");
wait 0.5;
ent[i] notify("menuresponse", game["menu_weapon_allies"], [/color][color=red]sWeapon[/color][color=blue]);
 
}
[/color][color=blue]}[/color]
[color=blue]}[/color]
 
[color=black]





Or I am way off....


edit:
and also I am not sure if you can concatonate a string and an int into a string...

eh.. I doubt it will work.. maybe it will spark something in someone and they will figure itout
 
Last edited:
well that seemed pretty close but remember allies can't use axis weapons and vice verca

thanks for your help :)
 
Code:
[color=#0000ff]if(isPlayer(ent[i]))
{[/color]
 
[color=black]for(iControl = 0; iControl < 2 ; iControl++)
{
[/color][color=black]if (iControl =0)[/color]
[color=blue]{[/color]
[color=red]str aWeapons1 = "AXIS WEAPON";
str aWeapons2 = "AXIS WEAPON";[/color]
[color=red]int iRand=rand(2);
sWeapon= "aWeapons" & iRand;[/color]
[color=blue]ent[i] notify("menuresponse", game["menu_team"], "axis");
wait 0.5;
ent[i] notify("menuresponse", game["menu_weapon_axis"], [/color][color=red]sWeapon[/color][color=blue]);
}[/color]
[color=blue]else
{[/color]
[color=blue][color=red]str aWeapons1 = "AXIS WEAPON";
str aWeapons2 = "AXIS WEAPON";[/color]
[color=red]int iRand=rand(2);
sWeapon= "aWeapons" & iRand;
[/color]ent[i] notify("menuresponse", game["menu_team"], "allies");
wait 0.5;
ent[i] notify("menuresponse", game["menu_weapon_allies"], [/color][color=red]sWeapon[/color][color=blue]);
 
}
[/color][color=blue]}[/color]
[color=blue]}[/color]

[color=black]
[/color]

hmm....
 
I thought that was it for sure, but in the console it's saying bad syntax and failing to compile the script so maybe it's an actual builtscript with the quake 3 engine?? in other words maybe the quake 3 engine made there own code similar to c++
 
ZER0X said:
I thought that was it for sure, but in the console it's saying bad syntax and failing to compile the script so maybe it's an actual builtscript with the quake 3 engine?? in other words maybe the quake 3 engine made there own code similar to c++

I think you are right.

Other than the string and int being assigned to a string.. the C++ code seemed fine... logic and syntax wise... but yeah either that or the rand() function needed a c++ library <stdlib.h> ..I figured it would have been included.... guess that means you have to manually go in and change the weapons everytime you want different guns... lol
 
case "allies":
case "axis":
case "autoassign":
if(response == "autoassign")
{
teams[0] = "allies";
teams[1] = "axis";
response = teams[randomInt(2)];

spawnpointname = "mp_deathmatch_intermission";
spawnpoints = getentarray(spawnpointname, "classname");
spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(spawnpoints);

Theres two randoms found in the script maybe I could use them to somehow to randomize the guns hmmmmm
 
ent notify("menuresponse", game["menu_team"], "allies");
wait 0.5;
ent notify("menuresponse", game["menu_weapon_allies"], randomint("springfield_mp", "thompson_mp"));


I put that randomint there and the even number bots (american) went to spectator lol
 
5 edits later:

lol okay I think I might have it


Code:
addBotClients()
{
wait 5;
 
for(;;)
{
if(getCvarInt("scr_numbots") > 0)
break;
wait 1;
}
 
iNumBots = getCvarInt("scr_numbots");
for(i = 0; i < iNumBots; i++)
{
ent[i] = addtestclient();
wait 0.5;
 
if(isPlayer(ent[i]))
{
if(i & 1)
{
[color=red]weapons[0] = "AXIS WEAPON";
weapons[1] = "AXIS WEAPON";
[/color][color=blue]ent[i] notify("menuresponse", game["menu_team"], "axis");
wait 0.5;
ent[i] notify("menuresponse", game["menu_weapon_axis"], [/color][color=red]weapons[randomInt(2)][/color][color=blue]);
}[/color]
[color=blue]else
{[/color]
[color=blue][color=red]weapons[0] = "ALLIES WEAPON";
weapons[1] = "ALLIES WEAPON";
[/color][/color]
[color=blue]ent[i] notify("menuresponse", game["menu_team"], "allies");
wait 0.5;
ent[i] notify("menuresponse", game["menu_weapon_allies"], [/color][color=red]weapons[randomInt(2)][/color][color=blue]);
 
}
[/color]}
}
}


... I keep spelling weapon wrong... wtf ???
 
Last edited:
Back
Top