Tank Problem

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
Gen Cobra
Major General
Posts: 739
Joined: Tue Jan 28, 2003 4:26 pm

Tank Problem

Post by Gen Cobra »

Well the map Stalingrad is all done. Everything turned out great but my tank doesnt do damage to me when it fires. I cant hear it move and I would like it to target just the allies. Does anyone know what the prob is?

Code: Select all

// STALINGRAD BETA TDM FFA RB
// BY GEN COBRA (Chris Murchison)

main: 

setcvar "g_obj_alliedtext1" " STALINGRAD" 

setcvar "g_obj_axistext1" " GEN COBRA"



level.script="maps/dm/stalingrad_beta.scr"		

setcvar "g_scoreboardpic" "textures/mohmenu/dmloading/stalingrad_beta2.tga"
	local.master = spawn ScriptMaster 

	local.master aliascache leadinmp1 sound/weapons/explo/Exp_LeadIn_06.wav soundparms 0.8 0.2 0.7 0.5 160 3000 auto loaded maps "m obj dm train" 
	local.master aliascache leadinmp2 sound/weapons/explo/Exp_LeadIn_07.wav soundparms 0.8 0.2 0.7 0.5 160 3000 auto loaded maps "m obj dm train" 
	local.master aliascache leadinmp3 sound/weapons/explo/Exp_LeadIn_08.wav soundparms 0.8 0.2 0.7 0.5 160 3000 auto loaded maps "m obj dm train" 
	local.master aliascache leadinmp4 sound/weapons/explo/Exp_LeadIn_09.wav soundparms 0.8 0.2 0.7 0.5 160 3000 auto loaded maps "m obj dm train" 
	local.master aliascache leadinmp5 sound/weapons/explo/Exp_LeadIn_10.wav soundparms 0.8 0.2 0.7 0.5 160 3000 auto loaded maps "m obj dm train" 
	local.master aliascache leadinmp6 sound/weapons/explo/Exp_LeadIn_11.wav soundparms 0.8 0.2 0.7 0.5 160 3000 auto loaded maps "m obj dm train" 
	local.master aliascache leadinmp7 sound/weapons/explo/Exp_LeadIn_12.wav soundparms 0.8 0.2 0.7 0.5 160 3000 auto loaded maps "m obj dm train" 
	local.master aliascache leadinmp8 sound/weapons/explo/Exp_LeadIn_13.wav soundparms 0.8 0.2 0.7 0.5 160 3000 auto loaded maps "m obj dm train"
	local.master aliascache higgins_explode sound/weapons/explo/Explo_MetalMed1.wav soundparms 1.5 0.0 1.0 0.0 500 5000 weapon loaded maps "m obj dm train" 

exec global/ambient.scr m5l1b music
exec global/exploder.scr
exec global/bomber.scr
exec global/door_locked.scr::lock
// call additional stuff for playing this map round based is needed
if(level.roundbased)
thread roundbasedthread

// call additional stuff for playing this map round based is needed
	if(level.roundbased)
		thread roundbasedthread
		
	level waitTill prespawn

	//*** Precache Dm Stuff
	
exec global/DMprecache.scr
	
level.script = maps/dm/stalingrad_beta.scr
exec ubersound/ubersound.scr

thread random_explode_start

	level waittill spawn


end
StartTank:

	// Initialisation of the tank parameters.
	$TankPanzer1 waitthread InitTank
	
	// Put the tank health on the player screen.
	$TankPanzer1 thread TankHealthLoop
	
	// Make the tank move along the chosen path.
	$TankPanzer1 thread MoveTank
	
	// Destruction of the tank.
	$TankPanzer1 thread TankDeath

end





//*************************************************************************************//
// Definition of the threads that are call from the scr.			       //
//*************************************************************************************//


InitTank:

	
	self.health = 1000				// Set the initial health of the tank.
	self removeondeath 0				// Make sure the tank doesn't desappear when it is destroy.
	self lock					// Make sure the player can't use the tank.
	$TankPanzer1 setcollisionentity self.target	// Set the tank collision mask
	
	// Set the tank's immunities.
	self immune bullet
	self immune fast_bullet
	self immune grenade
	self immune bash
	
end


TankHealthLoop:

	local.StartHealth = self.health
	local.LastHealth = self.health	

	while (isAlive self)
	{
		waitframe

		if !(isAlive self)
			end

		if (self.health < local.LastHealth)
		{
			local.HealthFraction = (self.health / local.StartHealth) * 100
			local.HealthFractionInt = int local.HealthFraction
			iprintlnbold_noloc (loc_convert_string "PANZER TANK: ") local.HealthFractionInt (loc_convert_string " percent")
			local.LastHealth = self.health
		}		
	}
	
end


MoveTank:

	local.Path = $TankPanzer1_Path1		// Set the tank path.
	local.TankSpeed = 7			// Set the tank speed value.
	local.Acceleration = 30			// Set the tank acceleration value.
	local.ReachDistance = 200		// Set the tank reaching distance value.
	local.LookAhead = 64			// Set the tank look ahead value
	
	// Move the tank along the path.
	self drive local.Path local.TankSpeed local.Acceleration local.ReachDistance local.LookAhead
	
	self waitTill drive			// Wait until the tank is at end of path.
	self stop				// Stop the tank.
	
	self thread TankFire			// Call the targeting and firing thread.	

end


TankFire:

	// While the tank is still alive.
	while(isAlive self)
	{
	
		// Get out of the thread if the player is dead.
		if !(isAlive $player)
			end
				
		// Initialisation of the main gun.
		local.gun1 = self QueryTurretSlotEntity 0
		
		// Set the main gun turn speed
		local.gun1 TurnSpeed 15
		
		// Aim the main gun at the player and wait until it is on the target.
		local.gun1 setAimTarget $player		
		local.gun1 waittill ontarget
		
		// Get out of the thread if the tank is destroy.
		if !(isAlive self)
			end
			
		// Check if the line of sight is clear.
		local.trace = trace (self.origin + (0 0 120)) ($player.origin + (0 0 48)) 1
		if ((local.trace[0] != $player.origin[0]) || (local.trace[1] != $player.origin[1]) || (local.trace[2] != $player.origin[2] + 48))
			wait(1)
			
		// Check if the player is not to close to the tank.				
		else if (vector_within $player.origin self.origin 384)
			wait(1)		
		
		// Check if the player is not to far from the tank.
		else if (!(vector_within $player.origin self.origin 2500))
			wait(1)		
		
		// If the tank can fire at the player
		else
		{
			// Make the main gun fire a shot at the target.
			local.gun1 startfiring
			wait(1)
			local.gun1 stopFiring
			
			wait(5)			
		}
		
	}
	
end


TankDeath:

	// Wait until the tank is dead.
	self waittill death	

	// Make sure the tank is visible.
	self show	
	
	// Make sure the tank is not moving.
	self stop
	
	// Initialisation of the 2 guns (main gun and mg).
	local.gun1 = self QueryTurretSlotEntity 0
	local.gun2 = self QueryTurretSlotEntity 1

	// Make sure the main gun isn't firing.
	local.gun1 stopfiring

	// Delete the main gun.
	if (local.gun1)
	{
		self DetachTurretSlot 0
		local.gun1 remove
	}

	// Delete the mg.
	if (local.gun2)
	{
		self DetachTurretSlot 1
		local.gun2 remove
	}
	
	// Play the sound for the explosion.
	self playsound explode_tank

	// Spawn the tank explosion.
	local.Exp = spawn "fx/fx_tank_explosion.tik"
	local.Exp.origin = self.origin
	local.Exp anim start

	// Shake the ground hard and make a damage zone for the tank destruction blast.
	exec global/earthquake.scr .23 4 0 0
	radiusdamage self.origin 200 200
	
	// Set the dead thank 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
	
	// Spawn the destroy tank model.
	local.damaged = spawn script_model model models/vehicles/tigertank_d.tik
	local.damaged.origin = self.origin
	local.damaged.angles = self.angles
	
	// Remove the non-destroy tank model.
	self remove
	local.Exp remove
	
end

// --------------------------------------------
//  Random Explosions
// --------------------------------------------

random_explode_start:

	thread random_explode1
	thread random_explode2
	thread random_explode3
	thread random_explode4
	$random_explode4_smoke anim start
	$player playsound warn_player_arty_cover

end
	
random_explode1:
 
	wait (randomfloat 13 + 16) 
	$random_explode1_origin playsound leadinmp 
	wait 1 
	$random_explode1 anim start 
	radiusdamage $random_explode1_origin 256 384 
	goto random_explode1
 
end 

random_explode2:
 
	wait (randomfloat 7 + 14) 
	$random_explode2_origin playsound leadinmp 
	wait 1 
	$random_explode2 anim start
	radiusdamage $random_explode2_origin 256 384 
	goto random_explode2
 
end 

random_explode3:
 
	wait (randomfloat 5 + 8) 
	$random_explode3_origin playsound leadinmp 
	wait 1
	$random_explode3_origin playsound higgins_explode 
	$random_explode3 anim start 
	radiusdamage $random_explode3_origin 256 512 
	goto random_explode3
 
end 

random_explode4:
 
	wait (randomfloat 8 + 12) 
	$random_explode4_origin playsound leadinmp 
	wait 1 
	$random_explode4 anim start 
	radiusdamage $random_explode4_origin 256 480 
	goto random_explode4
 
end 
Image
User avatar
Gen Cobra
Major General
Posts: 739
Joined: Tue Jan 28, 2003 4:26 pm

Post by Gen Cobra »

Anyone?
Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

Well I found a few things if !(isAlive $player) in multiplayer there are more than one player this is for single player .
same with the setaimtarget statement etc .

also you need to add a dmprojectile for mohaa not needed in spearhead

$TankPanzer1.dmprojectile= "models/projectiles/tigercannonshell.tik"

Try this out

Code: Select all


TankFire: 

   // While the tank is still alive. 
   while(isAlive self) 
   { 
             
      // Initialisation of the main gun. 
      local.gun1 = self QueryTurretSlotEntity 0 
       
      // Set the main gun turn speed 
      local.gun1 TurnSpeed 15 
              
      // Get out of the thread if the tank is destroy. 
      if !(isAlive self) 
         end 
//**********************************************************************
//         find a allies target to shoot at
//**********************************************************************
local.index = 1

for(local.i=1;local.i <= $player.size;local.i++)
{

if($player[local.i].dmteam = "allies")
{
      // Check if the line of sight is clear and that the players are not too close or far from tank. 
      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)) 
	{
		if !(vector_within $player[local.i].origin self.origin 384)// Check if the player is not too close to the tank.
		{ 
			if (!(vector_within $player[local.i].origin self.origin 2500))// Check if the player is not to far from the tank.
			{ 
			local.targets[local.index]= $player[local.i] // add player to the list
			local.index++
			}
		}
	}
}
}
//********** pick a target at random from the list****************

// Aim the main gun at the player and wait until it is on the target. 

local.aim = randomint(local.targets.size)+1
local.gun1 setaimtarget $player[local.aim]
local.gun1 waittill ontarget
local.gun1 anim fire
local.targets delete 
 
end 
User avatar
Gen Cobra
Major General
Posts: 739
Joined: Tue Jan 28, 2003 4:26 pm

Post by Gen Cobra »

Well I tried replacing the tankFire part of the thread with that and the script just failed to work.

And I dont fully understand the first part about the projectile. I suck at scripting and I would really like this tank in the final but Ill take it out if this just becomes a massive hassle. Thanks for helping. Maybe im not fully understanding.
Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

I just looked at it again looks like I forgot a } just before the word end and maybe since it is a while loop you should put a wait in there to avoid a infinate loop in thread error .

add this to the bottom of the thread

waitframe
}
end
User avatar
Gen Cobra
Major General
Posts: 739
Joined: Tue Jan 28, 2003 4:26 pm

Post by Gen Cobra »

Thanks a lot for your help. Im not as talented as some of you at scripting. The tank lagged an otherwise fps PERFECT map. Yeah the game just seized when I did that. I did some ajustments. It runs like a hooker with your wallet.

Im gonna let sumo do the tank for the bot version.
Image
Post Reply