Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
13 years ago
Auto-translated
Added 8 minutes later

function Start()
hero = GetAttackerHero
UnitCastGlobalSpell(hero, 54)
end

It says in the panel "wrong type of argument 1 when calling function UnitGlobalCast", what's wrong?
In reply to Heroist
User Avatar
13 years ago
Auto-translated
Heroist
Added 8 minutes ago

function Start()
hero = GetAttackerHero()
UnitCastGlobalSpell(hero, 54)
end

It says in the panel "wrong type of argument 1 when calling function UnitGlobalCast", what's wrong?
After GetAttackerHero, there should be parentheses (). This function always returns 'attacker-hero', so you can skip it.
User Avatar
13 years ago
Auto-translated
yeah, thanks, that works.

And is it possible to make a random spell selection? Let me explain:

function Start()
hero = GetAttackerHero()
cast = random(5)
if cast == 0 then
UnitCastGlobalSpell(hero, 54)
elseif cast == 1 then
UnitCastGlobalSpell(hero, 24)
elseif cast == 2 then
UnitCastGlobalSpell(hero, 25)
elseif cast == 3 then
UnitCastGlobalSpell(hero, 28)
elseif cast == 4 then
UnitCastGlobalSpell(hero, 29)
elseif cast == 5 then
UnitCastGlobalSpell(hero, 23)
end
end

?
In reply to Heroist
User Avatar
13 years ago
Auto-translated
The random function doesn't work in battle.
User Avatar
13 years ago
Auto-translated
Oh, that's a shame. But is there a way to make a random cast? Perhaps generate a random number each day and then request it in the battle script?
In reply to Heroist
User Avatar
13 years ago
Auto-translated
After each battle, you can use the following code:
function rndcast()
	while 1 do
		SetGameVar('spell', random(5))
		local index = GetLastSavedCombatIndex()
		while index == GetLastSavedCombatIndex() do
			sleep(10)
		end
	end
end
startThread(rndcast)
And in the combat script, replace the line:
cast = GetGameVar('spell')+0
with the line:
cast = random(5)
Yes, and random(5) will return a random number from 0 to 4. That is, random(n) returns a random number from 0 to n-1.
User Avatar
13 years ago
Auto-translated
yes, now it really casts spells randomly. However, the error is now different; it can't cast any spell except for prayer. I assign mass haste, stone skin, etc., but it says that "hero can't cast #25, 24, etc."
Here's a snippet of the script again:

if cast == 0 then
UnitCastGlobalSpell(hero, 54) --- prayer, works
elseif cast == 1 then
UnitCastGlobalSpell(hero, 24) --- haste
elseif cast == 2 then
UnitCastGlobalSpell(hero, 25) --- stone skin
elseif cast == 3 then
UnitCastGlobalSpell(hero, 28) --- bloodlust
elseif cast == 4 then
UnitCastGlobalSpell(hero, 29) --- deflection
elseif cast == 5 then
UnitCastGlobalSpell(hero, 23) --- prophet's power
end

Please explain this moment; otherwise, everything seems to be becoming clear.

Added 1 minute ago
Oops, sorry, the question is withdrawn. I needed to look for mass spells.

Thank you very much.
In reply to Heroist
User Avatar
13 years ago
Auto-translated
The first thing that comes to mind is a lack of mana. These spells consume mana, and there must be enough of it.
User Avatar
13 years ago
Auto-translated
yes, by the way, mana shortage is also an issue, I checked =)
And is it possible to make spells free while still using autocast?
In reply to Heroist
User Avatar
13 years ago
Auto-translated
Heroist
yes, by the way, mana shortage is also an issue, I checked =)
And is it possible to make spells free while still using autocast?
Yes, you can, by adding to the hero as much mana as the spell costs.
User Avatar
13 years ago
Auto-translated
yes, I already did that. I would simply check how much mana he had at the beginning of the battle, then give him 100, and after a random cast, return the amount he had at the beginning of the battle. Thank you very much! Now it's much clearer to me.

Added 3 hours and 55 minutes later
I have a new question:

-How do I check the hero's name at the start of the battle?
I'm recording it like this:

hero = GetAttackerHero()
if GetHeroName(hero) == 'Alaric' then

But it doesn't work... Even if I write it simpler:

hero = GetAttackerHero()
if hero == 'Alaric'

Ps: I'm probably bothering you a lot, but I really want to figure this out.
In reply to Heroist
User Avatar
13 years ago
Auto-translated
No need to make it "simpler." `GetHeroName` provides the ability to obtain a scripted hero name. What should happen if the hero passes the check?
User Avatar
13 years ago
Auto-translated
Battle script: function Start() hero = GetAttackerHero() if GetHeroName("hero") == 'Alaric' then cast = GetGameVar('spell')+0 mana = GetUnitManaPoints(hero) SetUnitManaPoints(hero, 100) if cast == 0 then UnitCastGlobalSpell(hero, 54) elseif cast == 1 then UnitCastGlobalSpell(hero, 221) elseif cast == 2 then UnitCastGlobalSpell(hero, 218) elseif cast == 3 then UnitCastGlobalSpell(hero, 220) elseif cast == 4 then UnitCastGlobalSpell(hero, 219) elseif cast == 5 then UnitCastGlobalSpell(hero, 216) end SetUnitManaPoints(hero, mana) end Script: function rndcast() while 1 do SetGameVar('spell', random(6)) local index = GetLastSavedCombatIndex() while index == GetLastSavedCombatIndex() do sleep(10) end end end startThread(rndcast)
In reply to Heroist
User Avatar
13 years ago
Auto-translated
The word "hero" should be written without quotation marks.
User Avatar
13 years ago
Auto-translated
yes, I made another silly mistake, thanks. there was a missing "end".

Added 13 hours and 59 minutes ago
so, the most important question for today remains:

And how to handle attaching a battlescript to a hero? The thing is, I would like to be able to recruit such a hero, let's say, in a tavern, but in this case, he appears on the map without the attached script and loses his functions.
Is there a function that, if such a hero appears on the map, automatically attaches the battlescript to him? Or is there another way?

Statistics

Welcome our newest member: recijeb