Solarus-Games English Forum

Solarus => Development => Topic started by: gzuk on September 15, 2022, 09:37:01 AM

Title: Make 2nd hero un-attackable by 1st hero
Post by: gzuk on September 15, 2022, 09:37:01 AM
Hi, I tried out the new multiple heroes feature (https://forum.solarus-games.org/en/index.php/topic,1493.0.html), but the default seems to be a player vs. player setup. The heroes hurt each other with their attacks, as in the "friendly fire" test map. For a coop quest, it would be nicer if you could also configure them to be immune to each other's attacks.

There are functions on the "enemy" type to configure attack reaction (set_attack_consequence), but these functions don't seem to exist on the "hero" type. In the CPP files, there are even more functions (is_sword_ignored), but it seems they have no Lua bindings.

Have I maybe overlooked an easy way to set this up? Or could it be implemented easily?
Title: Re: Make 2nd hero un-attackable by 1st hero
Post by: gzuk on September 19, 2022, 08:57:48 PM
I saw that you can call state:set_can_be_hurt on a state object. And in the parameter function you could probably check if the attacker is another hero, and then do nothing. But I'd have to set that on all the default states ("free", "running", "sword swinging" etc.), and I don't know where these states are created or stored. Does anyone know how I could get a handle on all the default states?
Title: Re: Make 2nd hero un-attackable by 1st hero
Post by: stdgregwar on September 21, 2022, 11:02:48 AM
Hello !

You are right disabling friendly fire is a lacking feature. I added a way to do it in this merge request : https://gitlab.com/solarus-games/solarus/-/merge_requests/1421

It adds the `on_attacking_hero` event that can be used to short circuit the default behavior and decide what to do. To disable the friendly fire quest-wide you can add the event to the hero's metatable.

Thank you for testing the multiplayer features !

Title: Re: Make 2nd hero un-attackable by 1st hero
Post by: gzuk on September 24, 2022, 09:18:03 PM
Thank you very much. I've checked out your additions, and the on_attacking_hero function works very well. If you define it on both heroes and leave it empty, then the heroes won't hurt each other any more, like for a coop game.

I'll play around some more with the multiple heroes, and make a new post when something else comes up.