Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ======================================================================================================
- Add Controllers Script
- ======================================================================================================
- ///mcs_add_controllers( Rooms, Controllers );
- ///@param Rooms - The room(s), single or array, that are getting controllers added to
- ///@param Controllers - The Controllers to add to the room(s), single or array
- #region //Details and Use
- /*
- Add room controllers to the game. You can specify a room and the controllers
- that go into it.
- Room ( or an array of rooms ) : What room(s) to put controller(s) into.
- Controller ( or an array of controllers ) : What controller(s) to put into the room(s).
- Event : Game Config Script
- Object Type : None
- Scope : Game
- */
- #endregion
- #region //Check if the system has been initiated, if not then initiate it.
- if( !instance_exists( mc_master ) ){
- instance_create_depth( 0,0, 0,mc_master );
- }
- #endregion
- var rm = argument[0], i, j, k, l, obj = argument[1];
- //If argument count is less than 1 you've dun fucked up
- if argument_count > 1{
- #region //Main Processing
- //First, we check the rooms and see if they are indexed
- if( is_array( rm ) ){//We have an array of rooms
- //Loop through the entries, find our rooms, add if neccessary
- for( j=0; j < array_length_1d(rm); j++ ){
- for( i = 0; i <= array_height_2d(global.game_nor_con); i++ ){
- if( i == array_height_2d(global.game_nor_con) || global.game_nor_con[i,0] == -1 ){//Add it
- global.game_nor_con[i,0] = rm[j];
- break;
- }
- if( global.game_nor_con[i,0] == rm[j] ){
- break;//It's already listed, so stop
- }
- }
- }
- #region //Object processing
- //Now that we've handled our rooms, let's insert objects
- if( is_array(obj) ){//Array of rooms, Array of objects
- for( l=0; l < array_length_1d(obj); l++ ){
- for(k=0; k < array_length_1d(rm); k++ ){//We are going to loop through and perform this on all of htese
- for( i = 0; i < array_height_2d(global.game_nor_con); i++ ){
- if( global.game_nor_con[i,0] == rm[k] ){//We've found our room
- for(j=1; j <= array_length_2d(global.game_nor_con, i); j++){//Loop through our controllers, add if not there
- if( j == array_length_2d(global.game_nor_con, i) || global.game_nor_con[i,j] == -1 ){
- global.game_nor_con[i,j] = obj[l]; // Put it on the end of our list
- break;
- }
- if( global.game_nor_con[i,j] == obj[l] ){
- break;//We're already listed, stop
- }
- }
- }
- }
- }
- }
- }else{//Array of rooms, only one object
- for(k=0; k < array_length_1d(rm); k++ ){//We are going to loop through and perform this on all of htese
- for( i = 0; i < array_height_2d(global.game_nor_con); i++ ){
- if( global.game_nor_con[i,0] == rm[k] ){//We've found our room
- for(j=1; j <= array_length_2d(global.game_nor_con, i); j++){//Loop through our controllers, add if not there
- if( j == array_length_2d(global.game_nor_con, i) || global.game_nor_con[i,j] == -1 ){
- global.game_nor_con[i,j] = obj; // Put it on the end of our list
- break;
- }
- if( global.game_nor_con[i,j] == obj ){
- break;//We're already listed, stop
- }
- }
- }
- }
- }
- }
- #endregion
- }else{//We have just one room
- //First, we loop through and check each of the rooms to make sure it isn't already listed
- for( i = 0; i <= array_height_2d(global.game_nor_con); i++ ){
- if( i == array_height_2d(global.game_nor_con) || global.game_nor_con[i,0] == -1 ){//Add it
- global.game_nor_con[i,0] = rm;
- break;
- }
- if( global.game_nor_con[i,0] == rm ){
- break;//It's already listed, so stop
- }
- }
- #region //Object Processing
- //Now that we've handled our rooms, let's insert objects
- if( is_array(obj) ){//One room, Array of objects
- for( k = 0; k < array_length_1d(obj); k++ ){
- for( i = 0; i <= array_height_2d(global.game_nor_con); i++ ){
- if( global.game_nor_con[i,0] == rm ){//We've found our room
- for(j=1; j <= array_length_2d(global.game_nor_con, i); j++){//Loop through our controllers, add if not there
- if( j == array_length_2d(global.game_nor_con, i) || global.game_nor_con[i,j] == -1 ){
- global.game_nor_con[i,j] = obj[k]; // Put it on the end of our list
- break;
- }
- if( global.game_nor_con[i,j] == obj[k] ){
- break;//We'r already listed, stop
- }
- }
- break;
- }
- }
- }
- }else{//One room, only one object
- for( i = 0; i <= array_height_2d(global.game_nor_con); i++ ){
- if( global.game_nor_con[i,0] == rm ){//We've found our room
- for(j=1; j <= array_length_2d(global.game_nor_con, i); j++){//Loop through our controllers, add if not there
- if( j == array_length_2d(global.game_nor_con, i) || global.game_nor_con[i,j] = -1 ){
- global.game_nor_con[i,j] = obj; // Put it on the end of our list
- break;
- }
- if( global.game_nor_con[i,j] == obj ){
- break;//We'r already listed, stop
- }
- }
- break;
- }
- }
- }
- #endregion
- }
- #endregion
- event_perform(mc_master, ev_room_start);//Initialize objects
- }else{
- show_error( "msc_add_controllers: Error, this script requires additional arguments", true );
- }
- ======================================================================================================
- Auto Add Script
- ======================================================================================================
- ///mcs_auto_add( "Slug" );
- ///@param Slug - A string containing the "word" to link everything together with
- /*
- This script quite simply links all controllers and all rooms
- that have the unified "slug" in their names. For instance "Jungle" will
- add all objects that contain the word "Jungle" to all rooms that have
- the word "Jungle" in the name.
- Higly recomend using some sort of convention that indicates you wish to
- include a controller.
- For instance, instead of just "jungle" do "a_jungle", then name your objects
- con_a_jungle_* and rm_a_jungle_* so you don't accidently include anything you
- don't wish to include.
- */
- #region//Check if the system has been initiated, if not then initiate it.
- if( !instance_exists( mc_master ) ){
- instance_create_depth( 0,0,0,mc_master );
- }
- #endregion
- var _s = argument[0], i, _n, _arr_r, _arr_o;
- _arr_r[0] = -1;
- _arr_o[0] = -1;
- #region//Search for rooms
- //Check for up to 1000 rooms.
- for( i=0; i<1000; i++ ){
- if( room_exists(i) ){//Check this room
- _n = room_get_name(i);
- if( string_pos( _s, _n ) != 0 ){//Check to see if our room has our slug
- if( _arr_r[0] == -1 ) _arr_r[0] = i;
- else _arr_r[array_length_1d( _arr_r )] = i;
- }
- }else{//We ran out of rooms
- break;
- }
- }
- #endregion
- #region//Search for controllers
- //Check for up to 1000 controllers.
- for( i=0; i<1000; i++ ){
- if( object_exists(i) ){//Check this controller
- _n = object_get_name(i);
- if( string_pos( _s, _n ) != 0 ){//Check to see if our controller has our slug
- if( _arr_o[0] == -1 ) _arr_o[0] = i;
- else _arr_o[array_length_1d( _arr_o )] = i;
- }
- }else{//We ran out of controllers
- break;
- }
- }
- #endregion
- //Add our controllers to our rooms
- if( _arr_r[0] != -1 && _arr_o[0] != -1 ){//Make sure we found stuff first
- mcs_add_controllers(_arr_r,_arr_o);
- }else{
- show_debug_message("Error MCS: No controllers or rooms found for slug '" + _s + "'" );
- }
- ======================================================================================================
- Remove Controllers Script
- ======================================================================================================
- ///mcs_remove_controller( room, controller );
- ///@param Room - The room we are removing a controller from
- ///@param Controller - The controller we are removing
- /*
- Using this script you are able to remove a room controller from being
- generated, as well as delete its instance.
- */
- var con = argument[1], rm = argument[0], i, j;
- for( j=0; j<array_height_2d( global.game_nor_con ); j++ ){
- if( global.game_nor_con[j, 0] == rm ){
- for( i=1; i<array_length_2d( global.game_nor_con, j ); i++ ){
- if( global.game_nor_con[j, i] == con ){
- if( instance_exists( global.game_nor_con[j, i] ) ){
- with( global.game_nor_con[j, i] ) instance_destroy();
- }
- global.game_nor_con[j, i] = -1;
- break;
- }
- }
- }
- }
- ======================================================================================================
- Master Control Object
- ======================================================================================================
- //MUST BE NAMED "mc_master"!!
- //MUST BE PERSISTENT!!
- =========================
- /////Create Event
- =========================
- /// @description Initiation and Description
- #region // Details
- /*
- This object is created when the controller engine is initiated. This handles all the
- controller inclusions based on what is in global values.
- Upon creation, it initializes the necessary global variables and launches the controller
- creation code.
- The structure of the global 2d array is as follows (OLD)
- game_nor_con[#,0] = Room ID
- game_nor_con[#,1..2..3..] = Controller Instance IDs
- */
- #endregion
- global.game_nor_con[0,0] = -1;
- event_perform(mc_master, ev_room_start);//Use this code to manually initiate controllers
- show_debug_message("MCS|||Master Control System initiated.");
- =========================
- /////Room Start Event
- =========================
- /// @description Initiate Controllers
- var i,j, ind = array_height_2d(global.game_nor_con);
- for(i=0; i < ind; i++){
- //Check if our item here is for our room
- if(room == global.game_nor_con[i,0]){
- //If so, if it's a valid object go ahead and create it
- for(j=1; j < array_length_2d(global.game_nor_con, i); j++){
- if( global.game_nor_con[i, j] != -1 and global.game_nor_con[i, j] != -4 ){
- if( !instance_exists( global.game_nor_con[i, j] ) ){
- instance_create_depth(0,0, 0, global.game_nor_con[i, j]);
- }
- }
- }
- }
- }
- show_debug_message("MCS|||Control initiations ran.");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement