Tank & Tank-barrier problem


(Genesis) #1

Hya…

I have a few questions about the tank and why the tank barrier is acting weird…
What i have managed to do is get the tank to spawn and to move when an allied player gets close, the problem is it spawns repared and it should spawn broken.
Another problem is when it hits waypoint 4 it stops (the tank barrier is behind that but it will stop anyway even when it isnt build).
Wich brings me to the tank barrier, i coppied and pasted tank barrier #2 from GoldRush, it looks fine in radiant but in-game the construction materials dont show up.
You CAN construct it if you stand on the right spot but when you do the dynamite-icon doesnt show up when your allied.

My script looks like this: (tank + tank barrier only)


//**********Tank**********
tank1
{
	//----------------------------------------------------------------------
	// The following are events that this entity is capable of triggering
	//----------------------------------------------------------------------
	spawn
	{
		// Set variables to defaults
		accum 0 set 0			// State
		accum 1 set 0			// Path state
		accum 1 bitset 0		// Set obstacle 0 as present
		accum 3 set 0			// Reset stop timer
		accum 9 set 0			// Reset script lockout counter

		// Wait for entities to spawn
		wait 100
		
		// Set initial position to the first waypoint
		followspline 0 waypoint_000 10000
		accum 2 set 1

		// Set default state (ie. tank ready)
		trigger self sound_idle
		trigger self anim_tracks_stop
		setstate tank1_smoke invisible
	}
	

	
	// Called when the entity is hurt
	pain
	{
	}
	
	
	
	// Called when the entity is destroyed
	death
	{
		// Update state bits
		accum 0 bitset 0						// Mark as broken, which mean it will stop at next waypoint
	}
	
	
	
	// Indirectly called when the entity is repaired
	rebirth
	{
		// Lock script
		trigger self script_lock
		
			// Change from broken to fixed model
			changemodel models/mapobjects/tanks_sd/churchhill.md3
	
			// Remove smoke
			setstate tank1_smoke invisible
	
			// Start
			trigger tank1_sound rebirth
			wait 500

			// Update state bits
			accum 0 bitreset 0					// Mark as not broken
		    accum 0 bitreset 4					// Mark as visually not broken
		
		// Unlock script
		trigger self script_unlock
	}
	
	
	
	// Called when a player is using the mounted MG
	mg42 mount
	{
	}
	
	
	
	// Called when a player is no longer using the mounted MG
	mg42 unmount
	{
	}
	

	
	
	
	//----------------------------------------------------------------------
	// Trigger functions
	//----------------------------------------------------------------------

	// This function is called when a player moves inside the escort zone
	trigger escort_trigger
	{
		// Check for obstacles
		trigger self check_obstacle_status

		// Update state bits and counters
		accum 0 bitset 2				// Mark as escort present
		accum 3 set 0					// Reset stop timer
		
		// Check if allowed to move
		accum 0 abort_if_bitset 0		// Abort if its broken
		accum 0 abort_if_bitset 1		// Abort if its already moving
		accum 0 abort_if_bitset 3		// Abort if an obstacle is in the way
		accum 9 abort_if_not_equal 0	// Abort if the script is currently locked
		
		// Lock script
		trigger self script_lock
		
			// Starting state
			trigger tank1_sound start
			startanimation 55 10 15 nolerp norandom
			wait 666

			// Driving state
			trigger self anim_tracks_forward
			startanimation 5 40 15 nolerp norandom

			// Wait a bit before starting to move
			wait 500
			
		// Unlock script
		trigger self script_unlock
		
		// Start movement loop
		trigger self move
	}

	
	
	// This function is called periodicly by a func_timer entity in the map.
	// Each time it checks a counter to see if the escort has been gone too
	// long. The counter is reset by the escort trigger function.
	trigger timer
	{
		// Increase counter, and if it hasn't reached 4 then abort
		accum 3 inc 1
		accum 3 abort_if_less_than 4
		
		// Update state bits
		accum 0 bitreset 2						// Mark as not escorted, which means it will stop at next waypoint

		// Need to periodicly check if the tank has been damaged
		trigger self check_death
	}
	
	


	
	//----------------------------------------------------------------------
	// Waypoint functions that checks if it can proceed to the next waypoint
	//----------------------------------------------------------------------

	// Check if its broken, and if so change to the broken state
	trigger check_death
	{
		// Check if its broken
		accum 0 abort_if_not_bitset 0		// Abort if not broken
		accum 0 abort_if_bitset 1			// Abort if its already moving
		accum 0 abort_if_bitset	4			// Abort if its already in its broken state
		accum 9 abort_if_not_equal 0		// Abort if the script is currently locked

		// Lock script
		trigger self script_lock

			// This target_kill entity will kill the func_constructible so that an engineer can repair it
			alertentity tank1_kill
		
			// Change from fixed to broken model
			changemodel models/mapobjects/tanks_sd/churchhill_broken.md3

			// Start smoking
			setstate tank1_smoke default

			// Death sound
			trigger self sound_death
			
			// Stopping state
			trigger self anim_tracks_stop
		    startanimation 45 10 15 nolerp norandom
		    wait 666

			// Stationary state
		    startanimation 0 1 15 nolerp norandom

			// Update state bits
		    accum 0 bitset 4				// Mark as visually broken state

		// Unlock script
		trigger self script_unlock
	}

	
	
	// Check if it isn't escorted, and if not then stop it
	trigger check_escort
	{
		// Check if its not escorted
		accum 0 abort_if_bitset 2			// Abort if escort is present

		// Lock script
		trigger self script_lock

			// Stop sound
			trigger tank1_sound stop

			// Stopping state
			trigger self anim_tracks_stop
		    startanimation 45 10 15 nolerp norandom
		    wait 666

			// Stationary state
		    startanimation 0 1 15 nolerp norandom
			
		// Unlock script
		trigger self script_unlock
	}


	
	// Check if there is an obstacle preventing it from continuing to the next waypoint, and if so then stop it
	trigger check_obstacle
	{
		// Update obstacle bit (with the help of the waypoint counter and some of the obstacle functions)
		trigger self check_obstacle_status
		accum 0 abort_if_not_bitset 3		// Abort if no obstacles in the way
		
		// Lock script
		trigger self script_lock

			// Stop sound
			trigger tank1_sound stop

			// Stopping state
			trigger self anim_tracks_stop
		    startanimation 45 10 15 nolerp norandom
		    wait 666

			// Stationary state
		    startanimation 0 1 15 nolerp norandom
			
		// Unlock script
		trigger self script_unlock
	}

	
	
	
	
	//----------------------------------------------------------------------
	// Obstacle functions
	//----------------------------------------------------------------------

	// Dispatching obstacle checking function
	trigger check_obstacle_status
	{
		accum 0 bitreset 3				// Mark as no obstacles in the way
		accum 2 trigger_if_equal 3 tank1 obstacle_000_check
	}


	
	// First obstacle - Checks if the obstacle is blocking the way
	trigger obstacle_000_check
	{
		accum 1 abort_if_not_bitset 0	// Abort if the obstacle has been removed
		accum 0 bitset 3				// Mark as an obstacle in the way
	}
	
	// First obstacle - Called by the death routine in another entity, once the obstacle is destroyed
	trigger obstacle_000_removed
	{
		accum 1 bitreset 0				// Mark obstacle as removed
	}

	
	
	
	
	//----------------------------------------------------------------------
	// Misc. functions
	//----------------------------------------------------------------------
	trigger script_lock {
		accum 9 inc 1
		}
	
	trigger script_unlock {
		accum 9 inc -1
		}


		
	
		
	//----------------------------------------------------------------------
	// Move functions
	//----------------------------------------------------------------------
	
	// Dispatching move function
	trigger move
	{
		// The obstacle bit is still valid because of the obstacle check done by the calling function
		accum 0 abort_if_bitset 3			// Abort if an obstacle is in the way

		// List of waypoints to go to
		accum 2 trigger_if_equal 1 tank1 move_to_001
		accum 2 trigger_if_equal 2 tank1 move_to_002
		accum 2 trigger_if_equal 3 tank1 move_to_003
		accum 2 trigger_if_equal 4 tank1 move_to_004
		accum 2 trigger_if_equal 5 tank1 move_to_005
		accum 2 trigger_if_equal 6 tank1 move_to_006
		accum 2 trigger_if_equal 7 tank1 move_to_007
	}


	
	// Called at the end of each move. If it passes some checks the movement is repeated
	trigger move_increment
	{
		accum 2 inc 1						// Increment waypoint counter

		// Check if its ok to proceed to the next waypoint
		trigger self check_death
		trigger self check_escort
		trigger self check_obstacle

		// This loop is used so that the tank can immediately advance after completing the move
		trigger self move
	}

	
	
	// Move to waypoint 001
	trigger move_to_001
	{
		accum 0 bitset 1			// Mark as moving
		followspline 0 waypoint_001 80 wait length -64
		accum 0 bitreset 1			// Mark as not moving
		trigger self move_increment
	}

	// Move to waypoint 002
	trigger move_to_002
	{
		accum 0 bitset 1			// Mark as moving
		followspline 0 waypoint_002 80 wait length -64
		accum 0 bitreset 1			// Mark as not moving
		trigger self move_increment
	}

	// Move to waypoint 003
	trigger move_to_003
	{
		accum 0 bitset 1			// Mark as moving
		followspline 0 waypoint_003 80 wait length -64
		accum 0 bitreset 1			// Mark as not moving

		// If there is a need to do something after it passes an obstacle then this is the place to do it.
		// Ex. hiding func_constructible for the obstacle or voice overs

		trigger self move_increment
	}

	// Move to waypoint 004
	trigger move_to_004
	{
		accum 0 bitset 1			// Mark as moving
		followspline 0 waypoint_004 80 wait length -64
		accum 0 bitreset 1			// Mark as not moving
		trigger self move_increment
	}

	// Move to waypoint 005
	trigger move_to_005
	{
		accum 0 bitset 1			// Mark as moving
		followspline 0 waypoint_005 80 wait length -64
		accum 0 bitreset 1			// Mark as not moving

		// Lock script
		trigger self script_lock

			// Stop sound
			trigger tank1_sound stop

			// Stopping state
			trigger self anim_tracks_stop
		    startanimation 45 10 15 nolerp norandom
		    wait 666

			// Stationary state
		    startanimation 0 1 15 nolerp norandom

		    // Wait a little until starting the fireing sequence
		    wait 900
			
			// Manually increment waypoint counter
			accum 2 inc 1
			
			// This turret function will unlock the script when its done
			trigger tank1_turret fire_at_target_1
	}

	// Move to waypoint 006
	trigger move_to_006
	{
		accum 0 bitset 1			// Mark as moving
		followspline 0 waypoint_006 80 wait length -64
		accum 0 bitreset 1			// Mark as not moving
		trigger self move_increment
	}

	// Move to waypoint 007
	trigger move_to_007
	{
		accum 0 bitset 1			// Mark as moving
		followspline 0 waypoint_007 80 wait length -64
		accum 0 bitreset 1			// Mark as not moving
		
		// If you want waypoints to loop, this is the place to reset the waypoint counter
		// Make sure that the last waypoint targets waypoint_001 to loop correctly
		accum 2 set 0				// Make the waypoints loop around

		trigger self move_increment
	}

	
	
	
	
	//----------------------------------------------------------------------
	// Tank sounds
	//----------------------------------------------------------------------
	trigger sound_idle
	{
		stopsound
		playsound sound/vehicles/tank/tank_idle.wav looping volume 512
	}
	
	trigger sound_start
	{
		stopsound
		playsound sound/vehicles/tank/tank_revup.wav volume 196
	}
	
	trigger sound_move
	{
		stopsound
		playsound sound/vehicles/tank/tank_move.wav looping volume 512
	}
	
	trigger sound_stop
	{
		stopsound
		playsound sound/vehicles/tank/tank_revdown.wav volume 196
	}
	
	trigger sound_death
	{
		stopsound
		playsound sound/vehicles/tank/tank_stop.wav volume 256
	}
	
	trigger sound_rebirth
	{
		stopsound
		playsound sound/vehicles/tank/tank_start.wav volume 196
	}




	
	//----------------------------------------------------------------------
	// Tank animations
	//----------------------------------------------------------------------
	trigger anim_tracks_forward
	{
		remapshader models/mapobjects/tanks_sd/bits_r models/mapobjects/tanks_sd/bits_forward
		remapshader models/mapobjects/tanks_sd/wheel_r models/mapobjects/tanks_sd/wheel_forward
		remapshader models/mapobjects/tanks_sd/bits_l models/mapobjects/tanks_sd/bits_forward
		remapshader models/mapobjects/tanks_sd/wheel_l models/mapobjects/tanks_sd/wheel_forward
		remapshaderflush
	}
	
	trigger anim_tracks_turningleft
	{
		remapshader models/mapobjects/tanks_sd/bits_r models/mapobjects/tanks_sd/bits_forward
		remapshader models/mapobjects/tanks_sd/wheel_r models/mapobjects/tanks_sd/wheel_forward
		remapshader models/mapobjects/tanks_sd/bits_l models/mapobjects/tanks_sd/bits_backward
		remapshader models/mapobjects/tanks_sd/wheel_l models/mapobjects/tanks_sd/wheel_backward
		remapshaderflush
	}
	
	trigger anim_tracks_turningright
	{
		remapshader models/mapobjects/tanks_sd/bits_r models/mapobjects/tanks_sd/bits_backward
		remapshader models/mapobjects/tanks_sd/wheel_r models/mapobjects/tanks_sd/wheel_backward
		remapshader models/mapobjects/tanks_sd/bits_l models/mapobjects/tanks_sd/bits_forward
		remapshader models/mapobjects/tanks_sd/wheel_l models/mapobjects/tanks_sd/wheel_forward
		remapshaderflush
	}
	
	trigger anim_tracks_stop
	{
		remapshader models/mapobjects/tanks_sd/bits_r models/mapobjects/tanks_sd/bits_r
		remapshader models/mapobjects/tanks_sd/wheel_r models/mapobjects/tanks_sd/wheel_r
		remapshader models/mapobjects/tanks_sd/bits_l models/mapobjects/tanks_sd/bits_l
		remapshader models/mapobjects/tanks_sd/wheel_l models/mapobjects/tanks_sd/wheel_l
		remapshaderflush
	}

	trigger anim_fire_start
	{
		startanimation 67 8 10 nolerp norandom
	}
	
	trigger anim_fire_stop
	{
		startanimation 0 1 15 nolerp norandom
	}
}





//======================================================================
// Tank turret
//======================================================================

tank1_turret
{
	spawn
	{
		// Wait for host entity to spawn
		wait 100
		
		// Attaches itself to a tag on the script_mover
		attachtotag tank1 tag_turret
	}


	
	//----------------------------------------------------------------------
	// Turret sequence
	//----------------------------------------------------------------------
	trigger fire_at_target_1
	{
		// Wait a little until starting sequence
		wait 1000

		// Turn turret towards target
		trigger tank1_sound turret_turn_start
		faceangles 0 60 0 4000						// Adjust angles to match the target
		trigger tank1_sound turret_turn_stop
		wait 500

		// Fire at target
		trigger tank1_sound turret_fire
		trigger tank1 anim_fire_start
		setstate tank1_flash default
		wait 50
		setstate tank1_flash invisible
		wait 200
		trigger tank1 anim_fire_stop

		// BUG: Apparently the entitys scriptblock is completely removed after its blown up the first time
		trigger target_000 blow_up
		wait 1000

		// Turn turret back to target
		trigger tank1_sound turret_turn_start
		faceangles 0 0 0 4000
		trigger tank1_sound turret_turn_stop
			
		// Wait a little until its ready to move again
		wait 500

		// Unlock script
		trigger tank1 script_unlock
	}


		
	//----------------------------------------------------------------------
	// Turret sounds
	//----------------------------------------------------------------------
	trigger sound_fire
	{
		stopsound
		playsound sound/vehicles/tank/tank_fire.wav volume 300
	}

	trigger sound_turn_start
	{
		stopsound
		playsound sound/vehicles/tank/turret_spin.wav looping volume 127
	}

	trigger sound_turn_stop
	{
		stopsound
		playsound sound/vehicles/tank/turret_end.wav volume 96
	}
}





//======================================================================
// The following are related entities which are attached because they need to follow the script_mover
//======================================================================

tank1_enabler_trigger
{
	spawn
	{
		// Wait for host entity to spawn
		wait 100
		
		// Attaches itself to a tag on the script_mover
		attachtotag tank1 tag_turret
	}
}



tank1_flash
{
	spawn
	{
		// Wait for host entity to spawn
		wait 200
		
		// Attaches itself to a tag on the script_mover
		attachtotag tank1_turret tag_flash
		
		// Hides the flash
		setstate tank1_flash invisible
	}
}



tank1_smoke
{
	spawn
	{
		// Wait for host entity to spawn
		wait 100
		
		// Attaches itself to a tag on the script_mover
		attachtotag tank1 tag_turret
		
		// Turn off smoking
		alertentity tank1_smoke
	}
}



tank1_toi
{
	spawn
	{
		// Wait for host entity to spawn
		wait 100
		
		// Attaches itself to a tag on the script_mover
		attachtotag tank1 tag_turret
	}
}





//======================================================================
// The following are the remaining entities
//======================================================================

tank1_construct
{
	spawn
	{
		// Needed for the icon to reappear correctly on the command map
		constructible_class 2
	}
	
	// Called when the repairs are starting
	buildstart final
	{
	}

	// Called when the repairs have failed
	decayed final
	{
	}
	
	// Called when the repairs have failed
	failed
	{
	}
		
	// Called when the repairs are done
	built final
	{
		// Resurrect the entity. This fills up its health and trigger the ::rebirth function
		alertentity tank1
	}
}

tank1_disabler
{
	spawn
	{
	}

	trigger run
	{
		// Call the function which controls the escort timeout
		trigger tank1 timer
	}
}

tank1_enabler
{
	spawn
	{
	}

	trigger run
	{
		// Call the function which handles the escort
		trigger tank1 escort_trigger
	}
}

tank1_kill
{
	spawn
	{
	}
}

tank1_timer
{
	spawn
	{
	}
}






//======================================================================
// This block contains sound redirectors. Since commands are executed in order
// the only way to have multiple waits at the same time is to play them through another scriptblock
//======================================================================

tank1_sound
{
	spawn
	{
	}
	
	trigger start
	{
		trigger tank1 sound_start
		wait 3400
		trigger tank1 sound_move
	}
	
	trigger stop
	{
		trigger tank1 sound_stop
		wait 1400
		trigger tank1 sound_idle
	}
	
	trigger rebirth
	{
		trigger tank1 sound_rebirth
		wait 1400
		trigger tank1 sound_idle
	}

	trigger turret_fire
	{
		trigger tank1_turret sound_fire
	}

	trigger turret_turn_start
	{
		trigger tank1_turret sound_turn_start
	}

	trigger turret_turn_stop
	{
		trigger tank1_turret sound_turn_stop
	}
}











//======================================================================
// OBSTACLES
//======================================================================

obstacle_000
{
	spawn
	{
	}
	
	pain
	{
	}
	
	death
	{
		// Notify relevant parts of the script that the obstacle has been destroyed
		trigger tank1 obstacle_000_removed
	}
}











//======================================================================
// TARGETS
//======================================================================
//
// Slot	Used for
// ====	========
// 0	State:
//		- Bit 0: Broken						0 = No		1 = Yes
//
target_000
{
	spawn
	{
		// Reset state bits
		accum 0 bitset 0					// Mark as not blown up
	}
	
	pain
	{
	}
	
	// If you need to notify other parts of the script that the target has been removed, then do it here.
	death
	{
	}
	
	// Called when the entity should be destroyed
	trigger blow_up
	{
		// Check if we have already been blown up
		accum 0 abort_if_not_bitset 0		// Abort if already blown up
		
		// Update state bits
		accum 0 bitreset 0					// Mark as blown up

		// Blow up
		alertentity target_000
	}
}

//*******Tank barrier*********

defense2
{
	spawn
	{
		wait 400
		trigger defense2 setup

		constructible_class 3
	}

	trigger setup
	{
		setstate defense2_materials default
		setstate defense2_materials_clip default
		setstate defense2_flag default


		setstate defense2_teeth invisible
	}

	buildstart final
	{
		setstate defense2_materials default
		setstate defense2_materials_clip default
		setstate defense2_flag default


		setstate defense2_teeth underconstruction
	}

	built final
	{
		setstate defense2_materials invisible
		setstate defense2_materials_clip invisible
		setstate defense2_flag invisible


		setstate defense2_teeth default

		trigger tank disable_stage4

		wm_announce "Tank Barrier #2 has been constructed."

		// *----------------------------------- vo ------------------------------------------*
		wm_teamvoiceannounce 0 "goldrush_axis_tankbar_constructed"

		wm_removeteamvoiceannounce 0 "goldrush_axis_tankbar_construct"
		wm_removeteamvoiceannounce 0 "goldrush_axis_tankbars_construct"
		// *---------------------------------------------------------------------------------*
	}

	decayed final
	{
		setstate defense2_materials default
		setstate defense2_materials_clip default
		setstate defense2_flag default


		setstate defense2_teeth invisible
	}

	death
	{
		setstate defense2_materials default
		setstate defense2_materials_clip default
		setstate defense2_flag default


		setstate defense2_teeth invisible

		trigger tank enable_stage4

		wm_announce "Tank Barrier #2 has been destroyed."

		// *----------------------------------- vo ------------------------------------------*
		wm_addteamvoiceannounce 0 "goldrush_axis_tankbar_construct"

		wm_teamvoiceannounce 0 "goldrush_axis_tankbar_destroyed"

		wm_teamvoiceannounce 1 "goldrush_allies_tankbar_destroyed"
		// *---------------------------------------------------------------------------------*
	}

	trigger remove
	{
		setstate defense2_toi invisible
		setstate defense2_materials invisible
		setstate defense2_materials_clip invisible
		setstate defense2_flag invisible
		setstate defense2_teeth invisible

		// *----------------------------------- vo ------------------------------------------*
		wm_removeteamvoiceannounce 0 "goldrush_axis_tankbar_construct"
		wm_removeteamvoiceannounce 0 "goldrush_axis_tankbars_construct"

		wm_removeteamvoiceannounce 1 "goldrush_allies_tankbar_destroy"
		wm_removeteamvoiceannounce 1 "goldrush_allies_tankbars_destroy"
		// *---------------------------------------------------------------------------------*

		remove
	}
}

Thnx in advance


(Malverik) #2

this smells like Chruker’s script for the tank… and unchanged!

to have it start broken, i guess you would need to put these in the spawn of the tank1_construct:

kill tank1
alertentity tank1_kill

and remove the line “alertentity tank1_smoke” in the spawn of tank1_smoke

for the barrier you need to tell the tank he cannot pass when it is built, and that hhe can pass when it is destroyed
so in the death part of defense2 add the line

trigger tank1 obstacle_000_removed 

since your barrier is rebuildable, you are missing a routine to signal the barrier has been built. So in the script for tank1, add a trigger like this one:


trigger obstacle_000_built 
   { 
      accum 1 bitset 0         
   } 

and add this line in the “built final” part of the defense2

trigger tank1 obstacle_000_built

and finally, because all that is copy pasted, there is a load of cleanup to do!
You’ll notice that there is a little bug with this Churchill (but that makes the script much more simple), is you stand on the turret while the tank is moving you will fall off.

Good luck!


(Genesis) #3

i did all that but when i load the map up in ET it says:

G_Scripting: allertentity cannot find targetname “tank1_kill”


(nUllSkillZ) #4

Haven’t followed this thread.
And I haven’t done anything with a moving tank /tank barrier so far.

But this error tells you that you haven’t got an entity with targetname “tank1_kill” in your map which is called by the script.


(Genesis) #5

well… i do have it ectually…

its linked to an origin brush and thats linked to the scipt mover… ive tried changing it to tank_kill but that doesnt work either… checks spelling of targetname
nope thats spelled correct…


(Genesis) #6

i got it sorted now… it spawns broken, allies fix, it drives and drives… until the tank barrier.
it will stop no matter what, even when the barrier isnt build.
when i go and build the barrier as axis then blow it up as allies, the tank will go on…

i really dont get it…


(nUllSkillZ) #7

I think SteelRat has had the same problems.
He has written a scriptix for this map.
So you should have a look at this scriptfix.

Edit:

I haven’t mentioned the mapname :banghead: :
Xposed