Post by kaoz on Feb 18, 2016 19:19:32 GMT 1
I have a problem in my Lua script where function Trigger04 refuses to work. I have been looking (for almost 2 weeks now), but can't see what might be wrong. Maybe (and hopefully) someone of you might
function Init()
RunScript("Clearvar", 2000);
RunScript("RevealObjective0", 3000);
RunScript("RevealObjective1", 12000);
RunScript("RevealObjective2", 21000);
RunScript("Info0", 49000);
end;
function Clearvar()
SetIGlobalVar("temp.objective.0", 0);
SetIGlobalVar("temp.objective.1", 0);
SetIGlobalVar("temp.objective.2", 0);
SetIGlobalVar("temp.objective.3", 0);
Suicide();
end;
function Trigger01()
if ((GetNUnitsInArea(1, "port_west") > 0) and
(GetNUnitsInArea(0, "port_west") == 0) and
(GetNUnitsInArea(1, "port_center") > 0) and
(GetNUnitsInArea(0, "port_center") == 0) and
(GetNUnitsInArea(1, "port_oil") > 0) and
(GetNUnitsInArea(0, "port_oil") == 0) and
(GetNUnitsInArea(1, "port_east") > 0) and
(GetNUnitsInArea(0, "port_east") == 0)) then
ObjectiveChanged(0, 2);
SetIGlobalVar("temp.objective.0", 1);
DisplayTrace("The city is lost...");
Suicide();
end;
end;
function Trigger03()
if ((GetNScriptUnitsInArea(0, "port_center") > 1) or
(GetNScriptUnitsInArea(1, "port_center") > 1) or
(GetNScriptUnitsInArea(2, "port_center") > 1) or
(GetNScriptUnitsInArea(3, "port_center") > 1)) then -- Allies in town
DisplayTrace("ALLIES IN TOWN");
KillScript("Trigr_100");
KillScript("Reinforce100");
KillScript("Trigr_102");
KillScript("Reinforce102");
KillScript("Trigr_103");
KillScript("Reinforce103");
KillScript("Trigr_104");
KillScript("Reinforce104");
KillScript("Trigr_105");
KillScript("Reinforce105");
KillScript("Trigr_106");
KillScript("Reinforce106");
KillScript("Trigr_108");
KillScript("Reinforce108");
KillScript("Trigr_109");
KillScript("Reinforce109");
KillScript("Trigger06");
KillScript("Trigger07");
KillScript("Trigger12");
RunScript("Trigger09", 17000);
RunScript("Trigger10", 18000);
RunScript("Trigger04", 27000);
Suicide();
end;
end;
function Trigger04()
if (GetIGlobalVar("temp.objective.0") == 0) then
RunScript("Objective0", 3000);
Suicide();
elseif (GetIGlobalVar("temp.objective.0") == 1) then
RunScript("Objective5", 9000);
Suicide();
end;
end;
function Objective0()
if ((GetNUnitsInArea(0, "port_oil") > 0) and
(GetNUnitsInArea(1, "port_oil") == 0) or
(GetNUnitsInArea(0, "port_center") > 0) and
(GetNUnitsInArea(1, "port_center") == 0) or
(GetNUnitsInArea(0, "port_east") > 0) and
(GetNUnitsInArea(1, "port_east") == 0)) then
ObjectiveChanged(0, 1);
LandReinforcement(4);
RunScript("RevealObjective6", 3000);
RunScript("RevealObjective7", 12000);
RunScript("RevealObjective8", 21000);
Suicide();
end;
end;
function Objective5()
if ((GetNUnitsInArea(0, "port_west") > 0) and
(GetNUnitsInArea(1, "port_west") == 0) and
(GetNUnitsInArea(0, "city_west") > 0) and
(GetNUnitsInArea(1, "city_west") == 0) and
(GetNUnitsInArea(0, "city_center") > 0) and
(GetNUnitsInArea(1, "city_center") == 0) and
(GetNUnitsInArea(0, "city_hospital") > 0) and
(GetNUnitsInArea(1, "city_hospital") == 0) and
(GetNUnitsInArea(0, "city_east") > 0) and
(GetNUnitsInArea(1, "city_east") == 0)) then
ObjectiveChanged(5, 1);
RunScript("RevealObjective6", 3000);
RunScript("RevealObjective7", 12000);
RunScript("RevealObjective8", 21000);
Suicide();
end;
end;
The script has been stripped because it would be too long to post, but these are the most important parts.
The player (0) needs to defend a city, divided in area's (city_east, port_west, etc). If player fails, global var will be set to 1, as shown in Trigger01. Later, when allied reinforcements enter the town, Trigger03 will start, killing a lot of scripts that stop enemy attacks on the city. That all works. Trigger03 will also start Trigger04 which checks the variable (0 or 1). Depending on value, it will start objective0 or objective5.
As you can see in Trigger03, there are more triggers starting. They all work fine, except Trigger04, so something must be wrong there, but i just can't seem to find it...
All help welcome!
function Init()
RunScript("Clearvar", 2000);
RunScript("RevealObjective0", 3000);
RunScript("RevealObjective1", 12000);
RunScript("RevealObjective2", 21000);
RunScript("Info0", 49000);
end;
function Clearvar()
SetIGlobalVar("temp.objective.0", 0);
SetIGlobalVar("temp.objective.1", 0);
SetIGlobalVar("temp.objective.2", 0);
SetIGlobalVar("temp.objective.3", 0);
Suicide();
end;
function Trigger01()
if ((GetNUnitsInArea(1, "port_west") > 0) and
(GetNUnitsInArea(0, "port_west") == 0) and
(GetNUnitsInArea(1, "port_center") > 0) and
(GetNUnitsInArea(0, "port_center") == 0) and
(GetNUnitsInArea(1, "port_oil") > 0) and
(GetNUnitsInArea(0, "port_oil") == 0) and
(GetNUnitsInArea(1, "port_east") > 0) and
(GetNUnitsInArea(0, "port_east") == 0)) then
ObjectiveChanged(0, 2);
SetIGlobalVar("temp.objective.0", 1);
DisplayTrace("The city is lost...");
Suicide();
end;
end;
function Trigger03()
if ((GetNScriptUnitsInArea(0, "port_center") > 1) or
(GetNScriptUnitsInArea(1, "port_center") > 1) or
(GetNScriptUnitsInArea(2, "port_center") > 1) or
(GetNScriptUnitsInArea(3, "port_center") > 1)) then -- Allies in town
DisplayTrace("ALLIES IN TOWN");
KillScript("Trigr_100");
KillScript("Reinforce100");
KillScript("Trigr_102");
KillScript("Reinforce102");
KillScript("Trigr_103");
KillScript("Reinforce103");
KillScript("Trigr_104");
KillScript("Reinforce104");
KillScript("Trigr_105");
KillScript("Reinforce105");
KillScript("Trigr_106");
KillScript("Reinforce106");
KillScript("Trigr_108");
KillScript("Reinforce108");
KillScript("Trigr_109");
KillScript("Reinforce109");
KillScript("Trigger06");
KillScript("Trigger07");
KillScript("Trigger12");
RunScript("Trigger09", 17000);
RunScript("Trigger10", 18000);
RunScript("Trigger04", 27000);
Suicide();
end;
end;
function Trigger04()
if (GetIGlobalVar("temp.objective.0") == 0) then
RunScript("Objective0", 3000);
Suicide();
elseif (GetIGlobalVar("temp.objective.0") == 1) then
RunScript("Objective5", 9000);
Suicide();
end;
end;
function Objective0()
if ((GetNUnitsInArea(0, "port_oil") > 0) and
(GetNUnitsInArea(1, "port_oil") == 0) or
(GetNUnitsInArea(0, "port_center") > 0) and
(GetNUnitsInArea(1, "port_center") == 0) or
(GetNUnitsInArea(0, "port_east") > 0) and
(GetNUnitsInArea(1, "port_east") == 0)) then
ObjectiveChanged(0, 1);
LandReinforcement(4);
RunScript("RevealObjective6", 3000);
RunScript("RevealObjective7", 12000);
RunScript("RevealObjective8", 21000);
Suicide();
end;
end;
function Objective5()
if ((GetNUnitsInArea(0, "port_west") > 0) and
(GetNUnitsInArea(1, "port_west") == 0) and
(GetNUnitsInArea(0, "city_west") > 0) and
(GetNUnitsInArea(1, "city_west") == 0) and
(GetNUnitsInArea(0, "city_center") > 0) and
(GetNUnitsInArea(1, "city_center") == 0) and
(GetNUnitsInArea(0, "city_hospital") > 0) and
(GetNUnitsInArea(1, "city_hospital") == 0) and
(GetNUnitsInArea(0, "city_east") > 0) and
(GetNUnitsInArea(1, "city_east") == 0)) then
ObjectiveChanged(5, 1);
RunScript("RevealObjective6", 3000);
RunScript("RevealObjective7", 12000);
RunScript("RevealObjective8", 21000);
Suicide();
end;
end;
The script has been stripped because it would be too long to post, but these are the most important parts.
The player (0) needs to defend a city, divided in area's (city_east, port_west, etc). If player fails, global var will be set to 1, as shown in Trigger01. Later, when allied reinforcements enter the town, Trigger03 will start, killing a lot of scripts that stop enemy attacks on the city. That all works. Trigger03 will also start Trigger04 which checks the variable (0 or 1). Depending on value, it will start objective0 or objective5.
As you can see in Trigger03, there are more triggers starting. They all work fine, except Trigger04, so something must be wrong there, but i just can't seem to find it...
All help welcome!