Already have a playable version?
HaisenX
Creator of
Recent community posts
Hello guys, I'm here to announce my first full game, you must survive as long as possible while random things fall from the sky, it's pretty simple! But I'm very happy with this achievement and I hope you all like it!!
link for Game: Dream Dodge da HaisenX
Hello I'm here to announce my first project!! It aims to help those who are working on a game with a mystery or horror theme and for that I created a simple flashlight to help.
Project link: Flashlight by HaisenX
Inventory and Equipment Code
- Thread starterHaisenX
- Start dateYesterday at 11:54 PM
- Tags#help #problem #programming help
HaisenX
New Member
I'm having trouble creating an equipment system for my game I have a working inventory but I can't put inventory items in the equipment tab
This is my code
Obj_Inventory-create:
inventario = false;
escala = 3;
comeco_x = 17 * escala;
comeco_y = 17 * escala;
slots_h = 4;
slots_v = 4;
total_slots = slots_h * slots_v;
tamanho_slots = 34 * escala;
buffer = 3 * escala;
inventario_l = sprite_get_width(Spr_Inventario) * escala
inventario_a = sprite_get_height(Spr_Inventario) * escala
item_selecionado = -1;
pos_selecionado = -1;
enum Item_Armas{
EspadaQuebrada,
LaminasDaCalamidade,
EspadaLonga,
Florete,
Katana,
Altura,
}
enum Item_Consumiveis{
PocaoDeCura,
PocaoDeMana,
Altura,
}
enum Item_Armaduras{
ArmaduradeAco,
ArmaduradeOuro,
Altura,
}
enum Infos{
Item,
Quantidade,
Sprite,
Altura,
}
// Criando e inicializando a grid de itens
grid_items = ds_grid_create(Infos.Altura, total_slots);
ds_grid_set_region(grid_items, 0, 0, Infos.Altura - 1, total_slots - 1, -1);
Step:
if keyboard_check_pressed(vk_tab){
inventario = !inventario
}
draw_gui:
var _guil = display_get_gui_width();
var _guia = display_get_gui_height();
var _mx = device_mouse_x_to_gui(0);
var _my = device_mouse_y_to_gui(0);
if (inventario == true){
var _invX = _guil / 1.05 - inventario_l / 1.05;
var _invy = _guia / 1.3 - inventario_l / 1.3;
draw_sprite_ext(Spr_Inventario, 0, _invX, _invy, escala, escala, 0, c_white, 1);
var ix = 0;
var iy = 0;
for (var i = 0; i < total_slots; i++){
var _slotsx = _invX + comeco_x + ((tamanho_slots + buffer) * ix);
var _slotsy = _invy + comeco_y + ((tamanho_slots + buffer) * iy);
if (point_in_rectangle(_mx, _my, _slotsx, _slotsy, _slotsx + tamanho_slots, _slotsy + tamanho_slots)){
draw_sprite_ext(Spr_Select_Inventario, 0, _slotsx, _slotsy, escala, escala, 0, c_white, 1);
if keyboard_check_pressed(ord("F")) and grid_items[# Infos.Item, i] != -1{
var _inst = instance_create_layer(Obj_Player.x, Obj_Player.y, "Instances",Obj_Item);
_inst.sprite_index = grid_items[# Infos.Sprite, i];
_inst.image_index = grid_items[# Infos.Item, i];
_inst.quantidade = grid_items[# Infos.Quantidade, i];
//ESVAZIANDO O SLOT
grid_items[# Infos.Item, i] = -1;
grid_items[# Infos.Quantidade, i] = -1;
grid_items[# Infos.Sprite, i] = -1;
}
if (mouse_check_button_pressed(mb_left)){
// Caso não tenha nenhum item selecionado
if (item_selecionado == -1){
item_selecionado = grid_items[# Infos.Item, i];
pos_selecionado = i;
}
else {
// Caso o item selecionado seja igual ao do slot que iremos colocar
if (item_selecionado == grid_items[# Infos.Item, i] && pos_selecionado != i && grid_items[# Infos.Sprite, i] == grid_items[# Infos.Sprite, pos_selecionado]){
// Empilhar itens: aumenta a quantidade do item no slot
grid_items[# Infos.Quantidade, i] += grid_items[# Infos.Quantidade, pos_selecionado];
// Limpa o slot de origem
grid_items[# Infos.Item, pos_selecionado] = -1;
grid_items[# Infos.Quantidade, pos_selecionado] = -1;
grid_items[# Infos.Sprite, pos_selecionado] = -1;
// Reseta seleção
item_selecionado = -1;
pos_selecionado = -1;
}
// Caso o slot selecionado esteja vazio
else if (grid_items[# Infos.Item, i] == -1){
// Transferir o item para o slot vazio
grid_items[# Infos.Item, i] = grid_items[# Infos.Item, pos_selecionado];
grid_items[# Infos.Quantidade, i] = grid_items[# Infos.Quantidade, pos_selecionado];
grid_items[# Infos.Sprite, i] = grid_items[# Infos.Sprite, pos_selecionado];
// Limpa o slot de origem
grid_items[# Infos.Item, pos_selecionado] = -1;
grid_items[# Infos.Quantidade, pos_selecionado] = -1;
grid_items[# Infos.Sprite, pos_selecionado] = -1;
// Reseta seleção
item_selecionado = -1;
pos_selecionado = -1;
}
// Caso o slot selecionado já tenha um item e queremos trocar a posição
else {
// Armazena os dados do item atual
var _item = grid_items[# Infos.Item, i];
var _quantidade = grid_items[# Infos.Quantidade, i];
var _spr = grid_items[# Infos.Sprite, i];
// Troca os itens entre os slots
grid_items[# Infos.Item, i] = grid_items[# Infos.Item, pos_selecionado];
grid_items[# Infos.Quantidade, i] = grid_items[# Infos.Quantidade, pos_selecionado];
grid_items[# Infos.Sprite, i] = grid_items[# Infos.Sprite, pos_selecionado];
// Restaura o item do slot de origem
grid_items[# Infos.Item, pos_selecionado] = _item;
grid_items[# Infos.Quantidade, pos_selecionado] = _quantidade;
grid_items[# Infos.Sprite, pos_selecionado] = _spr;
// Reseta seleção
item_selecionado = -1;
pos_selecionado = -1;
}
}
}
}
var _sprite = grid_items[# Infos.Sprite, i];
// Verifica se há um item no slot
if (grid_items[# Infos.Item, i] != -1){
// Desenha o sprite do item
draw_set_font(Font1);
draw_sprite_ext(_sprite, grid_items[# 0, i], _slotsx + 25, _slotsy + 25, escala, escala, 0, c_white, 1);
// Desenha a quantidade do item
draw_text(_slotsx + 1, _slotsy + tamanho_slots - 22, grid_items[# Infos.Quantidade, i]);
}
ix++;
if (ix >= slots_h){
ix = 0;
iy++;
}
}
// Ao clicar com o botão direito, o item selecionado é desmarcado
if (mouse_check_button_pressed(mb_right)){
item_selecionado = -1;
pos_selecionado = -1;
}
// Desenha o item selecionado enquanto está sendo arrastado
if (item_selecionado != -1){
draw_sprite_ext(grid_items[# Infos.Sprite, pos_selecionado], item_selecionado, _mx, _my, escala, escala, 0, c_white, 0.5);
}
}
script:
// SCRIPT
function ds_grid_add_item() {
var _grid_inv = Obj_Inventario.grid_items;
var _checagem = 0;
while _grid_inv[# Infos.Item, _checagem] != -1{
_checagem++;
}
_grid_inv[# 0, _checagem] = argument[0];
_grid_inv[# 1, _checagem] = argument[1];
_grid_inv[# 2, _checagem] = argument[2];
}
Obj_ equipment-Create:
inventario = false;
escala = 3;
comeco_x = 17 * escala;
comeco_y = 17 * escala;
slots_h = 4;
slots_v = 4;
total_slots = slots_h * slots_v;
tamanho_slots = 34 * escala;
buffer = 3 * escala;
inventario_l = sprite_get_width(Spr_Inventario) * escala
inventario_a = sprite_get_height(Spr_Inventario) * escala
item_selecionado = -1;
pos_selecionado = -1;
enum Item_Armas{
EspadaQuebrada,
LaminasDaCalamidade,
EspadaLonga,
Florete,
Katana,
Altura,
}
enum Item_Consumiveis{
PocaoDeCura,
PocaoDeMana,
Altura,
}
enum Item_Armaduras{
ArmaduradeAco,
ArmaduradeOuro,
Altura,
}
enum Infos{
Item,
Quantidade,
Sprite,
Altura,
}
// Criando e inicializando a grid de itens
grid_items = ds_grid_create(Infos.Altura, total_slots);
ds_grid_set_region(grid_items, 0, 0, Infos.Altura - 1, total_slots - 1, -1);
step:
if keyboard_check_pressed(vk_tab){
inventario = !inventario
}
draw_gui:
var _guil = display_get_gui_width();
var _guia = display_get_gui_height();
var _mx = device_mouse_x_to_gui(0);
var _my = device_mouse_y_to_gui(0);
if (inventario == true){
var _invX = _guil / 1.05 - inventario_l / 1.05;
var _invy = _guia / 1.3 - inventario_l / 1.3;
draw_sprite_ext(Spr_Inventario, 0, _invX, _invy, escala, escala, 0, c_white, 1);
var ix = 0;
var iy = 0;
for (var i = 0; i < total_slots; i++){
var _slotsx = _invX + comeco_x + ((tamanho_slots + buffer) * ix);
var _slotsy = _invy + comeco_y + ((tamanho_slots + buffer) * iy);
if (point_in_rectangle(_mx, _my, _slotsx, _slotsy, _slotsx + tamanho_slots, _slotsy + tamanho_slots)){
draw_sprite_ext(Spr_Select_Inventario, 0, _slotsx, _slotsy, escala, escala, 0, c_white, 1);
if keyboard_check_pressed(ord("F")) and grid_items[# Infos.Item, i] != -1{
var _inst = instance_create_layer(Obj_Player.x, Obj_Player.y, "Instances",Obj_Item);
_inst.sprite_index = grid_items[# Infos.Sprite, i];
_inst.image_index = grid_items[# Infos.Item, i];
_inst.quantidade = grid_items[# Infos.Quantidade, i];
//ESVAZIANDO O SLOT
grid_items[# Infos.Item, i] = -1;
grid_items[# Infos.Quantidade, i] = -1;
grid_items[# Infos.Sprite, i] = -1;
}
if (mouse_check_button_pressed(mb_left)){
// Caso não tenha nenhum item selecionado
if (item_selecionado == -1){
item_selecionado = grid_items[# Infos.Item, i];
pos_selecionado = i;
}
else {
// Caso o item selecionado seja igual ao do slot que iremos colocar
if (item_selecionado == grid_items[# Infos.Item, i] && pos_selecionado != i && grid_items[# Infos.Sprite, i] == grid_items[# Infos.Sprite, pos_selecionado]){
// Empilhar itens: aumenta a quantidade do item no slot
grid_items[# Infos.Quantidade, i] += grid_items[# Infos.Quantidade, pos_selecionado];
// Limpa o slot de origem
grid_items[# Infos.Item, pos_selecionado] = -1;
grid_items[# Infos.Quantidade, pos_selecionado] = -1;
grid_items[# Infos.Sprite, pos_selecionado] = -1;
// Reseta seleção
item_selecionado = -1;
pos_selecionado = -1;
}
// Caso o slot selecionado esteja vazio
else if (grid_items[# Infos.Item, i] == -1){
// Transferir o item para o slot vazio
grid_items[# Infos.Item, i] = grid_items[# Infos.Item, pos_selecionado];
grid_items[# Infos.Quantidade, i] = grid_items[# Infos.Quantidade, pos_selecionado];
grid_items[# Infos.Sprite, i] = grid_items[# Infos.Sprite, pos_selecionado];
// Limpa o slot de origem
grid_items[# Infos.Item, pos_selecionado] = -1;
grid_items[# Infos.Quantidade, pos_selecionado] = -1;
grid_items[# Infos.Sprite, pos_selecionado] = -1;
// Reseta seleção
item_selecionado = -1;
pos_selecionado = -1;
}
// Caso o slot selecionado já tenha um item e queremos trocar a posição
else {
// Armazena os dados do item atual
var _item = grid_items[# Infos.Item, i];
var _quantidade = grid_items[# Infos.Quantidade, i];
var _spr = grid_items[# Infos.Sprite, i];
// Troca os itens entre os slots
grid_items[# Infos.Item, i] = grid_items[# Infos.Item, pos_selecionado];
grid_items[# Infos.Quantidade, i] = grid_items[# Infos.Quantidade, pos_selecionado];
grid_items[# Infos.Sprite, i] = grid_items[# Infos.Sprite, pos_selecionado];
// Restaura o item do slot de origem
grid_items[# Infos.Item, pos_selecionado] = _item;
grid_items[# Infos.Quantidade, pos_selecionado] = _quantidade;
grid_items[# Infos.Sprite, pos_selecionado] = _spr;
// Reseta seleção
item_selecionado = -1;
pos_selecionado = -1;
}
}
}
}
var _sprite = grid_items[# Infos.Sprite, i];
// Verifica se há um item no slot
if (grid_items[# Infos.Item, i] != -1){
// Desenha o sprite do item
draw_set_font(Font1);
draw_sprite_ext(_sprite, grid_items[# 0, i], _slotsx + 25, _slotsy + 25, escala, escala, 0, c_white, 1);
// Desenha a quantidade do item
draw_text(_slotsx + 1, _slotsy + tamanho_slots - 22, grid_items[# Infos.Quantidade, i]);
}
ix++;
if (ix >= slots_h){
ix = 0;
iy++;
}
}
// Ao clicar com o botão direito, o item selecionado é desmarcado
if (mouse_check_button_pressed(mb_right)){
item_selecionado = -1;
pos_selecionado = -1;
}
// Desenha o item selecionado enquanto está sendo arrastado
if (item_selecionado != -1){
draw_sprite_ext(grid_items[# Infos.Sprite, pos_selecionado], item_selecionado, _mx, _my, escala, escala, 0, c_white, 0.5);
}
}
I hope you can help me