Page 1 of 1

a tank shooting in mp level

Posted: Sat Aug 02, 2003 1:37 pm
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

Posted: Sat Aug 02, 2003 4:00 pm
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

Posted: Sat Aug 02, 2003 5:12 pm
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)

Posted: Sat Aug 02, 2003 7:40 pm
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

Posted: Mon Aug 04, 2003 7:24 am
by martijn_NL
thanks, your script worked out on my map

Posted: Mon Aug 04, 2003 6:27 pm
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.

Posted: Mon Aug 04, 2003 7:38 pm
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

Posted: Tue Aug 05, 2003 6:24 am
by martijn_NL
I gonna try that

Posted: Wed Aug 06, 2003 11:13 am
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:

Posted: Wed Aug 06, 2003 1:20 pm
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.

Posted: Thu Aug 07, 2003 12:18 pm
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 
                  }

Posted: Thu Aug 07, 2003 1:02 pm
by martijn_NL
thanks it worked out 8-)

Posted: Sun Aug 10, 2003 11:37 am
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.