Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Победитель
User Avatar
15 years ago
Auto-translated
Gilraen
Oh Lord! This MoveHero doesn't work either!! I can understand these two heroes – no one wants to die, but they should work with scripts!!! My enemy heroes either do whatever they want (until I set up blocks) or just stand there (as in the last three cases). I've already tried calling them with MoveHero and attracting them with AiAttractor, but no – they're stuck!
Perhaps MoveHero only works when the path to the object is completely clear, i.e., not blocked by a monster or an enemy hero. And this can be checked using the function CanMoveHero(heroName, x, y, floorID).
User Avatar
15 years ago
Auto-translated
MoveHero is quite a tricky thing. It might not work if the destination point for the hero is on a "green" cell. For example, in Gnomania, it wasn't possible to use this function to make heroes attack a garrison. I did it like this: I sent them to an adjacent cell, and there was a region, and a trigger was defined for it:
function Gar(hero)
if hero=="bla-bla" then
MakeHeroInteractWithObject("bla-bla","Garnison");
end;
end;
User Avatar
15 years ago
Auto-translated
Okay, I figured it out. The heroes simply refused to attack cities at close range. I just placed the heroes from the cities on an adjacent tile (by the way, I used teleport to put them in the city; is there a way to place a hero "as a guest" and disable them?). And could you please provide more details about the quests? Where can I configure them, how can I add descriptions? How can I create an "empty" quest (only a description, completed by a script)?
User Avatar
15 years ago
Auto-translated
Well, I figured it out. The heroes simply didn't want to attack cities at close range. I just placed the heroes from the cities on an adjacent tile.
Damn, how do my heroes attack cities in Australia? :D
Do I have special scripts? :)
User Avatar
15 years ago
Auto-translated
The screenshot in message #32 shows the map properties tree. You expand it like that. Then you fill in the name, captionFileRef (title), and descriptionFileRef (description). If you want it to be hidden initially, set IsHidden and IsInitiallyVisible to false. That's it.
In reply to Ment
User Avatar
15 years ago
Auto-translated
Ment
MoveHero is quite a tricky thing. It might not work if the destination point for the hero is on a "green" cell. For example, in Gnomania, I couldn't get the heroes to attack a garrison using this function. I did it like this: I sent them to an adjacent cell, and there's a region there, and a trigger is defined for it:
function Gar(hero)
if hero=="bla-bla" then
MakeHeroInteractWithObject("bla-bla","Garnison");
end;
end;

Does this function only work if the hero is next to the object?
If not, then you don't even need to set up a region and trigger.
User Avatar
15 years ago
Auto-translated
Could you provide information on what the trigger condition looks like that activates when a unit or an enemy hero is defeated?
In reply to Победитель
User Avatar
15 years ago
Auto-translated
Winner
Could you please provide information on how to define a condition that triggers when a unit or an enemy hero is defeated?
Here's an example from my map:

if GetSavedCombatArmyHero(a1,0)=="Giovanni" then
Loose();
end;
if (GetSavedCombatArmyHero(a1,1)=="Giovanni") and (GetSavedCombatArmyHero(a1,0)=="Zehir") then
MessageBox(GetMapDataPath().."talk_of_grigorio_6.txt");
SetObjectiveState("kill_pl5", OBJECTIVE_COMPLETED, PLAYER_1 );
SetPlayerResource(PLAYER_1 ,GOLD, GetPlayerResource(PLAYER_1 , GOLD)+20000);
end;
if  flag_bad_grig==1 then
if (GetSavedCombatArmyHero(a1,1)=="Giovanni") and (GetSavedCombatArmyHero(a1,0)=="Duncan") then
SetObjectiveState("kill_pl6", OBJECTIVE_COMPLETED, PLAYER_1 );
MessageBox(GetMapDataPath().."talk_of_grigorio_5.txt");
SetObjectEnabled("portal1", true);
end;
else
if (GetSavedCombatArmyHero(a1,1)=="Giovanni") and (flag_britt==1) then
count_stacks = GetSavedCombatArmyCreaturesCount(a1,0);
for i=0,count_stacks-1 do
cr, numer, dead = GetSavedCombatArmyCreatureInfo(a1,0,i);
if cr==cr_ded then
Strelki_dead= Strelki_dead + dead;
end;
end;
Here are some code examples. If you understand them, you'll get it; if not, ask for an explanation.
This is a specific example where one hero defeats another, or a unit is destroyed, and their numbers are tallied.
Or do you need it to account for any enemy death?
Then, here's:
Procedure call format:
void sProc( sHeroName )
Stop:
Trigger(PLAYER_REMOVE_HERO_TRIGGER, nPlayerID, nil)
The procedure is called when player nPlayerID loses a hero. The name of this hero is passed to the procedure as a parameter.
User Avatar
15 years ago
Auto-translated
Thank you, Dyrman. The bottom option worked. However, I have a big problem now. The scripts are working intermittently. For example:
OpenCircleFog(83, 14, 0, 4, PLAYER_1); -- works,
but three lines below:
SetPlayerResource(PLAYER_1, GOLD, 5000); -- doesn't. Both lines are without functions, and I saw them working in other maps. What could be the problem?

P.S.: Nothing works, starting from the line
SetRegionBlocked("AntiAI", true, PLAYER_2);
Could it have "spoiled" everything that comes after it?
In reply to Победитель
User Avatar
15 years ago
Auto-translated
Winner

P.S.: It seemed to me that the code stopped working after the line
MessageBox("/Maps/SingleMissions/***********/msg1.txt");
If it's incorrect, could it block everything that comes after it?
Exactly. After an incorrect line in the function, all subsequent lines stop working.
Check the encoding in the text file, verify the correctness of the path (and also the correctness of other function names), and it's better to use the GetMapDataPath() function, because if you change the map file name, the specified paths will become invalid.
GetMapDataPath() - determines the path to the main map files.
.. - string concatenation
example:
MessageBox(GetMapDataPath().."talk_of_grigorio_6.txt");


Added 17 minutes later
Winner

P.S.: Nothing works, starting from the line
SetRegionBlocked("AntiAI", true, PLAYER_2);
Could it have "spoiled" everything that comes after it?
What comes after this line?
Post the entire script.
What does the console say? The console is a good helper in catching bugs ;)
And one more request: usually edit messages, not like a modder, because the time of the change is not visible, and I end up answering non-existent questions(( :(
User Avatar
15 years ago
Auto-translated
Could you please explain in more detail how to structure the function you posted in the previous message?

void - function name? - ( -name of the killed hero- )
-what happens when the hero dies?-
Trigger(PLAYER_REMOVE_HERO_TRIGGER, nPlayerID, nil)
end;
end;
-another trigger with the procedure name?-

P.S.: I fixed the errors in the previous code, thanks again for your help.
In reply to Победитель
User Avatar
15 years ago
Auto-translated
Winner
Could you please explain in more detail how to format the function you posted in the previous message?

void - function name? - ( -name of the killed hero- )
-what happens when the hero dies?-
Trigger(PLAYER_REMOVE_HERO_TRIGGER, nPlayerID, nil)
end;
end;
-another trigger with the procedure name?-

P.S.: I fixed the errors in the previous code, thanks again for your help.
Example:
DedF (GGDed)
if GGded == "Zosya" then
..........code here
end;
end;
Trigger(PLAYER_REMOVE_HERO_TRIGGER, 1, "DedF")

Something like that.
User Avatar
15 years ago
Auto-translated
The console is complaining :(. It says:
Script ERROR: attempt to call a nil value
This happens at the very end – it seems to be related to the function in question.
P.S.: The script editor complained about the second "end," so I removed it. Maybe we need to add an "else" statement?
In reply to Победитель
User Avatar
15 years ago
Auto-translated
Winner
The console is complaining :(. It says:
Script ERROR: attempt to call a nil value
This happens at the very end – it seems to be the function in question.
P.S.: The script editor complained about the second 'end', so I removed it. Maybe I need to add some kind of 'else'?
Did you just copy it or rework it in your own way? Everything seems fine with the 'END' statements. Add a function identifier – the word function. But that's obvious, I think. I doubt you just copied it.
You're calling 'nil' instead of something. Check if the hero, function, or parameters exist. Unless, of course, the problem isn't with the word 'function' itself. :)

"Zosya" is obviously a fictional name. It should be the name of the enemy hero. If the enemy hero's name can be anything, just remove the condition.
15 years ago
Auto-translated
Hello, I'm new to heroesworld. I've experimented with some simple scripts, and some of them turned out well. But it's still a very small amount compared to the scripts used in some maps, so I hope to collaborate with you.

Statistics

Welcome our newest member: recijeb