Minggu, 24 Mei 2015

Cara membuat inventory di game maker

Assalamu'alaikum, hai sob, selamat datang di DG, sekarang kita akan membahas "Cara membuat inventory di game maker"



Screen shoot :


SPRITE
Buat Sprite >>  Beri nama sItem>> Klik Edit sprite >>Klik File >>Klik add from file
dan load semua gambar yang ada didalam Folder sItem, tapi harus ber urutan
Klik tanda centang dan klik Separate collision mask dan klik center.

2.sMoney
Buat Sprite >>  Beri nama sMoney>> Klik Edit sprite >>Klik File >>Klik add from file
dan load semua gambar yang ada didalam Folder sMoney, tapi harus ber urutan
Klik tanda centang dan klik Separate collision mask dan klik center.

3.sWoodenArows
Buat Sprite >>  Beri nama sWoodenArrows>> Klik Edit sprite >>Klik File >>Klik add from file
dan load semua gambar yang ada didalam Folder sWoodenArrows, tapi harus ber urutan
Klik tanda centang dan klik Separate collision mask dan klik center.

4.sItemOnGround
Buat Sprite >>  Beri nama sItemOnGround>> Klik Edit sprite >>Klik File >>Klik add from file
dan load semua gambar yang ada didalam Folder sprite, Klik tanda centang dan klik Separate collision mask dan klik center.

5.sPort
Buat Sprite >>  Beri nama sPort>> Klik Edit sprite >>Klik File >>Klik add from file
dan load semua gambar yang ada didalam Folder sprite, Klik tanda centang dan klik Separate collision mask dan klik center.

6.spr_up
Buat Sprite >>  Beri nama spr_up>> Klik Edit sprite >>Klik File >>Klik add from file
dan load gambar yang ada didalam Folder sprite, klik tanda centang dan klik center.

7.spr_down
Buat Sprite >>  Beri nama spr_down>> Klik Edit sprite >>Klik File >>Klik add from file
dan load gambar yang ada didalam Folder sprite, klik tanda centang dan klik center.


8.spr_right
Buat Sprite >>  Beri nama spr_right>> Klik Edit sprite >>Klik File >>Klik add from file
dan load gambar yang ada didalam Folder sprite, klik tanda centang dan klik center.

9.spr_left
Buat Sprite >>  Beri nama spr_left>> Klik Edit sprite >>Klik File >>Klik add from file
dan load gambar yang ada didalam Folder sprite, klik tanda centang dan klik center.

Background

1.bggrass
Buat background>>  Beri nama bggrass>> Klik Edit sprite >>Klik File >>Klik add from file
dan load gambar yang ada didalam Folder sprite, tapi harus ber urutan
Klik tanda centang dan klik center.

Script

Buatlah folder grup dengan nama inventory scripts dan masukan scripts dibawah ini ke folder grup inventory scripts

1.inventory_add
Buat script>> Beri nama inventory_add>>dan isikan kode di bawah ini
//Call:     inventory_add(itemID,quantity)
//Info:     Adds item(s) to the inventory. itemID is the ID
//          of the item to be added and quantity is the number
//          of that item you want to add.
//Event:    Any
//Returns:  Number of items that couldn't be added because
//          the inventory was full. For example, if you add
//          10 items and there's only 7 places left in the
//          inventory, it will return 3.

var itemno,number,newno;
newno=0
itemno=argument0
number=argument1

var a;
if (item_stackable(itemno)=1) {
    var a;
    for (a=1 a<=28 a+=1) {
        if (global.inv_item[a,0]=itemno) {newno=a; global.inv_item[a,1]+=number; a=29;}
    }
    if (newno=0) {
        var b,lastno;
        lastno=0
        for (b=1 b<=28 b+=1) {
            if (global.inv_item[b,0]=0) {lastno=b; b=29}
        }
        if (lastno=0) {
            return (1)
        } else {
            global.inv_item[lastno,0]=itemno
            global.inv_item[lastno,1]=number
        }
    }
} else {
    var lastno,n;
    lastno=0
    n=0
    repeat (number) {
        n+=1
        var a;
        for (a=1 a<=28 a+=1) {
            if (global.inv_item[a,0]=0) {lastno=a; a=29}
        }
        if (lastno=0) {
            return (number-n)
        } else {
            global.inv_item[lastno,0]=itemno
            global.inv_item[lastno,1]=1
        }
    }
}
return (0)
dan klik tanda centang

2.inventory_delete
Buat script>> Beri nama inventory_delete>>dan isikan kode di bawah ini
//Call:     inventory_delete(itemID,quantity)
//Info:     Delete the first item in the inventory with number itemID.
//          quantity is the number of that item you want to delete.
//Event:    Any
//Returns:  Whether the item you want to delete existed
//          in the inventory. (If you want to delete 10 items for example,
//          but you only have 3 in the inventory, none will be deleted and
//          it will return 0)

var itemno,number;
itemno=argument0
number=argument1

if (inventory_number(itemno)<number) {return (0)}

if (item_stackable(itemno)=1) {
    var a,deleteno;
    for (a=1 a<=28 a+=1) {
        if (global.inv_item[a,0]=itemno) {deleteno=a a=29}
    }
    global.inv_item[deleteno,1]-=number
    if (global.inv_item[deleteno,1]<=0) {
        global.inv_item[deleteno,0]=0
        global.inv_item[deleteno,1]=0
    }
} else {
    var a,deleted;
    deleted=0
    for (a=1 a<=28 a+=1) {
        if (global.inv_item[a,0]=itemno) {
            global.inv_item[a,0]=0
            global.inv_item[a,1]=0
            deleted+=1
        }
        if (deleted=number) {a=29}
    }
}
return (1)
dan klik tanda centang

3.inventory_draw
Buat script>> Beri nama inventory_draw>>dan isikan kode di bawah ini
//Call:     inventory_draw(x,y,spr,alpha,backgroundcol)
//Info:     This will draw the inventory on the given x and y position. spr is
//          the sprite you want the inventory to have, you can write -1 if you
//          don't want a sprite (like I have done). Alpha is the alpha of the
//          inventory and backgroundcol is the background color of the inventory
//          (only if you don't use a sprite).
//Event:    Draw
//Returns:  ---

var xx,yy,spr,alpha,bgcol;
xx=argument0
yy=argument1
spr=argument2
alpha=argument3
bgcol=argument4

draw_set_alpha(alpha)

//Draw sprite or inventory
if (sprite_exists(spr)) {
    draw_sprite_stretched(spr,-1,xx,yy,(xx+138)-xx,(yy+240)-yy)
} else {
    draw_set_color(bgcol)
    draw_rectangle(xx,yy,xx+138,yy+240,0)

    draw_set_alpha(1)
    draw_set_color(c_black)
    draw_rectangle(xx,yy,xx+138,yy+240,1)
}
draw_set_alpha(1)
draw_set_color(c_black)

var a,b,no;
a=0
b=0
no=1
if (global.inv_optionshow=0) {
    global.inv_select=0
}
repeat (7) {
    repeat (4) {
        var spr,index;
        spr=sItems
        index=global.inv_item[no,0]
        if (item_stackable(global.inv_item[no,0])=1) {spr=item_sprite(global.inv_item[no,0]); index=item_index(global.inv_item[no,1])}
        draw_rectangle(xx+2+(34*a),yy+2+(34*b),xx+2+(34*a)+32,yy+2+(34*b)+32,1)
        if ((global.inv_holditemno=no)=0) {
            draw_sprite(spr,index,xx+2+(34*a)+16,yy+2+(34*b)+16)
            if (item_stackable(global.inv_item[no,0])=1) {
                draw_set_font(fnt002)
                draw_set_color(c_black)
                draw_text(xx+1+(34*a)+2,yy+1+(34*b)+2,value_str(global.inv_item[no,1]))
                draw_set_color(c_aqua)
                draw_text(xx+1+(34*a)+1,yy+1+(34*b)+1,value_str(global.inv_item[no,1]))
                draw_set_color(c_black)
            }
        }
        if (mouse_x>=xx+(34*a) && mouse_x<=xx+(34*a)+34 && mouse_y>=yy+(34*b) && mouse_y<=yy+(34*b)+34 && global.inv_optionshow=0) {global.inv_select=no}
        a+=1
        no+=1
    }
    a=0
    b+=1
}

//Draw the held item
if (global.inv_holditem=true) {
    var spr,index;
    spr=sItems
    index=global.inv_item[global.inv_holditemno,0]
    if (item_stackable(global.inv_item[global.inv_holditemno,0])=1) {spr=item_sprite(global.inv_item[global.inv_holditemno,0]); index=item_index(global.inv_item[global.inv_holditemno,1])}
    draw_sprite_ext(spr,index,mouse_x,mouse_y,1,1,0,c_white,0.5)
    if (item_stackable(global.inv_item[global.inv_holditemno,0])=1) {
        draw_set_alpha(0.5)
        draw_set_font(fnt002)
        draw_set_color(c_black)
        draw_text(mouse_x-15,mouse_y-15,value_str(global.inv_item[global.inv_holditemno,1]))
        draw_set_color(c_aqua)
        draw_text(mouse_x-16,mouse_y-16,value_str(global.inv_item[global.inv_holditemno,1]))
        draw_set_color(c_black)
        draw_set_alpha(1)
    }
}
dan klik tanda centang

4.inventory_draw_infobox
Buat script>> Beri nama inventory_draw_infobox>>dan isikan kode di bawah ini
//Call:     inventory_draw_infobox(x,y,spr,alpha,backgroundcol)
//Info:     Draws the infobox, that will show some information about
//          the selected item. x and y is the position on the screen
//          to draw the box. spr is the sprite you want the info box to have,
//          you can write -1 if you don't want a sprite (like I have done).
//          Alpha is the alpha of the info box and backgroundcol is the
//          background color of the info box (only if you don't use a sprite).
//Event:    Draw
//Returns:  ---

var xx,yy,spr,alpha,bgcol;
xx=argument0
yy=argument1
spr=argument2
alpha=argument3
bgcol=argument4

draw_set_alpha(alpha)

//Draw infobox
if (sprite_exists(spr)) {
    draw_sprite_stretched(spr,-1,xx,yy,(xx+138)-xx,(yy+66)-yy)
} else {
    draw_set_color(bgcol)
    draw_rectangle(xx,yy,xx+138,yy+66,0)

    draw_set_alpha(1)
    draw_set_color(c_black)
    draw_rectangle(xx,yy,xx+138,yy+66,1)
    draw_rectangle(xx+2,yy+2,xx+136,yy+64,1)
}
draw_set_alpha(1)
draw_set_color(c_black)

//Set temporary variables
var invno,itemno,name,number;
if (global.inv_holditem=1) {invno=global.inv_holditemno} else {invno=global.inv_select}
itemno=global.inv_item[invno,0]
number=global.inv_item[invno,1]
name=item_name(itemno)
info=item_info(itemno)

//Draw the item's name
draw_set_font(fnt001)
draw_set_color(c_black)
draw_text(xx+6,yy+6,name)
draw_set_color(c_red)
draw_text(xx+5,yy+5,name)

draw_set_font(fnt002)
//If the item is stackable, draw the number
if (item_stackable(itemno)=1) {
    draw_set_color(c_blue)
    draw_text(xx+5,yy+17,"x"+string(number))
}
//Draw the item info
draw_set_color(c_black)
draw_text(xx+6,yy+38,info)
draw_set_color(c_yellow)
draw_text(xx+5,yy+37,info)
dan klik tanda centang

5.inventory_draw_optionbox
Buat script>> Beri nama inventory_draw_optionbox>>dan isikan kode di bawah ini
//Call:     inventory_draw_optionbox(x,y,spr,alpha,backgroundcol)
//Info:     Draws the optionbox of an item, that will show the options of
//          the selected item. x and y is the position on the screen
//          to draw the box. spr is the sprite you want the info box to have,
//          you can write -1 if you don't want a sprite (like I have done).
//          Alpha is the alpha of the option box and backgroundcol is the
//          background color of the option box (only if you don't use a sprite).
//Event:    Draw
//Returns:  ---

var xx,yy,spr,alpha,bgcol,optionstr,options,optionwidth;
xx=argument0
yy=argument1
spr=argument2
alpha=argument3
bgcol=argument4
options=0
draw_set_font(fnt003)
optionwidth=string_width(item_name(global.inv_optionitemno))

//Set temporary variables
var a;
for (a=1 a<=10 a+=1) {
    if (item_options(global.inv_optionitemno,a)="" or a=10) {
        options=a-1;
        a=11
    } else {
        optionstr[a]=item_options(global.inv_optionitemno,a)
        if (string_width(optionstr[a]+" "+item_name(global.inv_optionitemno))>optionwidth) {optionwidth=string_width(optionstr[a]+" "+item_name(global.inv_optionitemno))}
    }
}
draw_set_alpha(alpha)

//Draw sprite or box
if (sprite_exists(spr)) {
    draw_sprite_stretched(spr,-1,xx,yy,(xx+optionwidth+12)-xx,(yy+((options+1)*12)+10)-yy)
} else {
    draw_set_color(bgcol)
    draw_rectangle(xx,yy,xx+optionwidth+12,yy+((options+1)*12)+10,0)

    draw_set_alpha(1)
    draw_set_color(c_black)
    draw_rectangle(xx,yy,xx+optionwidth+12,yy+((options+1)*12)+10,1)
    draw_rectangle(xx+2,yy+2,xx+optionwidth+10,yy+((options+1)*12)+8,1)
}

draw_set_alpha(1)
draw_set_color(c_black)
if (mouse_x<xx-4 || mouse_x>xx+optionwidth+16 || mouse_y<yy-4 || mouse_y>yy+((options+1)*12)+10) {global.inv_optionshow=0}
global.inv_optionselect=0

//Draw text
var no,str;
for (no=1 no<=options+1 no+=1) {
    if (no=options+1) {str="Cancel"} else {str=optionstr[no]}
    if (mouse_x>=xx+2 && mouse_x<=xx+optionwidth+10 && mouse_y>=yy+6+(12*(no-1)) && mouse_y<=yy+6+(12*(no-1))+10) {global.inv_optionselect=no}
    draw_set_color(c_black)
    draw_text(xx+6,yy+6+(12*(no-1)),str)
    if (global.inv_optionselect=no) {draw_set_color(c_red)} else {draw_set_color(c_white)}
    draw_text(xx+5,yy+5+(12*(no-1)),str)
    if (no<options+1) {
        draw_set_color(c_black)
        draw_text(xx+6+string_width(str+" "),yy+6+(12*(no-1)),item_name(global.inv_optionitemno))
        if (global.inv_optionselect=no) {draw_set_color(c_red)} else {draw_set_color(c_yellow)}
        draw_text(xx+5+string_width(str+" "),yy+5+(12*(no-1)),item_name(global.inv_optionitemno))
    }
}
//Check if the user press an option
if (mouse_check_button_pressed(mb_left)) {
    if (global.inv_optionselect=0 || global.inv_optionselect=options+1) {global.inv_optionshow=0} else {item_options_code(global.inv_optionitemno,global.inv_optionselect); global.inv_optionshow=0}
    mouse_clear(mb_left)
}
dan klik tanda centang

5.inventory_switch
Buat script>> Beri nama inventory_switch>>dan isikan kode di bawah ini
//Call:     inventory_switch(no1,no2)
//Info:     This will switch item number no1 with item number
//          no2 in the inventory.
//Event:    Any
//Returns:  ---

var no1,no2,temp1,temp2;
no1=argument0
no2=argument1

if (no1=0 or no2=0) {exit;}
temp1=global.inv_item[no1,0]
temp2=global.inv_item[no1,1]
global.inv_item[no1,0]=global.inv_item[no2,0]
global.inv_item[no1,1]=global.inv_item[no2,1]
global.inv_item[no2,0]=temp1
global.inv_item[no2,1]=temp2

6.inventory_items
Buat script>> Beri nama inventory_items>>dan isikan kode di bawah ini
//Call:     inventory_items()
//Info:     Returns the number of items in the inventory.
//Event:    Any
//Returns:  The number of items in the inventory.

var a,no;
no=0
for (a=1 a<=28 a+=1) {
    if (global.inv_item[a,0]>0) {no+=1}
}
return (no)
dan klik tanda centang

7.inventory_//Call:     inventory_number(itemID)
//Info:     Returns the number of items with number itemID.
//Event:    Any
//Returns:  The number of items with number itemID. (0 if there is none)

var itemno,number;
itemno=argument0
number=0

if (item_stackable(itemno)=1) {
    var invno,a;
    invno=0
    for (a=1 a<=28 a+=1) {
        if (global.inv_item[a,0]=itemno) {invno=a; a=29}
    }
    if (invno=0) {return (0); exit} else {number=global.inv_item[invno,1]}
} else {
    var a,no;
    no=0
    for (a=1 a<=28 a+=1) {
        if (global.inv_item[a,0]=itemno) {no+=1}
    
    number=no
}
return (number)
dan klik tanda centang

Buatlah folder grup dengan nama Item scripts dan masukan scripts dibawah ini ke folder grup Item scripts

1.item_name
Buat script>> Beri nama item_name>>dan isikan kode di bawah ini
//Call:     item_name(itemID)
//Info:     Returns with the name of item itemID.
//Event:    Any
//Returns:  The name of item no.

var no,name;
no=argument0
name=""

if (no=1) {name="Money"}
if (no=2) {name="Wooden axe"}
if (no=3) {name="Iron axe"}
if (no=4) {name="Old key"}
if (no=5) {name="Uncooked fish"}
if (no=6) {name="Cooked fish"}
if (no=7) {name="Wooden arrows"}
if (no=8) {name="Cheese"}
if (no=9) {name="Piece of paper"}
if (no=10) {name="Paper ball"}
if (no=11) {name=""}

return (name)
dan klik tanda centang

2.item_options
Buat script>> Beri nama item_options>>dan isikan kode di bawah ini
//Call:     item_options(itemID,optionno)
//Info:     Returns with item itemID's option string.
//Event:    Any
//Returns:  Option number optionno's string.

var no,no1,option;
no=argument0
no1=argument1
option=""

if (no=1) {
    if (no1=1) {option="Drop"}
}
if (no=2) {
    if (no1=1) {option="Wear"}
    if (no1=2) {option="Drop"}
}
if (no=3) {
    if (no1=1) {option="Wear"}
    if (no1=2) {option="Drop"}
}
if (no=4) {
    if (no1=1) {option="Drop"}
}
if (no=5) {
    if (no1=1) {option="Drop"}
}
if (no=6) {
    if (no1=1) {option="Eat"}
    if (no1=2) {option="Drop"}
}
if (no=7) {
    if (no1=1) {option="Wear"}
    if (no1=2) {option="Drop"}
}
if (no=8) {
    if (no1=1) {option="Eat"}
    if (no1=2) {option="Smell at"}
    if (no1=3) {option="Drop"}
}
if (no=9) {
    if (no1=1) {option="Read"}
    if (no1=2) {option="Smell at"}
    if (no1=3) {option="Sing to"}
    if (no1=4) {option="Throw away"}
    if (no1=5) {option="Attack"}
    if (no1=6) {option="Look at"}
    if (no1=7) {option="Listen to"}
    if (no1=8) {option="Eat"}
    if (no1=9) {option="Drop"}
}
if (no=10) {
    if (no1=1) {option="Drop"}
}

return (option)
dan klik tanda centang

3.item_options_code
Buat script>> Beri nama item_options_code>>dan isikan kode di bawah ini
//Call:     item_options_code(itemID,optionno)
//Info:     Sets what will happen when you click option optiono
//          in the selecte item.
//Event:    Any
//Returns:  ---

var no,no1;
no=argument0
no1=argument1

if (no=1) {
    if (no1=1) {drop_item(global.inv_select)}   //Drop
}
if (no=2) {
    if (no1=1) {show_message("Wear!")}          //Simple message
    if (no1=2) {drop_item(global.inv_select)}   //Drop
}
if (no=3) {
    if (no1=1) {show_message("Wear!")}          //Simple message
    if (no1=2) {drop_item(global.inv_select)}   //Drop
}
if (no=4) {
    if (no1=1) {drop_item(global.inv_select)}   //Drop
}
if (no=5) {
    if (no1=1) {drop_item(global.inv_select)}   //Drop
}
if (no=6) {
    if (no1=1) {oPlayer.hp+=20 global.inv_item[global.inv_select,0]=0 global.inv_item[global.inv_select,1]=0} //add hp and remove item
    if (no1=2) {drop_item(global.inv_select)}   //Drop
}
if (no=7) {
    if (no1=1) {show_message("Wear!!")}         //Simple message
    if (no1=2) {drop_item(global.inv_select)}   //Drop
}
if (no=8) {
    if (no1=1) {oPlayer.hp+=10 global.inv_item[global.inv_select,0]=0 global.inv_item[global.inv_select,1]=0} //add hp and remove item
    if (no1=2) {show_message("It smells good!")}//Simple message
    if (no1=3) {drop_item(global.inv_select)}   //Drop
}
if (no=9) {
    if (no1=1) {show_message("It says:#Please give credit to Davve941018 if you use this example!")}
    if (no1=2) {show_message("Um... why would you wanna do that?")}
    if (no1=3) {show_message("What's the point with that?")}
    if (no1=4) {global.inv_item[global.inv_select,0]=0 global.inv_item[global.inv_select,1]=0}
    if (no1=5) {global.inv_item[global.inv_select,0]=10}
    if (no1=6) {show_message("It's just a piece of paper...")}
    if (no1=7) {show_message("Nothing interesting happens.")}
    if (no1=8) {oPlayer.hp+=1 global.inv_item[global.inv_select,0]=0 global.inv_item[global.inv_select,1]=0}
    if (no1=9) {drop_item(global.inv_select)}
}
if (no=10) {
    if (no1=1) {drop_item(global.inv_select)}   //Drop
}
dan Klik tanda centang

4.item_info
Buat script>> Beri nama item_info>>dan isikan kode di bawah ini
//Call:     item_info(itemID)
//Info:     Returns with some info of item itemID.
//Event:    Any
//Returns:  The info of item itemID.

var no,name;
no=argument0
name=""

if (no=1) {name="Sweet, sweet money!"}
if (no=2) {name="A weak axe made out of#wood."}
if (no=3) {name="An axe made out of iron."}
if (no=4) {name="An old, rusty key."}
if (no=5) {name="Some newly caught fish!"}
if (no=6) {name="Yummy!"}
if (no=7) {name="Some weak wooden arrows."}
if (no=8) {name="It's a cheese."}
if (no=9) {name="Just a piece of paper."}
if (no=10) {name="This was once a piece#of paper."}
if (no=11) {name=""}

return (name)
dan klik tanda centang

5.item_stackable
Buat script>> Beri nama item_stackable>>dan isikan kode di bawah ini
//Call:     item_stackable(itemID)
//Info:     Returns whether item itemID is stackable or not.
//          (money is stackable for example)
//Event:    Any
//Returns:  If the selected item is stackable (1=yes, 0=no)

var no,stackable;
no=argument0
stackable=0

if (no=1) {stackable=1}
if (no=2) {stackable=0}
if (no=3) {stackable=0}
if (no=4) {stackable=0}
if (no=5) {stackable=0}
if (no=6) {stackable=0}
if (no=7) {stackable=1}
if (no=8) {stackable=0}
if (no=9) {stackable=0}
if (no=10) {stackable=0}

return (stackable)
dan klik tanda centang

6.item_sprite
Buat script>> Beri nama item_sprite>>dan isikan kode di bawah ini
//Call:     item_sprite(itemID)
//Info:     Returns the sprite of a stackable item
//Event:    Any
//Returns:  The sprite of a stackable item

var no,spr;
no=argument0
spr=-1

if (no=1) {spr=sMoney}
if (no=7) {spr=sWoodenArrows}

return (spr)
dan klik tanda centang

7.item_index
Buat script>> Beri nama item_index>>dan isikan kode di bawah ini
//Call:     item_index(value)
//Info:     Returns the index on a stackable item depending
//          on the value. (if you have 1000 money, it is displayed
//          as a big money pile instead of a small)
//Event:    Any
//Returns:  The image index of a stackable item no depending on the value

var no,value,index;
value=argument0
index=0

if (value=1) {index=0}
if (value>=2) {index=1}
if (value>=5) {index=2}
if (value>=20) {index=3}
if (value>=200) {index=4}
if (value>=1000) {index=5}

return (index)
dan klik tanda centang

Script yang ada di bawah ini tidak usah dimasukkan file group

1.value_str
Buat script>> Beri nama value_str>>dan isikan kode di bawah ini
//Call:     value_str(value)
//Info:     Returns with the string of value.
//          (13,349,123 is displayed as 13M for example)
//Event:    Any
//Returns:  The str of value.

var val,str;
val=argument0
str=string(val)

if (val>=100000) {str=string_copy(string(val),1,3)+"K"}
if (val>=1000000) {str=string_copy(string(val),1,4)+"K"}
if (val>=10000000) {str=string_copy(string(val),1,2)+"M"}
if (val>=100000000) {str=string_copy(string(val),1,3)+"M"}
if (val>=1000000000) {str=string_copy(string(val),1,4)+"M"}

return (str)
dan klik tanda centang

2.drop_item
Buat script>> Beri nama drop_item>>dan isikan kode di bawah ini
//Call:     drop_item(invno)
//Info:     This will create a oItemOnGround object on the
//          players position with the selected item's variables.
//Event:    Any
//Returns:  ---

var invno,obj;
invno=argument0
obj=instance_create(oPlayer.x+16,oPlayer.y,oItemOnGround)

obj.item=global.inv_item[invno,0]
obj.number=global.inv_item[invno,1]
global.inv_item[invno,0]=0
global.inv_item[invno,1]=0
dan klik tanda centang

FONT

1.fnt001
Buat font>> Beri nama font001>>ganti ukurang font 10>>ganti font jadi Terminal

2.fnt002
Buat font>> Beri nama font002>>ganti ukurang font 7>>ganti font jadi Comic Sans MS

3.fnt003
Buat font>> Beri nama font003>>ganti ukurang font 10>>ganti font jadi Arial

OBJECT

1.oInventory
Buat object>>Beri nama oInventory>> no sprite>>Depth -100000>>klik Persistent.
Add event>>Step>>Step>>Pilih control>>Klik execute code>> Isi code dibawah ini
room_caption=string(floor((fps/room_speed)*100))+"%"
if (mouse_check_button(mb_left) && global.inv_optionshow=0) {   //Check if we want to drag an item
    if (global.inv_holditem=false && global.inv_select>0) {
        global.inv_holditem=true
        global.inv_holditemno=global.inv_select
    }
}
if (!mouse_check_button(mb_left) && global.inv_holditem=true && global.inv_optionshow=0) {  //Puts down the dragged item if we release left mouse button.
    if (global.inv_select>0) {
        inventory_switch(global.inv_select,global.inv_holditemno)
    }
    global.inv_holditem=false
    global.inv_holditemno=0
}
if (mouse_check_button_pressed(mb_right) && global.inv_holditem=false && global.inv_select>0 && global.inv_optionshow=0 && global.inv_item[global.inv_select,0]>0) {    //Create option-box if we right click
    global.inv_optionshow=true
    global.inv_optionitemno=global.inv_item[global.inv_select,0]
    global.inv_optionx=mouse_x-view_xview
    global.inv_optiony=mouse_y-view_yview
}

Add event>>other>>game start>>execute code>>isikan code dibawah ini
global.inv_select=0         //What item in the inventory the cursor is hovering over

global.inv_holditem=false   //Whether we are holding an item or not
global.inv_holditemno=0     //The inventory number of the item we are holding

global.inv_optionshow=false //If we are looking at an item's options or not
global.inv_optionx=0        //x position of the options box
global.inv_optiony=0        //y position of the options box
global.inv_optionitemno=0   //ID of the selected item
global.inv_optionselect=0   //Selected option

var a;
for (a=0 a<=28 a+=1) {
    global.inv_item[a,0]=0    //The item's ID
    global.inv_item[a,1]=0    //The item's quantity
}

Add event>>draw>>execute code>> isikan code dibawah ini
draw_set_font(fnt001)
inventory_draw_infobox(view_xview+16,view_yview+268,-1,0.5,c_aqua)  //Draw the info box
inventory_draw(view_xview+16,view_yview+16,-1,0.5,c_aqua)           //Draw the inventory
if (global.inv_optionshow=1) {inventory_draw_optionbox(view_xview+global.inv_optionx,view_yview+global.inv_optiony,-1,0.75,c_aqua)}     //Draw the option box

2.oPlayer
Buat object>>Beri nama oPlayer>>spr_down
Add event>>Create>>Klik control>>execute code>>dan isikan kode dibawah ini
hp=10   //Create HP variable

Add event>>Step>>Step>>execute code>>dan isikan kode dibawah ini
//Simple control codes
depth=-y
x+=keyboard_check(vk_right)*4
x-=keyboard_check(vk_left)*4
y+=keyboard_check(vk_down)*4
y-=keyboard_check(vk_up)*4

//bergerak ke kanan
if keyboard_check_pressed(vk_right) //jika tombol panah kanan ditekan
{ //maka
sprite_index=spr_right //ganti sprite menjadi spr_right
}

if keyboard_check_pressed(vk_left)
{
sprite_index=spr_left
}

if keyboard_check_pressed(vk_up)
{
sprite_index=spr_up
}

if keyboard_check_pressed(vk_down)
{
sprite_index=spr_down
}

if keyboard_check(vk_nokey){
    image_speed = 0
}else{
    image_speed = 0.2
}

Add event>> Keyboard>>no key>> Set Variable>>Variable :image_speed>>Value: 0
Add event>>draw>>execute code>>isikan kode di bawah ini
//Draw hp above head
if hp>100 {hp=100}
draw_set_font(fnt002)
draw_set_halign(fa_center)
draw_set_color(c_black)
draw_text(x+16,y-31,"HP: "+string(hp)+"/100")
draw_set_color(c_red)
draw_text(x+17,y-32,"HP: "+string(hp)+"/100")
draw_set_halign(fa_left)
draw_sprite(sprite_index,image_index,x,y)

3.oItemOnGround
Buat object>>Beri nama oItemOnGround>>Depth 10
Add event>>Create>>Klik control>>execute code>> dan isikan kode di bawah ini
//This is so we dont get some stupid error messages
visible=0
alarm[0]=1

Add event>>Alarm>>Alarm 0>>execute code>>dan isikan kode di bawah ini
visible=1
//Set the image to the selected item
image_speed=0
image_index=item
sprite_index=sItems

if (item_stackable(item)=1) {sprite_index=item_sprite(item) image_index=item_index(number)}

Add event>>Collision>>oPlayer>>execute code>>dan isikan kode di bawah ini
//Pick up the selected item
if (global.inv_select=0) {
    inventory_add(item,number)
    instance_destroy()
}

4.oDoor
Buat object>>oPort>>Depth 10
Add event>>Collision>>oPlayer>>execute code>>dan isikan kode di bawah ini
//Move player out of collision
other.x=other.xprevious
other.y=other.yprevious

if (inventory_number(4)>0) {        //Check if "old key" exists in the inventory (it have ID 4)
    if show_question("Apa kamu yakin ingin membuka pintu dengan kunci ini!"){
    inventory_delete(4,1)           //Delete old key
    room_goto_next()
    }
} else {
    show_message("Kamu harus mempunyai kunci untuk membuka pintu ini!")
}

Room

Buat Room>>Beri nama stage 1>>Ubah snap X dan Y jadi 16>>pilih view>>Object following oPlayer
Dan mainkan dengan menekan F5

Kalau pengen belajar dengan file GMKnya bisa didownload disini

Semoga bermanfaat :D

NB:Kalau ingin mengkopas harus ada link sumbernya

Tidak ada komentar :

Posting Komentar