GameMaker: Studio

GameMaker: Studio

View Stats:
Horsecock Mar 14, 2015 @ 3:01pm
Can anyone help me code enemy item drops?
Ok so recently i've started work on my first game. I am using online tutorials to help me learn how to code. However in the game i am making at the moment is supposed to have an item drop feature. Let me describe what id like to code :

Killed enemys keep their corpses until searched for items or fade on their own after 60 seconds.
After searching for items (or 60 seconds after death) the corpse will fade away.
To search the corpse you would have to press "E" on the corpse you want to search.
Once you press "E" while aiming at the corpse, an inventory menu with 2 sides will open up.
One side will have your items and the other side will have the corpse's items.
You will have to click and drag the items individually to move them into your inventory.
However i would like to include a chance feature.
Every normal enemy will have a 75% chance of dropping $5.
Every advanced enemy will have a 100% chance of dropping $10, a 100% chance of dropping silver (which can later be sold at a shop) and a 50% chance of dropping $25.
Every boss will have a 50% chance at dropping metal (which can later be sold at a shop)
A day and night feature where days are 10 minutes and enemies spawn more than the amount of enemies that spawn at night. Nights are 8 minutes long.
There will be 5 nights and 6 days then the game will end and you will return to the main menu after credits.
During the first day 12 enemies spawn per minute and 2 advanced enemies during the last minute
During the first night 9 enemies spawn per minute and 1 advanced enemy during the last minute
After every day and night id like to make more enemies spawn the next day/night cycle.
I also need to code an inventory.

So that list has the things that i want to code... Yeah i know it is A LOT but you dont have to specifically tell me the code (unless you know it right off the top of your head) so you can send me a link to a video explaining these things to me IF you would take the time to do that. Sorry if i wasted your time and thank you for helping if you did.
< >
Showing 1-2 of 2 comments
Blind Mar 14, 2015 @ 4:15pm 
That's not a lot - you're among the first people to actual post what you want in a proper level of detail. Other people should take note.

First off, you need a corpse object - which may or may not be a subimage of a basic enemy, but lets assume corpses are a unique object.

Corpse:Create alarm[0]=room_speed*60
This sets alarm[0] to 60 seconds in length regardless of your room speed.

Corpse:Alarm[0]
decay=true

Step:
If decay=true image_alpha=min(image_alpha, image_alpha-.1)
if image_alpha <0 instance_destroy()

when your corpse expires it begins to fade out until it is eventually destroyed.


On either your player character, or a separate control module
On Collision with Corpse:
if keyboard_check_pressed(ord("E")) {
if other.decay=false script_lootdialog(other)
}

I'll assume you have some sort of looting dialoge, what this does is only checks for the pressing of E when you are in collision with a corpse, and returns the ID of the corpse to the argument list of script_lootdialog. This means that the inventory of corpse becomes available for the lootdialog. This also means if 2 or more corpses occupy the same space you'll only get the ID of the most recent one.

It also checks if your monster isn't in the process of decaying at the time.

Click and Drag for your script_lootdialog will be up to you, I don't work with mice so I never tried this.

The inventory of the corpse is created when they die. to create a specific corpse (such as a goblin corpse or a generic skeleton for a goblin monster), in your Goblin's DEATH routine you would do something like
bop = instance_create(x,y,corpse)
with(bop){
switch(other.rank){
case 0: if irandom(100) >= 75 item[1] = "$5";break
case 2:
if irandom(100)>=50 item[4]="Metal"
case 1:
item[3]="$10"
item[2]="Silver"
if irandom(100)>=50 item[1]="$25";break
}
}

What this does is loads the id of the corpse with a variety of loot based on rank. other.rank is used, because in a with statement the caller becomes the other. If rank is 0, low rank, your money is dropped and stopped. Case 2 (boss) is above case 1 without a break - this is a heirarchy. This means a boss is also an advanced enemy and would also have a chance at dropping the high rank (1) items.

This loads an array called item[x] with a variety of trinkets. Notice I load my array in reverse (4, 3, 2, 1) - this speeds up the math as arrays need to be restructured if you expand them, starting with 4 means you don't need to expand down.

Afterwards, your corpse will have items[0~whatever] set. in your script_lootdialoge you would scan for corpse.item[x] to find if anything is NON-ZERO and add it to your inventory. I made all my items "Strings", which may not be applicable - use best judgement.
Horsecock Mar 14, 2015 @ 4:31pm 
Originally posted by BBX:
That's not a lot - you're among the first people to actual post what you want in a proper level of detail. Other people should take note.

First off, you need a corpse object - which may or may not be a subimage of a basic enemy, but lets assume corpses are a unique object.

Corpse:Create alarm[0]=room_speed*60
This sets alarm[0] to 60 seconds in length regardless of your room speed.

Corpse:Alarm[0]
decay=true

Step:
If decay=true image_alpha=min(image_alpha, image_alpha-.1)
if image_alpha <0 instance_destroy()

when your corpse expires it begins to fade out until it is eventually destroyed.


On either your player character, or a separate control module
On Collision with Corpse:
if keyboard_check_pressed(ord("E")) {
if other.decay=false script_lootdialog(other)
}

I'll assume you have some sort of looting dialoge, what this does is only checks for the pressing of E when you are in collision with a corpse, and returns the ID of the corpse to the argument list of script_lootdialog. This means that the inventory of corpse becomes available for the lootdialog. This also means if 2 or more corpses occupy the same space you'll only get the ID of the most recent one.

It also checks if your monster isn't in the process of decaying at the time.

Click and Drag for your script_lootdialog will be up to you, I don't work with mice so I never tried this.

The inventory of the corpse is created when they die. to create a specific corpse (such as a goblin corpse or a generic skeleton for a goblin monster), in your Goblin's DEATH routine you would do something like
bop = instance_create(x,y,corpse)
with(bop){
switch(other.rank){
case 0: if irandom(100) >= 75 item[1] = "$5";break
case 2:
if irandom(100)>=50 item[4]="Metal"
case 1:
item[3]="$10"
item[2]="Silver"
if irandom(100)>=50 item[1]="$25";break
}
}

What this does is loads the id of the corpse with a variety of loot based on rank. other.rank is used, because in a with statement the caller becomes the other. If rank is 0, low rank, your money is dropped and stopped. Case 2 (boss) is above case 1 without a break - this is a heirarchy. This means a boss is also an advanced enemy and would also have a chance at dropping the high rank (1) items.

This loads an array called item[x] with a variety of trinkets. Notice I load my array in reverse (4, 3, 2, 1) - this speeds up the math as arrays need to be restructured if you expand them, starting with 4 means you don't need to expand down.

Afterwards, your corpse will have items[0~whatever] set. in your script_lootdialoge you would scan for corpse.item[x] to find if anything is NON-ZERO and add it to your inventory. I made all my items "Strings", which may not be applicable - use best judgement.
Thank you very much! This was extremely helpful.
< >
Showing 1-2 of 2 comments
Per page: 1530 50

Date Posted: Mar 14, 2015 @ 3:01pm
Posts: 2