Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to OrnsteinDragonslayer
User Avatar
8 years ago
Auto-translated
OrnsteinDragonslayer
What I mean is, should this SetObjective be implemented as a separate function, or can it be included in this one?
Just put it right here.
User Avatar
8 years ago
Auto-translated
Here's the question: I want to make it so that the hero of team 1 (AI) patrols a specific path. I know that something similar was done in the first map of the third campaign (where Markel has to avoid being caught by the mages' patrol), but I looked at the scripts, and it's a nightmare for me as a beginner in scripting. So, the question is: is there a way to simplify the script for the mages' patrol from that mission? And there's also a line there with the detection radius, which, apparently, if Markel is within that radius, the enemy hero will pursue him. But in my map, there's a problem here. Let's say I set everything up correctly, but the patrolling hero from team 1 will pass near the city of team 2 (the enemy). Won't he capture the city, and will the script break? Thanks in advance for the answers.
User Avatar
8 years ago
Auto-translated
Here's the question. I have several identical objects with triggers attached to them. I wrote a function that can work with any of them and takes the object number as an argument. I call it with a touch trigger like this: `Trigger(OBJECT_TOUCH_TRIGGER, 'object name', 'function(object number)')`. This works, but each time it triggers, it writes an error to the console: "attempts to call a nil value." Should I ignore this error, since everything works as intended, or does it actually affect something?

UPD. I experimented a bit and came up with this. If I write something like: `

str = 'function(parameter)'
...
Trigger(OBJECT_TOUCH_TRIGGER, 'object name', 'parse(str)')

then there will be no error in the console. However, I don't fully understand how this works and whether it's a good approach.
User Avatar
8 years ago
Auto-translated
Here is a snippet from my map:
Trigger(OBJECT_TOUCH_TRIGGER, "monum1", "monumtext");
Trigger(OBJECT_TOUCH_TRIGGER, "monum2", "monumtext");
Trigger(OBJECT_TOUCH_TRIGGER, "monum3", "monumtext");
Trigger(OBJECT_TOUCH_TRIGGER, "monum4", "monumtext");

function monumtext (hero, obj)
if obj == 'monum1' then
MessageBox(mpath.. 'monum1.txt');
elseif obj == 'monum2' then
MessageBox(mpath.. 'monum2.txt');
elseif obj == 'monum3' then
MessageBox(mpath.. 'monum3.txt');
elseif obj == 'monum4' then
MessageBox(mpath.. 'monum4.txt');
end;
end;
The object_touch trigger always passes 2 parameters to the function (it doesn't matter if you use them or not): the name of the hero who touched the object and the name of the object that was touched. Therefore, you should write Trigger(OBJECT_TOUCH_TRIGGER, 'object name', 'function'), without any parameters in the parentheses.
User Avatar
8 years ago
Auto-translated
Thanks, I'd rather not come up with any workarounds, just in case...
User Avatar
8 years ago
Auto-translated
Here's a question about triggers. I have two regions that activate different events. Let's say a hero enters the first region, and something happens. But how do I prevent the event in the second region from being activated afterward? A workaround like "blocking the second region for the player" cannot be implemented.
User Avatar
8 years ago
Auto-translated
Reset the trigger for the second region. Trigger(TRIGGER_TYPE, 'region name', nil)
User Avatar
8 years ago
Auto-translated
Here's the question. I'm working on a task where I need to eliminate a specific hero (Orson). But I want to give the player a choice, so there's a branching path, which means two functions: one for "accepting" the task and one for "refusing" it. The refusal function works, but the execution function doesn't. Maybe I made a mistake somewhere? Could you please take a look? Also, the console doesn't seem to be reporting any errors. It just does nothing. Although the trigger seems to be set correctly.
function SuppGlutt()
SetObjectiveState("Qnecro", OBJECTIVE_COMPLETED);
RemoveObject("Isher");
SetObjectOwner("gorodZemlya", 1);
ChangeHeroStat("RedHeavenHero04", STAT_EXPERIENCE, 15000);
ChangeHeroStat("RedHeavenHero04", STAT_MORALE, 1);
ChangeHeroStat("RedHeavenHero04", STAT_LUCK, 1);
Trigger(PLAYER_REMOVE_HERO_TRIGGER, "Straker", nil);
end;

Trigger(PLAYER_REMOVE_HERO_TRIGGER, "Straker", "SuppGlutt");
User Avatar
8 years ago
Auto-translated
REMOVE_HERO_TRIGGER works slightly differently.
Trigger(PLAYER_REMOVE_HERO_TRIGGER, player number, 'function to which the names of the lost hero and its victor (or nil) will be passed')

So, it should be something like this:
function SuppGlutt (looser, winner)
if(looser == "Straker") then
SetObjectiveState("Qnecro", OBJECTIVE_COMPLETED);
RemoveObject("Isher");
SetObjectOwner("gorodZemlya", 1);
ChangeHeroStat("RedHeavenHero04", STAT_EXPERIENCE, 15000);
ChangeHeroStat("RedHeavenHero04", STAT_MORALE, 1);
ChangeHeroStat("RedHeavenHero04", STAT_LUCK, 1);
Trigger (PLAYER_REMOVE_HERO_TRIGGER, number, nil);
end;
end;

Trigger (PLAYER_REMOVE_HERO_TRIGGER, player number to which the desired hero belongs, "SuppGlutt")
User Avatar
8 years ago
Auto-translated
Question about triggers. I don't know much about them, but I think I need them here, so I'm asking for help.
There are several special neutral creatures. After they are destroyed, a trigger should activate (probably), and a reserve hero should appear.
How is this implemented?
And a second question, not about triggers: can one trigger activate multiple functions? How do I write that?
For example, will a trigger like this work - Trigger(REGION_ENTER_AND_STOP_TRIGGER, "dialog", "Dialog1", "function2", "function3", "function228"); ?
In reply to OrnsteinDragonslayer
User Avatar
8 years ago
Auto-translated
OrnsteinDragonslayer
Question about threads. I don't know much about them, but I think I need them here, so I'm asking for help.
There are several special neutral creatures. After they are destroyed, a trigger should activate (probably), and a reserve hero should appear.
How is this implemented?

Something like this:
function fun()
while (1) do
sleep(2);
if (Exists('neutral1') == nil) and (Exists('neutral2') == nil) then
fun2();
break
end;
end;
end;

startThread(fun);

The function fun checks in a loop whether the objects neutral 1 and 2 exist. As soon as they disappear, the function fun2() is executed. startThread can be written immediately after loading the map, or when you need it (for example, when you receive a quest for the neutral creatures).
OrnsteinDragonslayer

And a second question, not about threads: can one trigger activate multiple functions? How do I write this?
For example, will a trigger like this work - Trigger(REGION_ENTER_AND_STOP_TRIGGER , "dialog", "Dialog1", "function2", "function3", "function228"); ?

Perhaps it can be done somehow, but I would launch them in a chain:

Trigger(REGION_ENTER_AND_STOP_TRIGGER , "dialog", "Dialog1")

function Dialog1 ()
...
function2();
end;

function function2 ()
...
function3();
end;

and so on.
User Avatar
8 years ago
Auto-translated
Perhaps there is a way to do it; I would launch them in a chain:
A more traditional approach is as follows:
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "dialog", "Dialog1")

function Dialog1()
  function1();
  function2();
  function3();
end
In reply to Jack_of_shadows
User Avatar
8 years ago
Auto-translated
if anyone knows, could you please tell me how to transfer the hero's level to a combat script:confused: :
function start()
if the attacker's hero level >= 1
cast one spell
if the attacker's hero level >= 10
cast one spell
if the attacker's hero level >= 20
cast one spell
end:rolleyes:
In reply to LetoX
User Avatar
8 years ago
Auto-translated
LetoX
If anyone knows, could you please tell me how to transfer the hero's level to a combat script:confused: :
function start()
if the attacker's hero level >=1
cast one spell
if the attacker's hero level >=10
cast one spell
if the attacker's hero level >=20
cast one spell
end:rolleyes:

using a global variable:
x = GetHeroLevel('name of the hero')
SetGameVar('Level', x)

in the combat script, get its value:
function Start()
HeroLevel = GetGameVar('Level') + 0
if(HeroLevel >= 1) then
...
and so on.
User Avatar
8 years ago
Auto-translated
Here's the function I wrote based on your suggestion:
function cherti ()
        while (1) do
            sleep(2);
            if (Exists('chert1') == nil) and (Exists('chert2') == nil) and (Exists('chert3') == nil) and (Exists('chert4') == nil) and (Exists('chert5') == nil) and (Exists('chert6') == nil) and (Exists('chert7') == nil) and (Exists('chert8') == nil) then
               Quelaag ();
               break
            end;
        end;
end;

startThread("cherti");

function Quelaag ()
        DeployReserveHero( "Oddrema", 60, 36, GROUND );
end;
But after all the "cherti" are destroyed, nothing happens. Can you tell me where the error is? Added 23 minutes later And another question. Is it possible to create a hidden connection between quests? I'll try to come up with a simple example: Quest - destroy an enemy hero. Secondary quest - destroy a neutral creature. When you approach the enemy hero, dialogue #1 plays, but if you have destroyed the neutral creatures, dialogue #2 will play. Also, if you simply fight the enemy hero, his army will have 5 phoenixes. But if you defeat the neutral creatures, he will have 250 wolves and some artifact will be found. Is it possible to implement something like this?

Statistics

Welcome our newest member: recijeb