Modme Forums
Menu:

Is there a way to work with classes? (Object-orientated)

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: Akrime
Question is in the title. Can I make classes just like in C# or Java?


ModmeBot:

Reply By: DTZxPorter
Surprisingly, BO3 introduced classes in their scripting language. See scripts\shared for some examples.

Here is a snippet of one:

class cDoor
{
	var m_s_bundle;							// Bundle with info regarding the door.
	var m_str_targetname;
	var m_str_target;
	var m_str_script_flag;
	
	var m_e_door;							// Door Ent

	var m_e_trigger;						// Trigger Ent
	var	m_e_trigger_player;					// Player who opens the door
	var m_n_trigger_height;
	
	var m_n_hack_pct;						// percentage of the current hack completed.
	var m_b_hacking;						// true if hacking is currently taking place.
	
	var m_e_hint_trigger;

	var m_v_open_pos;						// Door open and close positions (for slide doors)
	var m_v_close_pos;
	
	var m_n_door_connect_paths;				// Does door connect paths?

	var m_b_is_open;						// Is the door open?

	// Overrides that can be set in script
	var m_override_swing_angle;

	var m_door_open_delay_time;				// Ability to delat the door opening
	
	constructor()
	{
		m_n_trigger_height = 80;			// Default trigger height
		m_override_swing_angle = undefined;
		m_door_open_delay_time = 0;
		m_e_trigger_player = undefined;
	}

	destructor()
	{
		if( IsDefined(m_e_trigger) )
		{
			m_e_trigger delete();
		}
	}

	function init_xmodel( str_xmodel, connect_paths, v_origin, v_angles )
	{
		if( !IsDefined(str_xmodel) )
		{
			str_xmodel = "script_origin";
			//ASSERTMSG( "No model found in Door Script Bundle" );
			//return;
		}

		m_e_door = spawn( "script_model", v_origin, 1 );
		m_e_door setModel( str_xmodel );
		m_e_door.angles = v_angles;
		
		if(connect_paths)
		{
			m_e_door DisconnectPaths();
		}			
	}
	
	function get_hack_pos()
	{
		v_trigger_offset = m_s_bundle.v_trigger_offset;
	
		v_pos = calculate_offset_position( m_e_door.origin, m_e_door.angles, v_trigger_offset );
		v_pos = ( v_pos[0], v_pos[1], v_pos[2]+50 );		// Its a look at trigger, so move the base of the trigger off the ground
		
		if ( IsDefined( m_str_target ) )
		{
			e_target = GetEnt( m_str_target, "targetname" );
			if ( IsDefined( e_target ) )
			{
				return e_target.origin;
			}
		}
		
		return v_pos;
	}
(etc....)
}