GM:S 1.4 Kill Feed

Discussion in 'Programming' started by Gamerev147, Jul 19, 2017.

  1. Gamerev147

    Gamerev147 Member

    Joined:
    Sep 12, 2016
    Posts:
    444
    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!
     
  2. VectorStudio

    VectorStudio Member

    Joined:
    Jul 19, 2017
    Posts:
    20
    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);
     
  3. Gamerev147

    Gamerev147 Member

    Joined:
    Sep 12, 2016
    Posts:
    444
    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?
     
  4. John Andrews

    John Andrews Living Enigma

    Joined:
    Oct 28, 2016
    Posts:
    277
    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
     
  5. VectorStudio

    VectorStudio Member

    Joined:
    Jul 19, 2017
    Posts:
    20
    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: Jul 19, 2017
    John Andrews and Gamerev147 like this.
  6. Gamerev147

    Gamerev147 Member

    Joined:
    Sep 12, 2016
    Posts:
    444
    Awesome! That worked great! :)
    Thank you so much!
     
  7. VectorStudio

    VectorStudio Member

    Joined:
    Jul 19, 2017
    Posts:
    20
    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 ;).
     
    Gamerev147 likes this.
  8. Gamerev147

    Gamerev147 Member

    Joined:
    Sep 12, 2016
    Posts:
    444
    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?
     
  9. VectorStudio

    VectorStudio Member

    Joined:
    Jul 19, 2017
    Posts:
    20
    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: Jul 20, 2017

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice