• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Legacy GM Kill Feed

Gamerev147

Member
How would I come about making a kill feed?

When I kill an enemy in my game I would like it to show in the top right corner that I killed the enemy (but show its id).

How could I do this? All help is appreciated! :)
Thanks in advance!
 
Does your game contain different types of enemies? I would create a parent object of all enemies and a GUI object. GUI object will have a variable for example "text". I guess your enemies have health so in this object I would basically check if you killed an enemy and that set the text variable as ID of this enemy.

Creating the text variable in the GUI object (Create Event):
Code:
text = "";
Checking for death of an enemy in the parent object (Step Event):
Code:
if (health <= 0)
{
    GUI.text = string(id);
}
Drawing the text variable in the GUI object (Draw Event):
Code:
draw_text(x, y, "You have slain an enemy: " + text);
 

Gamerev147

Member
Does your game contain different types of enemies? I would create a parent object of all enemies and a GUI object. GUI object will have a variable for example "text". I guess your enemies have health so in this object I would basically check if you killed an enemy and that set the text variable as ID of this enemy.

Creating the text variable in the GUI object (Create Event):
Code:
text = "";
Checking for death of an enemy in the parent object (Step Event):
Code:
if (health <= 0)
{
    GUI.text = string(id);
}
Drawing the text variable in the GUI object (Draw Event):
Code:
draw_text(x, y, "You have slain an enemy: " + text);
I found this by messing around for a bit... But my issue now is what happens when I kill multiple enemies in a short amount of time?
The GUI would be updating and displaying that I killed the next enemy.

How could I make it so it would be like this:

> [Username] has killed [Enemy_ID]
> [Username] has killed [Enemy_ID_2]
> [Username] has killed [Enemy_ID_3]
> ETC...

Would I have to create a list of something somehow? And if so, how could I do that?
 

John Andrews

Living Enigma
You could use objects for that but that'd be very unnecesary I'll let the most experienced people talk in this case, but if you want to know how I'd do it tell me I'd gladly help
 
Here is my quick solution:

You can create 2 lists:
Code:
text = ds_list_create();
alpha = ds_list_create();
Than if you kill an enemy add text into the text list and set it's alpha to 1:
Code:
ds_list_add(GUI.text, string(id);
ds_list_add(GUI.alpha, 1);
In the GUI's step subtract alpha of each text:
Code:
for (var i = 0; i < ds_list_size(text); i++)
{
    alpha[| i] -= 0.01;
 
    if (!alpha[| i])
    {
        ds_list_delete(text, i);
        ds_list_delete(alpha, i);
    }
}
And here is how to draw from the text list with it's alpha:
Code:
for (var i = 0; i < ds_list_size(text); i++)
{
    draw_set_alpha(alpha[| i]);
    draw_text(x, y + 16 * i, "You have slain an enemy:" + text[| i]);
}
You are going to get something like that:
list.png
 
Last edited:

Gamerev147

Member
Here is my quick solution:

You can create 2 lists:
Code:
text = ds_list_create();
alpha = ds_list_create();
Than if you kill an enemy add text into the text list and set it's alpha to 1:
Code:
ds_list_add(GUI.text, string(id);
ds_list_add(GUI.alpha, 1);
In the GUI's step subtract alpha of each text:
Code:
for (var i = 0; i < ds_list_size(text); i++)
{
    alpha[| i] -= 0.01;
 
    if (!alpha[| i])
    {
        ds_list_delete(text, i);
        ds_list_delete(alpha, i);
    }
}
And here is how to draw from the text list with it's alpha:
Code:
for (var i = 0; i < ds_list_size(text); i++)
{
    draw_set_alpha(alpha[| i]);
    draw_text(x, y + 16 * i, "You have slain an enemy:" + text[| i]);
}
You are going to get something like that:
View attachment 11193
Awesome! That worked great! :)
Thank you so much!
 

Gamerev147

Member
No problem, if you want to change the speed of disappearance just change 0.01 to whatever you want. But I guess you figured it out by yourself ;).
Slight issue.... The text is being drawn perfectly fine at the X position I've given, but since Y is being multiplied by X to "stack" the text, it won't draw where I want it.
How could I fix this?
 
Slight issue.... The text is being drawn perfectly fine at the X position I've given, but since Y is being multiplied by X to "stack" the text, it won't draw where I want it.
How could I fix this?
Yes you can draw only several messages by changing this:
Code:
i < ds_list_size(text);
For example to this:
Code:
i < clamp(ds_list_size(text), 0, 5);
Now it will draw only first 5 messages but at the end it will still show all because they continuously disappear.
 
Last edited:
Top