Thread: Train

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Yamato's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    839
    Reputation
    13
    Thanks
    154
    My Mood
    Amazed

    Train

    Hello

    I have been trying something in this last 2 days, and is the _train.gsc in Skidrow.

    Is it posible to make the train??? , it could be awesome. I thought of a noobie way, if nobody knows anything, IŽll try with it. :P


    Code:
    #include maps\mp\_utility;
    #include common_scripts\utility;
    
    SOUND_DELAY_MIN = 0.1;
    SOUND_DELAY_MAX = 1;
    
    init()
    {
    	train = getEnt( "the_l_train", "targetname" );
    	assertex( isdefined( train ), "Calling to setup train in map without having the train in map! [targetname: the_l_train]" );
    	train thread train_setup();
    }
    
    train_setup()
    {
    	precacheItem( "train_mp" );	
    	
    	delay_until_first_train = 2;
    	Units_per_second = 1200;// train speed
    	train_cars = 24;
    	distance_between_cars = 368;
    	eq_radius = 900;// 	radius of earthquakes broadcast from the train tracks
    
    	min_time_between_trains = 100;
    	max_time_between_trains = 200;
    
    	lead_in_dist = 8000;
    	lead_out_dist = 4000;
    
    	train_car_sound_interval = 3;
    	
    	flag_init( "train_running" );
    
    	yaw = self.angles[ 1 ];
    	while ( yaw >= 90 )
    	{
    		yaw -= 90;
    	}
    	assertEx( yaw == 0, "Trains must have a yaw of 0, 90, 180, or 270 currently( for collision purposes )" );
    
    	wheels = getentarray( "wheel", "targetname" );
    	wheel_model = wheels[ 0 ].model;
    	wheel_offset = [];
    	foreach ( wheel in wheels )
    	{
    		wheel linkto( self );
    		wheel.offset = self.origin - wheel.origin;
    	}
    
    	// ****************
    	// Set up the other cars
    	// ****************	
    	forward = anglestoforward( self.angles );
    	forward *= distance_between_cars;
    	car_separation_vec = forward;
    	cars = [];
    	for ( i = 0; i < train_cars - 1; i++ )// - 1 car self is the lead car
    	{
    		car = spawn( "script_model", self.origin - car_separation_vec );
    		car.angles = self.angles;
    		car setmodel( self.model );
    		car linkto( self );
    		car_separation_vec += forward;
    		cars[ cars.size ] = car;
    		car.wheels = [];
    
    		foreach ( owner_wheel in wheels )
    		{
    			wheel = spawn( "script_model", car.origin + owner_wheel.offset );
    			wheel setmodel( wheel_model );
    			wheel.angles = owner_wheel.angles;
    			wheel linkto( car );
    			car.wheels[ car.wheels.size ] = wheel;
    		}
    	}
    
    	// ****************
    	// The start and end points for the train, set from script origins
    	// ****************	
    	start = getent( self.target, "targetname" );
    	start.origin = ( start.origin[ 0 ], start.origin[ 1 ], self.origin[ 2 ] );
    	
    	end = getent( start.target, "targetname" );
    	end.origin = ( end.origin[ 0 ], end.origin[ 1 ], self.origin[ 2 ] );
    	forward = anglestoforward( self.angles );
    	start.origin = start.origin - forward * lead_in_dist;
    	end.origin = end.origin + forward * lead_out_dist;
    
    	track_dist = distance( start.origin, end.origin );
    	travel_dist = track_dist + train_cars * distance_between_cars;
    	travel_time = travel_dist / Units_per_second;
    	track_time = track_dist / Units_per_second;
    	full_train_time = train_cars * distance_between_cars / Units_per_second;
    
    
    
    	// ****************
    	// set up the earthquakes that play to make the train tracks rattle
    	// ****************	
    	distance_between_eq_orgs = eq_radius * 0.5;
    	eq_count = track_dist / distance_between_eq_orgs;
    
    	// the amount of time it takes for all the EQs to start before the train moves in
    	delay_between_eqs = track_time / eq_count;
    	travel_time_segment = track_time / eq_count;
    	min_time_between_trains -= track_time;
    	if ( min_time_between_trains < 0.1 )
    		min_time_between_trains = 0.1;
    	max_time_between_trains -= track_time;
    	if ( max_time_between_trains < min_time_between_trains )
    		max_time_between_trains = min_time_between_trains + 0.1;
    
    	eq_points = [];
    	for ( i = 0; i < eq_count; i++ )
    	{
    		progress = i / eq_count;
    		eq_points[ i ] = start.origin * ( 1 - progress ) + end.origin * progress;
    	}
    
    	self.cars = cars;
    	self.wheels = wheels;
    
    	self.origin = start.origin;
    	wait( delay_until_first_train );
    	
    	for ( ;; )
    	{
    		hide_trains();
    		wait( 0.05 );
    		self.origin = start.origin;
    
    
    		// First there is a lead in of small EQs to shake the platform
    		timer = gettime();
    		for ( i = 0; i < eq_count; i++ )
    		{
    			thread train_eq( eq_points[ i ], eq_radius, track_time, full_train_time );
    			wait( delay_between_eqs );
    		}
    
    		show_trains();
    		thread train_kills_players( train_cars, distance_between_cars );
    		thread train_spawns_dust();
    
    		// Now the train goes by
    		self moveto( end.origin + car_separation_vec, travel_time );
    		train_play_sounds( train_car_sound_interval );
    		
    		wait( travel_time );
    		hide_trains();
    
    		train_stop_sounds( train_car_sound_interval );
    
    		flag_set( "train_running" );
    		self notify( "train_stops_killing_players" );
    		// Wait until the next train
    		wait( randomfloatrange( min_time_between_trains, max_time_between_trains ) );
    	}
    }
    
    train_play_sound_delayed( alias )
    {
    	wait( randomfloatrange( SOUND_DELAY_MIN, SOUND_DELAY_MAX ) );	
    	self playLoopSound( alias );
    }
    
    train_play_sounds( max )
    {	
    	self thread train_play_sound_delayed( "veh_train_eng_dist1_loop" );
    	self thread train_play_sound_delayed( "veh_train_eng_dist2_loop" );
    	self thread train_play_sound_delayed( "veh_train_eng_mid_loop" );
    	self thread train_play_sound_delayed( "veh_train_eng_close1_loop" );
    	self thread train_play_sound_delayed( "veh_train_eng_close2_loop" );
    	
    	// dont play sounds on every car
    	count = 0;
    	for ( i = 0; i < self.cars.size; i++ )
    	{
    		count++;
    		if ( count < max )
    			continue;
    		count = 0;
    	
    		self.cars[ i ] thread train_play_sound_delayed( "veh_train_car_dist_loop" );
    		self.cars[ i ] thread train_play_sound_delayed( "veh_train_car_mid_loop" );
    		self.cars[ i ] thread train_play_sound_delayed( "veh_train_car_close_loop" );
    	}
    }
    
    train_stop_sounds( max )
    {
    	self stopLoopSound( "veh_train_eng_dist1_loop" );   
    	self stopLoopSound( "veh_train_eng_dist2_loop" );   
    	self stopLoopSound( "veh_train_eng_mid_loop" );     
    	self stopLoopSound( "veh_train_eng_close1_loop" );  
    	self stopLoopSound( "veh_train_eng_close2_loop" );  
    
    	count = 0;
    	for ( i = 0; i < self.cars.size; i++ )
    	{
    		count++;
    		if ( count < max )
    			continue;
    		count = 0;
    	
    		self.cars[ i ] stopLoopSound( "veh_train_car_dist_loop" );
    		self.cars[ i ] stopLoopSound( "veh_train_car_mid_loop" );
    		self.cars[ i ] stopLoopSound( "veh_train_car_close_loop" );
    	}
    }
    
    hide_trains()
    {
    	// Hide the train while it warps to position
    	self hide();
    	foreach ( wheel in self.wheels )
    	{
    		wheel hide();
    	}
    	foreach ( car in self.cars )
    	{
    		car hide();
    		foreach ( wheel in car.wheels )
    		{
    			wheel hide();
    		}
    	}
    }
    
    show_trains()
    {
    	// show the train while it warps to position
    	self show();
    	foreach ( wheel in self.wheels )
    	{
    		wheel show();
    	}
    	foreach ( car in self.cars )
    	{
    		car show();
    		foreach ( wheel in car.wheels )
    		{
    			wheel show();
    		}
    	}
    }
    
    train_spawns_dust()
    {
    	if ( !isdefined( level._effect[ "train_dust" ] ) )
    		return;
    		
    	range = 40;
    	self endon( "train_stops_killing_players" );
    	
    	for ( ;; )
    	{
    		/*
    		for ( i = 0; i < 10; i ++ )
    		{
    			x = randomfloatrange( self.min_x, self.max_x );
    			y = randomfloatrange( self.min_y, self.max_y );
    			PlayFX( level._effect[ "train_dust" ], ( x, y, self.origin[ 2 ] - 30 ) );
    		}
    		*/
    
    		count = randomintrange( 1, 3 ); // which means 1 to 2 fx per frame
    		for ( i = 0; i < count; i ++ )
    		{
    			x = randomfloatrange( self.min_x - range, self.max_x + range );
    			y = randomfloatrange( self.min_y - range, self.max_y + range );
    			PlayFX( level._effect[ "train_dust_linger" ], ( x, y, self.origin[ 2 ] - 10 ) );
    		}
    		wait( 0.05 );
    	}
    }
    
    train_kills_players( train_cars, distance_between_cars )
    {
    	// find the extents of the train, presuming it is going straight n/s/e/w and then test vs player origins to see
    	// if they should be run over
    	train_width = 68;
    	self endon( "train_stops_killing_players" );
    
    	forward = anglestoforward( self.angles );
    	right = anglestoright( self.angles );
    	full_car_vec = forward * distance_between_cars;
    	half_car_vec = full_car_vec * 0.5;
    	train_width_vec = right * train_width;
    
    	sides = [];
    	sides[ "front" ] = self.origin + half_car_vec;
    	sides[ "rear" ] = self.origin + train_cars * full_car_vec * - 1;
    	sides[ "right" ] = self.origin + train_width_vec;
    	sides[ "left" ] = self.origin - train_width_vec;
    	start = self.origin;
    
    	max_x = sides[ "front" ][ 0 ];
    	min_x = sides[ "front" ][ 0 ];
    	max_y = sides[ "front" ][ 1 ];
    	min_y = sides[ "front" ][ 1 ];
    	foreach ( side in sides )
    	{
    		if ( side[ 0 ] > max_x )
    			max_x = side[ 0 ];
    		if ( side[ 0 ] < min_x )
    			min_x = side[ 0 ];
    		if ( side[ 1 ] > max_y )
    			max_y = side[ 1 ];
    		if ( side[ 1 ] < min_y )
    			min_y = side[ 1 ];
    	}
    
    	for ( ;; )
    	{
    		dif = start - self.origin;
    		start = self.origin;
    		max_x -= dif[ 0 ];
    		min_x -= dif[ 0 ];
    		max_y -= dif[ 1 ];
    		min_y -= dif[ 1 ];
    		
    		// store it for the dust fx
    		self.min_x = min_x;
    		self.max_x = max_x;
    		self.min_y = min_y;
    		self.max_y = max_y;
    		
    		//print3d( ( max_x, max_y, self.origin[ 2 ] ), " * " );
    		//print3d( ( min_x, max_y, self.origin[ 2 ] ), " * " );
    		//print3d( ( max_x, min_y, self.origin[ 2 ] ), " * " );
    		//print3d( ( min_x, min_y, self.origin[ 2 ] ), " * " );
    
    		hit_ents = [];
    
    		foreach ( player in level.players )
    		{
    			if ( !isalive( player ) )
    				continue;
    			if ( player.sessionstate != "playing" )
    				continue;
    			if ( !train_hits( player, min_x, min_y, max_x, max_y ) )
    				continue;
    				
    			player playsound( "melee_knife_hit_watermelon" );
    
    			pos = get_damageable_player_pos( player );
    			hit_ents[ hit_ents.size ] = get_damageable_player( player, pos );
    		}
    
    		grenades = getentarray( "grenade", "classname" );
    		foreach ( grenade in grenades )
    		{
    			if ( !train_hits( grenade, min_x, min_y, max_x, max_y ) )
    				continue;
    
    			pos = get_damageable_grenade_pos( grenade );
    			hit_ents[ hit_ents.size ] = get_damageable_grenade( grenade, pos );
    		}
    	
    		foreach ( ent in hit_ents )
    		{				
    			ent.damage = 5000;
    			ent.pos = self.origin;
    			ent.damageOwner = self;
    			ent.eInflictor = self;
    
    			ent maps\mp\gametypes\_weapons::damageEnt(
    				ent.eInflictor, // eInflictor = the entity that causes the damage (e.g. a claymore)
    				ent.damageOwner, // eAttacker = the player that is attacking
    				ent.damage, // iDamage = the amount of damage to do
    				"MOD_PROJECTILE_SPLASH", // sMeansOfDeath = string specifying the method of death (e.g. "MOD_PROJECTILE_SPLASH")
    				"train_mp", // sWeapon = string specifying the weapon used (e.g. "claymore_mp")
    				ent.pos, // damagepos = the position damage is coming from
    				vectornormalize(ent.damageCenter - ent.pos) // damagedir = the direction damage is moving in
    			);			
    		}
    				
    		wait( 0.05 );
    	}
    }
    
    train_hits( entity, min_x, min_y, max_x, max_y )
    {
    	if ( entity.origin[ 2 ] < self.origin[ 2 ] - 5 )
    		return false;
    
    	if ( entity.origin[ 2 ] > self.origin[ 2 ] + 162 )
    		return false;
    
    	x = entity.origin[ 0 ];
    	y = entity.origin[ 1 ];
    	if ( x < min_x )
    		return false;
    	if ( y < min_y )
    		return false;
    	if ( x > max_x )
    		return false;
    	if ( y > max_y )
    		return false;
    	return true;
    }
    
    
    train_eq( origin, eq_radius, track_time, full_train_time )
    {
    	train_eq_lerp_for_time( origin, 0.0, 0.09, eq_radius, track_time, 0.5 );
    	train_eq_for_time( origin, 0.17, eq_radius, full_train_time, 0.5 );
    	train_eq_lerp_for_time( origin, 0.09, 0, eq_radius, track_time, 0.5 );
    	//level notify( "stop_train_debug" + origin );
    }
    
    train_eq_for_time( origin, eq, eq_radius, eq_time, eq_time_slice )
    {
    	// earthquake makes the quake taper off over time so we
    	// are going to do a lot of earthquakes to simulate a steady quake
    	//thread print3d_eq( origin, eq );
    	steps = int( eq_time / eq_time_slice );
    	for ( i = 0; i < steps; i++ )
    	{
    		Earthquake( eq, eq_time_slice * 3, origin, eq_radius );
    		wait( eq_time_slice );
    	}
    	remainder = eq_time - steps * eq_time_slice;
    	if ( remainder > 0 )
    	{
    		wait( remainder );
    	}
    }
    
    train_eq_lerp_for_time( origin, eq1, eq2, eq_radius, eq_time, eq_time_slice )
    {
    	// earthquake makes the quake taper off over time so we
    	// are going to do a lot of earthquakes to simulate a steady quake
    	//thread print3d_eq( origin, eq );
    	steps = int( eq_time / eq_time_slice );
    	for ( i = 0; i < steps; i++ )
    	{
    		progress = i / steps;
    		eq = eq2 * progress + eq1 * ( 1 - progress );
    		if ( eq > 0 )
    			Earthquake( eq, eq_time_slice * 3, origin, eq_radius );
    		wait( eq_time_slice );
    	}
    	remainder = eq_time - steps * eq_time_slice;
    	if ( remainder > 0 )
    	{
    		wait( remainder );
    	}
    }
    
    print3d_eq( origin, msg )
    {
    	level notify( "stop_train_debug" + origin );
    	level endon( "stop_train_debug" + origin );
    	for ( ;; )
    	{
    		Print3d( origin, msg );
    		wait( 0.05 );
    	}
    }

  2. #2
    EpicPlayer's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    628
    Reputation
    13
    Thanks
    158
    Never thought of this idea...
    But could be really interesting, GL making one

  3. #3
    Yamato's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    839
    Reputation
    13
    Thanks
    154
    My Mood
    Amazed
    Quote Originally Posted by EpicPlayer View Post
    Never thought of this idea...
    But could be really interesting, GL making one
    The first thing I have to know, is that if the models that appear exist,

  4. #4
    mathieutje12's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    Close to my PC
    Posts
    578
    Reputation
    14
    Thanks
    166
    My Mood
    Angelic
    just try it out if the model exist i guess it wont work

  5. #5
    Yamato's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    839
    Reputation
    13
    Thanks
    154
    My Mood
    Amazed
    Quote Originally Posted by mathieutje12 View Post
    just try it out if the model exist i guess it wont work
    I can always try some crap with Carepackages,

  6. #6
    cgallagher21's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Posts
    1,627
    Reputation
    11
    Thanks
    325
    My Mood
    Angelic
    You know what could be a shit train v1.
    Make it out of moveable green or red carepackages.
    Lol hehehehe random...,

  7. #7
    ~Just IN~'s Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    self thread xbox360nolife() {
    Posts
    518
    Reputation
    11
    Thanks
    55
    My Mood
    Doh
    Quote Originally Posted by cgallagher21 View Post
    You know what could be a shit train v1.
    Make it out of moveable green or red carepackages.
    Lol hehehehe random...,
    mean much?

    Good luck.

  8. #8
    EpicPlayer's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    628
    Reputation
    13
    Thanks
    158
    Quote Originally Posted by Yamato View Post
    The first thing I have to know, is that if the models that appear exist,
    I don't think theres any train models, however you could mix different models to look like a train xD

  9. #9
    Yamato's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    839
    Reputation
    13
    Thanks
    154
    My Mood
    Amazed
    Quote Originally Posted by EpicPlayer View Post
    I don't think theres any train models, however you could mix different models to look like a train xD
    Only CPs, but the problem is to put them all toghether and make them move well,

  10. #10
    iKiLLYouCro's Avatar
    Join Date
    Aug 2010
    Gender
    male
    Location
    Germany, Croatia
    Posts
    678
    Reputation
    16
    Thanks
    49
    My Mood
    Bitchy
    HAHA A Train in MW2!
    ADD ME ON XFire: iKiLLYouCro


    [IMG]https://i238.photobucke*****m/albums/ff303/colby1666/Signatures/ClanTag2.png[/IMG]

  11. #11
    [WhA]4FunPlayin's Avatar
    Join Date
    Sep 2010
    Gender
    male
    Location
    Not here
    Posts
    757
    Reputation
    8
    Thanks
    169
    My Mood
    Lonely
    No model that I know.

    You can connect carepackages like killingDyl did:


    For moving the train it's simple as nothing

    Code:
    b[0] = spawn train...
    b[1] = spawn train...
    b[2] = spawn train...
    *skip*
    b[10000] = spawn train...
    Code:
    for(a = b.size; a > -1; a--)
    {
    b[a] moveX(3000, 5); //move X axis by 5 seconds
    //don't add any 'wait'
    }
    Or moveY because I don't really know.

  12. #12
    MuLtiHuNTeR's Avatar
    Join Date
    May 2010
    Gender
    male
    Posts
    49
    Reputation
    10
    Thanks
    1
    My Mood
    Inspired
    Quote Originally Posted by EpicPlayer View Post
    I don't think theres any train models, however you could mix different models to look like a train xD
    There are models of train on derail.

  13. #13
    EpicPlayer's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    628
    Reputation
    13
    Thanks
    158
    Quote Originally Posted by MuLtiHuNTeR View Post
    There are models of train on derail.
    A bit new to modding, aye?
    These are "images" not models which developers use to create the maps :P

    I'm a bit lazy but, there could be chance that it's a model, all you have to do is search through all (almost) IWD files
    Yamato?

  14. #14
    Yamato's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    839
    Reputation
    13
    Thanks
    154
    My Mood
    Amazed
    Quote Originally Posted by EpicPlayer View Post
    A bit new to modding, aye?
    These are "images" not models which developers use to create the maps :P

    I'm a bit lazy but, there could be chance that it's a model, all you have to do is search through all (almost) IWD files
    Yamato?
    OMG, , IŽll try, the problem I have is to make the train, I know how to make something move, like 4funplaying code, but what I dont know is how to make a Train Wagon, mmm, I can make it, but with the Killingdyl mapping functions. But then, how do I move all?

  15. #15
    EpicPlayer's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    628
    Reputation
    13
    Thanks
    158
    Killingdyll mapping functions, you mean _mapedit.gsc? ;p

    I found a saveable forge mod, do you want it? (Saves the codes in games_mp.log)

Page 1 of 2 12 LastLast