GMS 2 [SOLVED] attack (hit) player multiple time by diffrent other players att the same time!

FoufaDjo

Member
so am creating a topdown 2v2 game and i found my self stuck on the dmage system.
right now i have diffrent controls for the same hero and all 4 players play the same hero so its the same object.
the player can knockback multiple other players but the player that got hit cant be targeted by another attack.
so what am looking att is that he can be hit by another attack but still cant be hit by the first one so that the knockback and the dmg dont stack.
 
I'm having a bit of a hard time following your question, but essentially if I am reading it right your saying you want to prevent the player from being struck a second time before the first hit is finished? Is that right? If so you just need to use alarms.

You would set in the create event a variable called something like can_hit = true; and then in the step you check if can_hit == true and if it is then the player can be hit by an attack (meaning run your collision code). Then, if the player is hit you set can_hit to false and set an alarm to run in 2 seconds. In that alarm that runs in 2 seconds reset the variable can_hit to true. That's it.

*edit, reading your post again it may be that you want the player to get hit still, but only not be knocked back? If so then you do the same thing I explained above, but with a new variable called can_pushback and if its set to true then push the player back, set can_pushback to false and reset it in an alarm. Anytime you need to separate out events like this it will pretty much always be this same solution, utilizing a separate flag and an alarm.
 

hughrock18

Member
@robproctor83: I believe foufadjo was saying that his (obj_player) won't "stack" damage and knockbacks when hit by more than 1 opponent at a time. The concept (correct me if i'm wrong) is that 1 player can hit multiple opponents (each opponent is another copy of the obj_player being controlled by... well... other players), but each player (each inst of the obj_player), for one reason or another, will NOT allow recieved damage or knockback (status?... strength?... force?) to stack. So... each player can get hit and knocked back once, but this effect will not intensify when hit multiple times (at the same time).

So... we are left with a few questions if my assumption is accurate.

@FoufaDjo: Can you only initiate this hit and knockback response once and never again, or can it be done multiple times (but not at the same time)?
 

FoufaDjo

Member
@robproctor83: I believe foufadjo was saying that his (obj_player) won't "stack" damage and knockbacks when hit by more than 1 opponent at a time. The concept (correct me if i'm wrong) is that 1 player can hit multiple opponents (each opponent is another copy of the obj_player being controlled by... well... other players), but each player (each inst of the obj_player), for one reason or another, will NOT allow recieved damage or knockback (status?... strength?... force?) to stack. So... each player can get hit and knocked back once, but this effect will not intensify when hit multiple times (at the same time).

So... we are left with a few questions if my assumption is accurate.

@FoufaDjo: Can you only initiate this hit and knockback response once and never again, or can it be done multiple times (but not at the same time)?
it can be done multiple times but not at the same time
 

NightFrost

Member
so what am looking att is that he can be hit by another attack but still cant be hit by the first one so that the knockback and the dmg dont stack.
Your explanations are difficult to understand, but it seems your attack instances persist for multiple steps and you want them to damage a player only once? In that case, objattack instances have to keep a list of players they've already damaged and not damage them again. That is, they should be doing the damage collision checks and reduce hit points from collided targets. Player objects should not touch that at all, only check if their hit points are down to zero.
 

FoufaDjo

Member
Your explanations are difficult to understand, but it seems your attack instances persist for multiple steps and you want them to damage a player only once? In that case, objattack instances have to keep a list of players they've already damaged and not damage them again. That is, they should be doing the damage collision checks and reduce hit points from collided targets. Player objects should not touch that at all, only check if their hit points are down to zero.
u mean like this
https://forum.yoyogames.com/index.php?threads/solved-adding-instance-id-to-ds-lists.12738/
 
Ah I think I see what you are asking. Your code probably only allows one collision at a time so when two players are touching the collision object only one of them are hit. You need to use specialized functions to find all collisions, there are a few ways to do this but a simple way is to just use this script

https://www.gmlscripts.com/script/instance_place_list

But be aware this will change how you handle collisions so you will need to adapt your code to work with it.
 

FoufaDjo

Member
Ah I think I see what you are asking. Your code probably only allows one collision at a time so when two players are touching the collision object only one of them are hit. You need to use specialized functions to find all collisions, there are a few ways to do this but a simple way is to just use this script

https://www.gmlscripts.com/script/instance_place_list

But be aware this will change how you handle collisions so you will need to adapt your code to work with it.
i keeped searching for other solution and found this
https://developer.amazon.com/fr/blo...d7c3a/gamemaker-basics-hitboxes-and-hurtboxes
i think thats how it work ill put in my code and see what happens
 

FoufaDjo

Member
it worked i used the same code but in the objattack simple and easy to use thnx boys for the help
https://developer.amazon.com/fr/blo...d7c3a/gamemaker-basics-hitboxes-and-hurtboxes

in objattack creat event set:
ignore = false;
ignoreList = ds_list_create();


in objattack colision with objplayer(p for indicating if the player is an enemy or not):
if other.p != p{
//check to see if your target is on the ignore list
//if it is on the ignore list, dont do stuff again
for(i = 0; i < ds_list_size(ignoreList); i ++){
if(ignoreList[|i] = other.id){
ignore = true;
break;
}
}
//if it is NOT on the ignore list, do stuff, and add it to
//the ignore list
if(!ignore){
do stuff
ds_list_add(ignoreList,other.id);
}
}
 
Last edited:

FoufaDjo

Member
i forgot something when the objattack duration ends u need to destroy the ignoreList it looks like this:
ds_list_destroy(ignoreList);
instance_destroy();
thats it uwu
 
Top