Solarus-Games English Forum

Solarus => Development => Topic started by: Diarandor on January 10, 2016, 11:29:51 AM

Title: Start the sword attack from an item script?
Post by: Diarandor on January 10, 2016, 11:29:51 AM
Hi! I was trying to script a weapon menu like the one in Link's awakening (but with 3 slots and any weapon could be assigned to each of them). I wanted to make it possible to unassign the sword of the attack button (with the possibility of assigning other items to the attack button), but also I want the possibility of assigning the sword to other buttons, is it possible? The problem that I have is that I don't know how to start the built-in sword attack from an item script...

(Note that calling the command "game:simulate_command_pressed("attack")" is not a solution since the sword would be already unassigned from the attack command.)

Could this be possible with solarus 1.5 using some access to the sword sprite? And in that case how?
Title: Re: Start the sword attack from an item script?
Post by: Diarandor on January 10, 2016, 11:58:45 AM
I guess that I will have to script my own sword as a custom entity instead of using the built-in one...  :-\
Title: Re: Start the sword attack from an item script?
Post by: MetalZelda on January 10, 2016, 01:31:39 PM
I don't really know what you want to do ? You want to make the attack slot item-assignable ?

My though is to entirely code the sword in LUA and assign a savegame value to this slot (which will determine what item is assigned to this slot) and then, if the attack button is pressed, start the item.
Title: Re: Start the sword attack from an item script?
Post by: Diarandor on January 10, 2016, 02:00:46 PM
Yes, I will have to use a custom entity for the sword. It's probably the best option.
Title: Re: Start the sword attack from an item script?
Post by: GameboyArda on January 10, 2016, 06:16:09 PM
Or you could make a New Item Like: Sword 2

and use a Code Like:
Code ( lua) Select
set:asainable(true)
Title: Re: Start the sword attack from an item script?
Post by: Christopho on January 10, 2016, 08:06:58 PM
Would this help? https://github.com/christopho/solarus/issues/821
Title: Re: Start the sword attack from an item script?
Post by: MetalZelda on January 10, 2016, 08:34:55 PM
Hmmm, if the default sword script have hero:start_sword() in on_using, yes, this could save a lot of time.
Since what he wants is a  item-assignable button, a single value (like I said) representing what is assigned might do what he wants.

Off topic : In the other hand, would it be possible f there are the same thing but for the spin attack ? (hero:start_spin_attack())
Title: Re: Start the sword attack from an item script?
Post by: Diarandor on January 11, 2016, 01:56:13 AM
Thanks a lot Christopho! That would be exactly the solution I was looking for, so I will wait for it.

(Sorry if I am asking too many things and features, which could be annoying for the forums sometimes. It's because I have been scripting a lot lately and these kind of problems appear frequently...)

As MetalZelda suggests, it would be useful too to have a function "hero:start_spin_attack()".

A nice and general syntax for future versions could be a function "hero:start_attack(attack_name)".
Pros: shorter API and simpler functions.
Cons: incompatibilities with the current syntax, which is terrible...
Anyway, one could define that general function directly using the current ones, so it is not necessary.
Title: Re: Start the sword attack from an item script?
Post by: Christopho on January 25, 2016, 12:43:05 PM
hero:start_attack() is now done in 1.5 development version.
For the spin attack, we will see later how to remove it properly from the engine and replace it by a script. So since it will disappear, I am not adding spin attack things to the API.