Make 2nd hero un-attackable by 1st hero

Started by gzuk, September 15, 2022, 09:37:01 AM

Previous topic - Next topic
Hi, I tried out the new multiple heroes feature, 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?

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?

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 !


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.

Thanks, it works fine for me on_Attack_hero.