• 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!

Randomizing multiple instances of the same object - GML

Hi everyone. I'm pretty new here but I have a question that I was unable to find anywhere.

I am working on a multiplayer side-scroller roguelite, and I am having an issue randomizing rolls. I currently have two players I have created, and if they both swing their sword on the frame, they will get the same damage roll. How do I go about randomizing these rolls?
For context, here are my damage calculations. baseattackdamage is a global variable to set the players to as they begin, and playerdamageincrease will be the modifier from items.
GML:
critcheck = (irandom_range(0,100)/100)
damage = irandom_range(baseattackdamage*playerdamageincrease*.95,baseattackdamage*playerdamageincrease*1.05)

if critcheck < playercritchance {
    doesitcrit = true;
    damage = damage*playercritdamage;
}
if critcheck > playercritchance {
    doesitcrit = false;
}
this works great for getting a random number from 95% to 105% of their attack range.

However, the probem I am encountering is that if player1 and player 2 swing their sword on the same frame, they will both get the same number (if they dont have modifiers applied), and they will both always crit.

How do I get the rolls to be independent from each other?

I have tried adding randomise(), random_set_seed(date_current_datetime()), as well as random_get_seed(), but none of this fixes that issue.

Thanks in advance!
 
Update: I think this might have something to do with my hitbox object. I noticed that if I position the players in a way so that player 1 will swing their sword and hit an enemy (damage number pops up confirming) and player 2 swings their sword and hits nothing, if it is on the same frame, they will both create the damage popup. Also, sometimes the popup appears TWICE.


STEP event
GML:
//attack 1
if (keyboard_check_pressed(ord("O"))
    &&  attackavailable = true
    &&  attacknumber = 1
    &&  playerdirection = "right"){
        image_index = 0;
        sprite_index = playerattackright1;
        attacktimer = 0;
        attackavailable = false;
        attackbuffer = 0;
        audio_play_sound(snd_swordswing1,1,false);
        var hitboxcreation =  (instance_create_layer(x,y,"Hitboxes",obj_playerhitbox)){
                hitboxcreation.id_of_origin = other.id;
                hitboxcreation.damage = other.damage
                hitboxcreation.attacknumber = other.attacknumber
                hitboxcreation.playerdirection = other.playerdirection
                hitboxcreation.doesitcrit = other.doesitcrit

        };
                attacknumber = 2;
}


STEP event
GML:
//Hitbox creation
if (attacknumber = 1 && playerdirection = "right"){
    sprite_index = righthitbox1; //matching the correct hitbox to the correct attack animation
    }

GML:
if (place_meeting (x, y, obj_playerhitbox) && self.currenthealth >0){
    obj_playerhitbox.hitregistered = true;
    timesincelasthit = 1.5
    with (obj_playerhitbox){
        if (other.currenthealth - self.damage) > 0{
            other.hurt = true
            other.doesitcrit = self.doesitcrit
            alarm[2] = .05*room_speed;
            //vspeed = -3
            //hspeed = 20
            scr_sound(other.impactsound);
            if (self.x - other.x)>0 {
                motion_add(150,5)
            }
            if (self.x - other.x)<0 {
            motion_add(30,5)  
            }
        }
        other.currenthealth = other.currenthealth - self.damage;
        repeat (3){
            instance_create_layer(x,y,"Instances", obj_blood);
        }
        var damagepopup = instance_create_layer(x,y-20,"HUD",obj_damagepopup)
        damagepopup.damageamount = self.damage
        with (obj_playerhitbox) {
            damagepopup.damageamount = self.damage
            damagepopup.doesitcrit = self.doesitcrit}
    }
}

damage popup CREATE event
GML:
gravity = .5;
motion_add(irandom_range(65,105),9);
alarm[0] = room_speed/2.6;
alpha = 1;
damage popup STEP event:
GML:
if instance_exists(obj_damagepopup){
    motion_add(270,.01)
}
if hspeed > 2{
    hspeed = 2
}
if hspeed < -2 {
    hspeed = -2
}
if gravity = 0 {
        alpha -= 2/room_speed
}
if gravity = 0 {
    hspeed = hspeed/1.5
}
if alpha <= 0 {
    instance_destroy()
}
self.depth = self.depth+1
damage popup draw event:
GML:
draw_set_alpha(alpha)
if doesitcrit = false{
    draw_set_font(fnt_damagetext)
}
if doesitcrit = true{
    draw_set_font(fnt_damagetextcrit)
}



//draw_text(x, y-12, string(instance_id));
//draw_text_color(x,y-12, string(damageamount),c_red,c_red,c_red,c_red,alpha)

if doesitcrit = false{
    draw_set_color(global.basicdamage);
    draw_text_outline(x,y,string(round(damageamount)),1,c_black,16)
}
if doesitcrit = true {
    draw_set_color(global.basicdamagecrit);
    draw_text_outline(x,y,string(round(damageamount)) + "!",1,c_black,16);
}



The idea was to create a hitbox with all the needed fields I would use to determine all the specifics. Is the fact that both players are creating this object the problem?
 
Top