# Coding bots for call of duty



## ZER0X

> 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    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 

*yawn*_


----------



## b3n

Looks a bit like C++, i wonder if there are any C programmers here.


----------



## ZER0X

> ent_ notify("menuresponse", game["menu_weapon_allies"], "springfield_mp");_


_

I've tried making it like this



			ent notify("menuresponse", game["menu_weapon_allies"], "springfield_mp", "thompson_mp);

Click to expand...

 didn't work....truly is confusing_


----------



## b3n

You will probably have to use a Random Array type function but we need to know what language its in..


----------



## b3n

Have you tried looking at the source code of other games based on the quake 3 engine such as RTCW or Quake 3 itself?


----------



## ZER0X

> }
> 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 

it's probably the most simplest thing_


----------



## ZER0X

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");
> }
> }
> }
> }_


----------



## b3n

So simple yet so confusing. Glad you solved your problem


----------



## ZER0X

b3n said:
			
		

> So simple yet so confusing. Glad you solved your problem



Actually LOL again

When you kill the bot it respawns with that gun  i'm getting annoyed


----------



## b3n

LOL you'll get it one day


----------



## ZER0X

> 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


----------



## SFR

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


----------



## ZER0X

well that seemed pretty close but remember allies can't use axis weapons and vice verca

thanks for your help


----------



## SFR

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....


----------



## ZER0X

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++


----------



## SFR

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


----------



## ZER0X

> 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


----------



## ZER0X

> 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_


----------



## SFR

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 ???


----------



## b3n

That looks alright to me...ZER0X? Did it work?


----------



## ZER0X

No There was no compile error but! when I went to add bots they didn't come in???

Oh yer thanks for helping me again SFR  much appreciated


----------



## ZER0X

Actually again I forgot to do the spacing, so YAYAYAY IT WORKED THANKYOU SFR


----------



## SFR

edit:

LOL.. well I just wrote a post saying sorry... wish I could have helped.. but hell yeah.. cool!

Glad it worked!


Well everyone got a glimpse at software testing LOL


start out with bulky, faulty code.. and work your way down to something simple that works!


----------



## ZER0X

SFR said:
			
		

> edit:
> 
> LOL.. well I just wrote a post saying sorry... wish I could have helped.. but hell yeah.. cool!
> 
> Glad it worked!
> 
> 
> Well everyone got a glimpse at software testing LOL
> 
> 
> start out with bulky, faulty code.. and work your way down to something simple that works!



LOL yer, now all I have to do is make them move (instead of back and fourth firing straight forward) but that means I have to find a file were the bots are made BUT I THINK IT"S IN A DLL thats were I dont think I can go


----------



## SFR

if you find the dll you can email it to me ... I might be able to edit it.


----------



## ZER0X

SFR said:
			
		

> if you find the dll you can email it to me ... I might be able to edit it.



Thanks i'll be sure to do that  

What program opens .dll's I mean of course you can open it in c++ but when I did you couldn't edit anything.....theres also   .....notepad


----------



## SFR

ZER0X said:
			
		

> Thanks i'll be sure to do that
> 
> What program opens .dll's I mean of course you can open it in c++ but when I did you couldn't edit anything.....theres also  .....notepad


 
Well I have an express (beta version) of Visual Studio 5.0 and the full version of Visual Studio .Net 2003 ...  I can create DLL's so I should be able to edit them as well...


----------



## ZER0X

I don't think it's in a .dll I need to find were the bots are scripted to eg (Move shoot etc)so I can edit that It's somewere within the .pk3 files (the files we went through) If I could find it I'd send it to ya to edit.......

I'm hungry anyway time for a late tea


----------



## ZER0X

Sorry for bringing this backup but people have been sending me emails about these bots....how to code them...so I put together a little site

www.coddumbbot.tk


----------



## SFR

ZER0X said:
			
		

> Sorry for bringing this backup but people have been sending me emails about these bots....how to code them...so I put together a little site
> 
> www.coddumbbot.tk


 

Why you sorry? lol

I had fun figuring it out! ... if you ever have any more code you want to change you know where to find me


----------



## ZER0X

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)
			{
				weapons[0] = "mp40_mp";
				weapons[1] = "mp44_mp";
				weapons[2] = "kar98k_mp";
				weapons[3] = "kar98k_sniper_mp";
				ent notify("menuresponse", game["menu_team"], "axis");
				wait 0.5;
				ent notify("menuresponse", game["menu_weapon_axis"], weapons[randomInt(4)]);
				goprone;wait 2;+gostand
			}
			else
			{
				weapons[0] = "bar_mp";
				weapons[1] = "thompson_mp";
				weapons[2] = "m1garand_mp";
				weapons[3] = "m1carbine_mp";
				weapons[4] = "springfield_mp";
				ent notify("menuresponse", game["menu_team"], "allies");
				wait 0.5;
				ent notify("menuresponse", game["menu_weapon_allies"], weapons[randomInt(5)]);
				goprone;wait 2;+gostand
			}
		}
	}
}

Ok there's the code, what I want is for them to change there weapon like the next weapon....

In one of the config files it has: "bind MWHEELDOWN "weapnext" perhaps you can combine that into the above code (Not including the "bind MWHEELDOWN" just "weapnext")

Well SFR you like coding...there you go  it actually is kinda fun to learn code._


----------



## SFR

ZER0X said:
			
		

> Ok there's the code, what I want is for them to change there weapon like the next weapon....
> 
> In one of the config files it has: "bind MWHEELDOWN "weapnext" perhaps you can combine that into the above code (Not including the "bind MWHEELDOWN" just "weapnext")


 

hmmm... I am not quite sure what you want done..

Here is what I think I know: right now when you create/add a BOT it randomly chooses the weopon... thats what we created... instead of randomly choosing the weopon.. do you want to CHOOSE which weopon to give the bot?


----------



## ZER0X

I need them to switch weapons while there actaully in the game.

When you play you get Grenades, a hand gun and the main gun (the gun that you choose) so say randomly it will change to the handgun, then grenades you know etc etc


----------

