setting:
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1","Question");
deleting:
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1",nil);
A similar error exists in your first example with the message box.
New here? I'm Roha — want a quick tour?
Knight of the Abyss, if you have it, please refer to the script guide. The last parameter of triggers is the name of the function that should be called when the trigger is activated. To disable it, you need to insert "nil" instead of the name:
setting:
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1","Question");
deleting:
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1",nil);
A similar error in your first example with the message box.
Use the console, try simply typing this into it before entering the region:
@Trigger(REGION_ENTER_AND_STOP_TRIGGER,"reg_1",nil);
and check if the trigger activates. Perhaps some error will appear, for example, due to a typo.
-- table storing region names and visit flags
region_table =
{
{name = 'NAME_OF_THE_FIRST_REGION', visited = 0},
{name = 'NAME_OF_THE_SECOND_REGION', visited = 0},
...
};
-- initialization function
function RegionInit()
for i, region in region_table do
Trigger(REGION_ENTER_AND_STOP_TRIGGER, region.name, 'RegionVisit');
end
end
-- unified visit function
function RegionVisit(hero)
-- check which region we are in
for i, region in region_table do
if(IsObjectInRegion(hero, region.name)) then
Trigger(REGION_ENTER_AND_STOP_TRIGGER, region.name, nil);
region.visited = 1;
-- here you can do what you need, depending on the region number (variable i is the number in the region_table table)
end
end
end
-- returns true if the region with the name name has been visited
function IsRegionVisited(name)
for i, region in region_table do
if((region.name == name) and (region.visited == 1)) then
return true
end
end
return nil
end
Abyss Knight, using additional flags. I used to do similar things like this (the code isn't complete, but it illustrates the principle):-- table storing region names and visit flags
region_table =
{
{name = 'NAME_OF_THE_FIRST_REGION', visited = 0},
{name = 'NAME_OF_THE_SECOND_REGION', visited = 0},
...
};
-- initialization function
function RegionInit()
for i, region in region_table do
Trigger(REGION_ENTER_AND_STOP_TRIGGER, region.name, 'RegionVisit');
end
end
-- unified visit function
function RegionVisit(hero)
-- check which region we are in
for i, region in region_table do
if(IsObjectInRegion(hero, region.name)) then
Trigger(REGION_ENTER_AND_STOP_TRIGGER, region.name, nil);
region.visited = 1;
-- here you can do what you need, depending on the region number (variable i is the number in the region_table table)
end
end
end
-- returns true if the region with the name name has been visited
function IsRegionVisited(name)
for i, region in region_table do
if((region.name == name) and (region.visited == 1)) then
return true
end
end
return nil
end
region_visit_cnt = 0;` increment it and check it after the line `region.visited = 1;`region_visit_cnt = region_visit_cnt + 1;
if(region_visit_cnt >= 5) then
SetObjectiveState(QUEST_NAME, OBJECTIVE_COMPLETED);
end
Hello! I'm a complete beginner, I don't understand anything about scripts, so I would like to know... How can I make enemies automatically attack a city? That is, so that they don't collect resources, don't fight with mobs, etc., but immediately go to the city.
mod(GetDate(), 14) == 1
function CheckMana()
while GetHeroStat("hero_name", STAT_MANA_POINTS) >= 10 do
sleep(5)
end
Loose()
end
startThread(CheckMana)2) You can see it in the map itself. It uses the functions GetObjectNamesByType and SetObjectOwner.function change_all_owners()
local types = {'BUILDING', 'TOWN', 'HERO', 'DWELLING'}
for i, type in types do
for j, object in GetObjectNamesByType(type) do
if GetObjectOwner(object) == OLD_OWNER then
SetObjectOwner(object, NEW_OWNER)
end
end
end
end
1)function CheckMana()
while GetHeroStat("hero_name", STAT_MANA_POINTS) >= 10 do
sleep(5)
end
Loose()
end
startThread(CheckMana)