When choosing options 1 and 3, everything works as expected, but option 2 produces an error.
The error occurs at ChangeHeroState(heroichik, 4, 5).
spells = {SPELL_MASS_WEAKNESS, SPELL_MASS_SLOW, SPELL_MASS_CURSE, SPELL_UNHOLY_WORD} How can I make it cast a random spell?
random_spell = spells[random(1, length(spells))];
However, if this is in combat, there is no function implemented that returns a random number (combat and overworld scripts have different sets of functions). You either need to write it yourself or use, for example, the lualib.lua library by RedHeavenHero (search the forum). I used the library.