Start the sword attack from an item script?

Started by Diarandor, January 10, 2016, 11:29:51 AM

Previous topic - Next topic
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?
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

I guess that I will have to script my own sword as a custom entity instead of using the built-in one...  :-\
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

January 10, 2016, 01:31:39 PM #2 Last Edit: January 10, 2016, 01:37:18 PM by MetalZelda
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.

Yes, I will have to use a custom entity for the sword. It's probably the best option.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Or you could make a New Item Like: Sword 2

and use a Code Like:
Code ( lua) Select
set:asainable(true)
You know that nearly all of use strugled once
with RPG maker. But now we make with
Solarus! 8)


January 10, 2016, 08:34:55 PM #6 Last Edit: January 10, 2016, 08:36:26 PM by MetalZelda
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())

January 11, 2016, 01:56:13 AM #7 Last Edit: January 11, 2016, 02:05:25 AM by Diarandor
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.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

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.