• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Kill Streak / Combo Timer

S

sivispacem

Guest
I wanted to post some code to assist others and to seek refinement.
I humbly admit I am a beginner and that there is likely a better way to code for this than I have presented.
However, it does work. Please feel free to comment and/or modify.

1) Created an object - obj_kill_streak - persistent - placed in title room

2) obj_kill_streak - Create
GML:
/// @desc Init Vars for Kill Streak
global.total_kills = 0;
global.kill_streak = 0;
global.kill_points_add = 0;
global.kill_streak_bonus = 0;
global.kill_streak_state = false;
//give a bonus to the timer based on kill streak and difficulty level
{
    if(global.kill_streak <= 14)
    {global.kill_streak_bonus = 0}
    else if(global.kill_streak >= 15) and (global.kill_streak < 29)
    {global.kill_streak_bonus = 0.5}
    else if(global.kill_streak >= 30) and (global.kill_streak < 64)
    {global.kill_streak_bonus = 1}
    else if(global.kill_streak >= 65) and (global.kill_streak < 99)
    {global.kill_streak_bonus = 1.5}
    else if(global.kill_streak >= 100)
    {global.kill_streak_bonus = 2}
    else {exit};
}
global.kill_streak_timer = (room_speed * (3 + global.kill_streak_bonus));
3)obj_kill_streak - Step
GML:
/// @desc Logic for Checking Player Kills in x Time
if(global.kill_streak_timer > 0)
{
    //obj_enemy_parent user events (damage/destroy) add to global.total_kills
    //obj_enemy_parent user events (damage/destroy) add to global.skill_streak
    global.kill_points_add = global.kill_streak;
    //global timer is reset in obj_enemy_parent user events (damage/destroy)
    global.kill_streak_state = true;
}
else
{
    global.player_1_score += global.kill_points_add;
    alarm[0] = 1;
    //set kill streak and points added to zero in alarm[0]
}
//count timer down and keep at zero if no qualifying event
global.kill_streak_timer -= 1;
if(global.kill_streak_timer <= 0)
{global.kill_streak_timer = 0};
4)obj_kill_streak - Alarm[0]
GML:
/// @desc Set Kill Streak and Points Added to Zero
global.kill_streak = 0;
global.kill_points_add = 0;
global.kill_streak_state = false;
5) In the Destroy events for the enemy parent/objects (however you choose)
GML:
{
    global.total_kills +=1;
    global.kill_streak +=1;
    global.kill_streak_timer = (room_speed * (3 + global.kill_streak_bonus));
}
I used global variables because I am drawing to the GUI in a separate object, and, yes, I can use with but this was easier for me.
1611260714460.png 1611260734305.png
 

FrostyCat

Redemption Seeker
Tell me what your global.kill_streak_bonus should be when global.kill_streak is 29, 64 or 99. See an issue?

DO NOT write two-ended ranges the way you just did, it's just too easy to screw up. Specify just one end of the range and let else handle the rest.
GML:
if (global.kill_streak < 15) {
    global.kill_streak_bonus = 0;
} else if (global.kill_streak < 30) {
    global.kill_streak_bonus = 0.5;
} else if (global.kill_streak < 65) {
    global.kill_streak_bonus = 1;
} else if (global.kill_streak < 100) {
    global.kill_streak_bonus = 1.5;
} else {
    global.kill_streak_bonus = 2;
}
else can also form ladders with multiple if conditions to make them mutually exclusive. When writing subsequent conditions, remember to take advantage of what getting to the point of else has already ruled out.
GML:
if (score <= 100) {
    audio_play_sound(snd_yousuck, 1, false);
} else if (score <= 200) {
    audio_play_sound(snd_couldbebetter, 1, false);
} else {
    audio_play_sound(snd_yourock, 1, false);
}
 
S

sivispacem

Guest
That is my oversight, thank you for pointing it out. I thought I had all >= or <=.
Fixed as you have suggested.
 
Top