Target The Right Team

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Desert Eagle
Captain
Posts: 237
Joined: Mon Jan 13, 2003 1:05 am
Location: Mapping Bunker
Contact:

Target The Right Team

Post by Desert Eagle »

I can get my "ai" tanks running and firing in mulitplayer map. Only problem is they target all players. I have been pulling my hair out.

I just want the tanks to fire at the allies. Any suggestions?


Desert Eagle
User avatar
MPowell1944
Moderator
Posts: 287
Joined: Thu Jan 09, 2003 7:06 am
Location: Woodstock, GA
Contact:

Post by MPowell1944 »

Ask JV. This could be a similar setup that he used with his bots recognizing which team the player was on.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Actually I have also a multiplayer tank & halftrack & flak script that attacks the right players ;).

Just do a $player[number].dmteam check.

dmteam can be:
allies
axis
spectator
freeforall

Example:

Code: Select all

if(local.player.dmteam == allies)
{
    local.dummy = spawn script_origin
    local.dummy attach local.player "Bip01 Head"
    $tiger.turret setaimtarget local.dummy
    $tiger.turret waittill ontarget
    $tiger.turret anim fire // blow his head off
    wait 0.5
    $tiger.turret setaimtarget NULL
    local.dummy remove
}
:)
Image
User avatar
mohaa_rox
Field Marshal
Posts: 2760
Joined: Mon Nov 11, 2002 7:05 am
Contact:

Post by mohaa_rox »

Cool, you're da man! But too bad MoH has no gore, other wise byebye to his head.
Live to map, not map to live.
-mohaa_rox, .map
moderator
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Post by Parts »

The script below I wrote to only target players fairly near by that the tank can actually see. Otherwise you'll find the tank firing at walls because it knows there is a player behind it:

Code: Select all

//************************************** 
//*** this will:
//***    find an player near by to shoot at!
// if local.team = 1 then shoot at axis
// if local.team = 2 then shoot at allies

start local.team:


if (local.team == 1)
{
	println ("looking for Axis target")
	
	//look for first player in range and shoot at them!
	
	for (self.i = 1; self.i <= 32; self.i++)
	{
		if ($player[self.i])
		{
			if ($player[self.i].dmteam == axis)
			{
				if (vector_length (self.origin - $player[self.i].origin) > 200)
				{
					if (vector_length (self.origin - $player[self.i].origin) < 3000)
					{
						if (self cansee $player[self.i])
						{
							println ("targeting player #" + self.i)
							self.gun setAimTarget $player[self.i]
							self.gun waittill ontarget
							self.gun anim fire
							goto breakloop
						}
						else
						{
							println "can't see him!"
						}
					}
				}
			}		
		}
	}
	println "no target found" 
}
else
{
	println ("looking for Allied target")
	
	//look for first player in range and shoot at them!
	
	for (self.i = 1; self.i <= 32; self.i++)
	{
		if ($player[self.i])
		{
			if ($player[self.i].dmteam == allies)
			{
				if (vector_length (self.origin - $player[self.i].origin) > 200)
				{
					if (vector_length (self.origin - $player[self.i].origin) < 3000)
					{
						if (self cansee $player[self.i])
						{
							println ("targeting player #" + self.i)
							self.gun setAimTarget $player[self.i]
							self.gun waittill ontarget
							self.gun anim fire
							goto breakloop
						}
						else
						{
							println "can't see him!"
						}
					}
				}
			}		
		}
	}
	println "no target found" 
}


	
breakloop:

end
Last edited by Parts on Sun Apr 13, 2003 11:41 am, edited 1 time in total.
[VS-UK]Capt.Parts[BnHQ]
User avatar
mohaa_rox
Field Marshal
Posts: 2760
Joined: Mon Nov 11, 2002 7:05 am
Contact:

Post by mohaa_rox »

Awesome! Does it work?
Live to map, not map to live.
-mohaa_rox, .map
moderator
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

I'm afraid you'll have to use sighttrace instead of cansee :?

Also a little tip: use $player.size instead of 32.
Image
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Post by Parts »

ahh ok will change. Certainly works as is however the changes jv-map suggest will make it better
[VS-UK]Capt.Parts[BnHQ]
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

cansee is only supposed to work for AI actors :shock:
Image
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Post by Parts »

it is definitly working at present to good effect on the vs-uk server. You should see the players running for cover as the tank cannon turns to shoot them! :twisted:

However looping through an array of 32 players is not hte best way, .size is a much better idea.

NOTE all these mods I have done are for spearhead.
[VS-UK]Capt.Parts[BnHQ]
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Parts wrote:NOTE all these mods I have done are for spearhead.
That could explain it.
Image
Desert Eagle
Captain
Posts: 237
Joined: Mon Jan 13, 2003 1:05 am
Location: Mapping Bunker
Contact:

Great Thanks

Post by Desert Eagle »

Thanks for the input everyone. It now seems to be working right. The axis can now be the ground support for the tanks without being shot at by the tanks. Also the allies now have a reason for at least one of them to have a bazooka.

Now tanks moving, stopping and firing at allied players. This is great!

I have been trying hard to give my Spearhead, Roundbased/TOW map that feel like your really there, like in the SIngle Player missions.

So Far:

2 axis tanks running their course and firing at allied players
By using Projectile Genators in maps, giving the impression of a large firefight
Walls that explode apart like in Malta
Allied Assault Gliders the allies ride into battle
Allied portable airborne artillery peice that I built that is driven out via a jeep out of Glider.
Smoke, Fire, Ruined Buidlings
Firing Battery of Flak88 for the axis to shoot down allied airstrikes carried out by p-47 Thunderbolts.

Kinda a Destoyred Village, Small City, St Renan and Stalingard all in type of map.

Whats left:
The scripting nightmare
A little more Manvis
TOW objectives and triggers
Post Reply