[SOLVED] loading equipment in hangar

Axl Trauts

Member
Hi all,

I am trying to start with loading some equipment on my ship on a hangar. How should it work? Basically, the player has a ship divided in sections: Wing slot 1, wing slot 2, body, extra and special. The player starts buying those equipment from a shop and then load them on each slot, only one can be loaded on each section of the ship.

Now, every equipment is stored on a global 2d array using this example extract:
From the obj_global_starter controller:
Code:
// 0=Name, 1=Quantity, 2=Max quantity, 3=Initial Qty, 4=Sprite
global.ar_inventory[5,0] = "Misil";       // Missile
global.ar_inventory[5,1] = 0;               // Macro: M_MisilQty
global.ar_inventory[5,2] = 2;
global.ar_inventory[5,3] = 0;
global.ar_inventory[5,4] = spr_itm_misil;
global.ar_inventory[5,5]="Wing2";      // Section on the ship it can be installed
Maybe column 3 is not needed but I still put it. column 1 tells if I bought it or not.

Now there is another table... I mean... array for the slot selection on the hangar:

From the obj_global_starter controller:
Code:
global.ar_equipo[0,0]="Wing1"; // Ship section
global.ar_equipo[0,1]="";       // Selected equipment
global.ar_equipo[1,0]="Wing2";
global.ar_equipo[1,1]="";
global.ar_equipo[2,0]="Body";
global.ar_equipo[2,1]="";
global.ar_equipo[3,0]="Special";
global.ar_equipo[3,1]="";
global.ar_equipo[4,0]="Extra";
global.ar_equipo[4,1]="";
Now on the Hangar Object I´d like to put a big ship sprite divided in sections, where I can click on each section, and choose the valid equipment for that section from a drop-down menu or something useful, for example if I click on Wing2, I can see "Misil", but if I click on Body, Misil shouldn´t be listed. When I select Misil, its name will be stored on that slot
Code:
global.ar_equipo[1,1]=global.ar_inventory[i,0];
(Works like a foreign key)

I don´t know how to do the drop-down list but I have the way to filter it using the slot name on global.ar_inventory[i,5], or something that works like that, can you give me examples?
 

Axl Trauts

Member
I solved this and all the things on the Hangar, but i'll post how to make the drop-down list showing only the items on your inventory and by section.

First the calling button, or the menu button that calls the submenu: obj_hangar_seccion. This button is placed on each portion of the ship blueprint on the hangar, so it each one have a creation code that says:

Creation code for the obj_hangar_seccion on the Extra section of the ship:
Code:
seccion = "Extra";
texto = "Equipar extras";
spritesel = spr_hangar_extra;
Step Event:
Code:
if distance_to_point(mouse_x,mouse_y)<=0 and ctrl_shop.pausar == false
{   if mouse_check_button_released(mb_left)
    {   scr_menu_seleccion(x,y,seccion) //  Opens submenu. The variable seccion is defined on the button's creation code.
        ctrl_shop.pausar = true;  //  If true the menu buttons on the room won´t be clickable until the submenu is closed
    }
}
Draw Event:
Code:
if distance_to_point(mouse_x,mouse_y)<=0 and ctrl_shop.pausar == false
{   draw_sprite(spritesel,1,x,y);  // spritesel is also defined on the creation code. Shows the sprite for the menu button.
    draw_text(448,224,texto) // texto also a creation code variable
}
------------------------------------------------
Script scr_menu_seleccion
Code:
menux = argument0;
menuy = argument1;
seccion =  argument2;

count = 0;
for(i=0; i<array_height_2d(global.ar_inventory); i+=1)
{   if(global.ar_inventory[i,5]==seccion and global.ar_inventory[i,1]>0)
    {   boton=instance_create(menux+20,menuy+26+26*count,obj_hangar_bn);
        boton.nombre = global.ar_inventory[i,0]; // passes nombre to submenu
        boton.seccion = seccion; // passes seccion to submenu
        count = count+1;
    }
}
instance_create(menux+20,menuy+26*(count+1),obj_hangar_bn_exit);
---------------------------------------------------
obj_hangar_bn is the button of the submenu that shows only the items defined on that section and only if there is at least one on the inventory

Create Event:
Code:
q=-1;
close = false;
// seccion defined on scr_menu_seleccion
// nombre defined on scr_menu_seleccion
Step Event:
Code:
// q returns position on the equipment array where I want to store or load the equipment.
for(i=0;i<array_height_2d(global.ar_equipo);i+=1)
{   if(global.ar_equipo[i,0] == seccion)
    {   q = i;
    }
}

// Se selecciona el equipo en la sección escogida al hacer clic
if distance_to_point(mouse_x,mouse_y)<=0
{   if mouse_check_button_released(mb_left)
    {   global.ar_equipo[q,1] = nombre;
        close = true;
    }
}

// Close submenu. The close variable is used for a final submenu button that only works to cancel the selection and return to the menu.
if close == true
{   with(obj_hangar_bn_par) 
    {   instance_destroy();
        ctrl_shop.pausar = false;
    }
}
Draw Event:
Code:
draw_self();
draw_text(x,y+4,+string(nombre));
I don't think I've forgotten anything. I hope this works for somebody, as a way to give back to the community.
 
Top