Page 1 of 1

dm.projectile for tanks

Posted: Mon Mar 31, 2008 2:48 am
by Wierdo
I have a problem. I made a tank from the script and spawned it into a dm map. I made the sounds work, made the turret follow the $player, and shoot. Germans will leave the tank when destroyed as well.

Now the problem: The cannon fires blanks. No damage is delivered to the player.

If I could get a "scripting God" or lucky layman to help me out, I would be greatful. The error says I need a model for a projectile attack. Here's the script:

Code: Select all

//****************
// Installs a Tiger Tank
//****************

spawn_thing:
   local.temp = spawn models/vehicles/tigertank.tik "targetname" "tank1"
   $tank1.dmprojectile= "models/projectiles/tigercannonshell.tik"
   local.temp.origin = $spawn_origin.origin
   self remove   
   thread tank
end


tank:

	$tank1 waitthread tank1_initialize 		//setup tank properties
	$tank1 thread tank1_feedback			//monitor for damage taken and gives feedback effects
	//$tank1 waitthread tank1_move $tank1_path	//setup tank movement parameters and make tank move
	$tank1 thread tank1_targeting			//targeting systems
	$tank1 thread tank1_death			//monitor for death
end

tank1_initialize:
	//*** Setup the tank properties

	local.gun = self QueryTurretSlotEntity 0 		//local.gun is the tank turret itself   	local.gun.dmprojectile= "models/projectiles/tigercannonshell.tik"
 	local.gun.turret1= "vehicles/tigercannon.tik"

	local.gun2 = self QueryTurretSlotEntity 1		//local.gun2 is the machine gun if it ever worked
	self.health = 1000				//health - damage per player's panzerschreck shell is 200
	self removeondeath 0 			//prevent it from vanishing when destroyed
	self lock					//prevent it from being usable by the player
	local.gun TurnSpeed 8			//set the turret traversing speed original value 4



	self immune bullet
	self immune fast_bullet
	self immune grenade
	self immune bash
end

tank1_feedback:

	local.originalhealth = self.health
	local.previoushealth = self.health	//initialize	

	while (isAlive $tank1)
	{
		waitframe

		if !(isAlive $tank1)
			end

		if (self.health < local.previoushealth)
		{
			local.tankfraction = (self.health / local.originalhealth) * 100
			local.tankfractioninteger = int local.tankfraction
			iprintlnbold_noloc (loc_convert_string "TIGER TANK: ") local.tankfractioninteger (loc_convert_string " percent")//(loc_convert_string "\%")
			local.previoushealth = self.health
		}		
	}

end

tank1_death:

	self waittill death

	iprintlnbold "Tiger Tank destroyed."

	local.gun = self QueryTurretSlotEntity 0		//local.gun is the tank turret itself
	local.gun2 = self QueryTurretSlotEntity 1		//local.gun2 is the machine gun if it ever worked

	self show
	self playsound explode_tank
	self stop

	local.gun stopfiring

	//*** If a main gun and/or mounted machine gun exists on the tank, remove it

		if (local.gun)
		{
			self DetachTurretSlot 0
			local.gun remove
		}

		if (local.gun2)
		{
			self DetachTurretSlot 1
			local.gun2 remove
		}

	//*** Activate the explosion visual effect

		local.temp = spawn script_model
		local.temp.origin = self.origin
		local.temp model "fx/fx_tank_explosion.tik"
		local.temp anim start

	//*** Shake the player's view hard

		exec global/earthquake.scr .23 4 0 0

	//*** Issue some damage in a radius around the destroyed vehicle

		radiusdamage self.origin 200 200

		//Kill the player if there's a chance they might be stuck in the barrel...don't be close when the tank explodes.

		radiusdamage ( ($tank1_radiusdamage_source.origin) + (0 0 16) ) 2000 325 1 

	//*** Turn on the tank barrel collision 

//		$tank1_barrel_collision solid

	//*** Replace the model with the destroyed version and give it a collision mask

		local.brushmodel = self.target.brushmodel

		local.collision = spawn script_object model local.brushmodel
		local.collision.angles = self.angles
		local.collision.origin = self.origin
		local.collision disconnect_paths

		local.damaged = spawn script_model model models/vehicles/tigertank_d.tik
//		local.damaged.targetname = self.targetname	
		local.damaged.origin = self.origin
		local.damaged.angles = self.angles
		self remove

	//*** Initialize the 'guys getting out of the tank' animation

		local.anims[0] = tank_exit_1
		local.anims[1] = tank_exit_2
		local.anims[2] = tank_exit_3
		local.anims[3] = tank_exit_4

		local.damaged thread global/vehicles_thinkers.scr::tank_guys_get_out local.anims

end

tank1_targeting: 

if (isAlive self) 
   { 
   self fullstop 
   local.gun = self QueryTurretSlotEntity 0
   local.gun setAimTarget $player 
   local.gun waittill ontarget
   goto fire
   }
end

fire: 
   if (isAlive self)
{
local.trace = trace (self.origin + (0 0 120)) ($player[local.i].origin + (0 0 48)) 1 
   if ! ((local.trace[0] == $player[local.i].origin[0]) || (local.trace[1] == $player[local.i].origin[1]) || (local.trace[2] == $player[local.i].origin[2] + 48)) 
   {
      println "DENIED BY NO LINE OF SIGHT"
      wait 1
      goto fire
   }
      local.gun startfiring
      wait 1
      local.gun stopfiring
      wait 5
      local.gun waittill ontarget
      goto fire
}
end

This script may also have problems attacking more than one $player in multiplayer. :cry:

Posted: Mon Mar 31, 2008 4:59 pm
by jv_map
Hi Weirdo,

Is this for AA, SH or BT? I take it you wish to use it in multiplayer?

dm.projectile

Posted: Tue Apr 01, 2008 2:23 am
by Wierdo
Affirmative. This is for Allied Assault. I will need it to work in Multiplayer.

Posted: Tue Apr 01, 2008 6:27 pm
by jv_map
Ok all clear :)

Change the line

local.gun.dmprojectile= "models/projectiles/tigercannonshell.tik"

into

local.gun dmprojectile "models/projectiles/tigercannonshell.tik"

That should cause the projectiles to do damage, I think.

For multiplayer you will have to rewrite your targeting code. I recommend just that in any case, since you are using a variable (local.i) which is never assigned a value. I'd be surprised it if worked at all :?

Done Deal

Posted: Wed Apr 02, 2008 12:44 am
by Wierdo
That did it. Now the tank delivers instant death to anybody in front of the barrel.

I will test the tank in multiplayer sometime and determine if the current code works. 8-)

Tank firing code

Posted: Sun Apr 19, 2009 11:38 pm
by Wierdo
I have tested the map in multiplayer and found the targeting to be incredibly stupid. With 2 players in game
the following occurs:
  • Player 1 stands in the open and dares the tank with player 2 at side.

    Result: Player 1 dies, tank keeps shooting player 1's corpse.
    Apon respawn, tank keeps shooting player 1.
    If player 2 gets behind something heavy, the tank kills player 1, and waits till player 1 respawns.

    Player 2 stands in open, player 1 hides behind something heavy.

    Result: Player 1 is shot at, so long as it can draw a line of sight to player 2.
    If player 2 gets too far away, tank stops shooting and keeps aim at player 1.
This must be fixed. Obviously, a tank that fires on player 1 (Host, i think) only will be easily defeated. Anybody
got a quick solution to this? :?

Re: Tank firing code

Posted: Mon Apr 20, 2009 5:59 am
by Aprop
Wierdo wrote:. Obviously, a tank that fires on player 1 (Host, i think)
Yes, its written in your script?

Code: Select all

   local.gun setAimTarget $player 

Script

Posted: Wed Apr 22, 2009 6:13 am
by Wierdo
:oops: I guess it is time to show the updated script:

Code: Select all

targeting: 

if! (isAlive self)
   end

local.index = 1 

for (local.i=1;local.i <= $player.size;local.i++)
{
local.trace = trace (self.origin + (0 0 120)) ($player[local.i].origin + (0 0 48)) 1 
if(($player[local.i].dmteam == "allies" && $player[local.i].health >= 1 && vector_within $player[local.i].origin self.origin 2500) && ((local.trace[0] == $player[local.i].origin[0]) || (local.trace[1] == $player[local.i].origin[1]) || (local.trace[2] == $player[local.i].origin[2] + 48)))
   {
      self fullstop 
      local.gun = self QueryTurretSlotEntity 0
      local.aim = randomint(local.targets.size)+1 
      local.gun setaimtarget $player[local.aim] 
      local.gun waittill ontarget
       local.gun startfiring
       wait 1
       local.gun stopfiring
       wait 5
   }
}
   local.gun setaimtarget NULL
   waitframe
goto targeting
end
The above test was ran with this current scripting setup.