a tank shooting in mp level

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
martijn_NL
Map Reviewer
Posts: 156
Joined: Mon Apr 14, 2003 5:33 pm
Location: The Netherlands
Contact:

a tank shooting in mp level

Post by martijn_NL »

I want to make tank in my level that will shoot on the the allied players (if they are visible for the tank)

I made a tank in my map (panzer IV), gived it a targetname.
Then i made this script.

tank:
$panzerIV1.gun = $panzerIV1 QueryTurretSlotEntity 0


while (level.tankbom == 0)
{
level.players = $player.size
local.sucker = (randomint (level.players))
if ($panzerIV1 cansee local.sucker && local.sucker.dmteam == "allies")
{
$panzerIV1.gun setaimtarget local.sucker
$panzerIV1.gun waittill ontarget
$panzerIV1.gun anim fire
}
}
end

can someone help me
Mapping 4 life
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Post by Parts »

here's one I made earlier :shock:

This script takes a sparameter defining which side you want the vehicle to aim at.

Code: Select all

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

ShootAtTeam 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 <= $player.size; self.i++)
	{
		if ( isalive($player[self.i]) && ($player[self.i].health > 0) )
		{
			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
						}

					}
				}
			}		
		}
	}
//	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 <= $player.size ; self.i++)
	{
		if ( isalive($player[self.i]) && ($player[self.i].health > 0) )
		{
			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
						}
					}
				}
			}		
		}
	}
	//println "no target found" 
}


	
breakloop:

end 
so if you were writing a thread that continually looked for allies and shot at them it would look like this:


Code: Select all

LoopingThread:
   while (1)
   {

      $mytanktargetname ShootAtTeam 2

      //pause so do don't take up all the processor time
      wait 1

   }

end
[VS-UK]Capt.Parts[BnHQ]
User avatar
martijn_NL
Map Reviewer
Posts: 156
Joined: Mon Apr 14, 2003 5:33 pm
Location: The Netherlands
Contact:

Post by martijn_NL »

what does this mean :

if (vector_length (self.origin - $player[self.i].origin) > 200)
{
if (vector_length (self.origin - $player[self.i].origin) < 3000)
Mapping 4 life
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

you may need to define the gun ?

self.gun= self QueryTurretSlotEntity 0
if (vector_length (self.origin - $player[self.i].origin) > 200)
{
if (vector_length (self.origin - $player[self.i].origin) < 3000)
a vector is a line from point a to point b so those lines check the length of the vector from the gun to the player so that they are in the range of more than 200 and less than 3000
User avatar
martijn_NL
Map Reviewer
Posts: 156
Joined: Mon Apr 14, 2003 5:33 pm
Location: The Netherlands
Contact:

Post by martijn_NL »

thanks, your script worked out on my map
Mapping 4 life
User avatar
martijn_NL
Map Reviewer
Posts: 156
Joined: Mon Apr 14, 2003 5:33 pm
Location: The Netherlands
Contact:

Post by martijn_NL »

I played my map with my clan on our clanserver, but then the tank does not fire, i think this is realy strange, because it did work on my own pc when i start level (local server). I though maybee a error, but with logfile 2 i did not see any errors. This is so weird, please help.
Mapping 4 life
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Post by Parts »

Seems like the mod is either not installed or another mod is overwriting it.

Put some debug text in your script after level waittill spawn using println and see if they appear in the log file. At least you will know if the script is being ran at all
[VS-UK]Capt.Parts[BnHQ]
User avatar
martijn_NL
Map Reviewer
Posts: 156
Joined: Mon Apr 14, 2003 5:33 pm
Location: The Netherlands
Contact:

Post by martijn_NL »

I gonna try that
Mapping 4 life
User avatar
martijn_NL
Map Reviewer
Posts: 156
Joined: Mon Apr 14, 2003 5:33 pm
Location: The Netherlands
Contact:

Post by martijn_NL »

I made a mistake, i made a global script of your script u have to me. But i forgot to pack it in the *.pk3 file. :oops:
Mapping 4 life
User avatar
martijn_NL
Map Reviewer
Posts: 156
Joined: Mon Apr 14, 2003 5:33 pm
Location: The Netherlands
Contact:

Post by martijn_NL »

I dicovered i major bug in your script, parts.
When i'm shoot by the tank the guns keeps following me, also when choose another team(It doesn't find another target when it killed someone but it sticks to one target)(only when i'm playing alone). I tried some things bit they don't work out someone know a solution for that? I used the script parts gave to me.
Mapping 4 life
Parts
Sergeant
Posts: 72
Joined: Thu Apr 10, 2003 12:35 pm
Location: UK
Contact:

Post by Parts »

martijn_NL wrote:I dicovered i major bug in your script, parts.
When i'm shoot by the tank the guns keeps following me, also when choose another team(It doesn't find another target when it killed someone but it sticks to one target)(only when i'm playing alone). I tried some things bit they don't work out someone know a solution for that? I used the script parts gave to me.
OK I think the line that is causing the problem is setaimat. Effectivly the tank will continue to aim at that player event though it is not shooting and can't see them!

Try changing it to this:

Code: Select all

                  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 
                     self.gun setAimTarget NULL 
                     goto breakloop 
                  }
[VS-UK]Capt.Parts[BnHQ]
User avatar
martijn_NL
Map Reviewer
Posts: 156
Joined: Mon Apr 14, 2003 5:33 pm
Location: The Netherlands
Contact:

Post by martijn_NL »

thanks it worked out 8-)
Mapping 4 life
User avatar
martijn_NL
Map Reviewer
Posts: 156
Joined: Mon Apr 14, 2003 5:33 pm
Location: The Netherlands
Contact:

Post by martijn_NL »

I found another bug, the tank cannot shoot through windows. My question is how can i make the tank shoot through a window. I checked the console and it said no allied target found. To me it seemd that the tank sees the window is a wall.
Mapping 4 life
Post Reply