 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 586
|
Posted: Sat Dec 16, 2023 2:28 pm Post subject: Code puzzlement |
|
|
I'm writing some code for a game in lua, Heroes of Might and Magic V. I have some similar code, not exact, where one of them works perfectly, the other compile some of the code as a nil and won't work. Here is the code snippet that works.
| Code: |
startnumberofheroes = 0;
--lots of code lines that has nothing to do with my question
playernames = GetPlayerHeroes(numhumanplayer);
if mod(GetDate(DAY),7) == 0 then
if GetCurrentPlayer() == numhumanplayer then
for i = 0, length(playernames) do
if HasHeroSkill(playernames[i], 13) then
--Add Haven Creastures
AddHeroCreatures(playernames[i], 2, 30);
AddHeroCreatures(playernames[i], 4, 24);
AddHeroCreatures(playernames[i], 6, 18);
AddHeroCreatures(playernames[i], 8, 12);
AddHeroCreatures(playernames[i], 10, 6);
AddHeroCreatures(playernames[i], 12, 4);
AddHeroCreatures(playernames[i], 14, 2);
elseif HasHeroSkill(playernames[i], 14) then
--similar code for all the factions no need to repeat
--else;
end;
end;
--else;
end;
end;
for i =startnumberofheroes, length(playernames) - 1
GiveHeroSkill(playernames[i], 74);
GiveHeroSkill(playernames[i], 88);
GiveHeroSkill(playernames[i], 139);
GiveHeroSkill(playernames[i], 100);
GiveHeroSkill(playernames[i], 126);
GiveHeroSkill(playernames[i], 22);
GiveHeroSkill(playernames[i], 23);
GiveHeroSkill(playernames[i], 24);
GiveHeroSkill(playernames[i], 25);
GiveHeroSkill(playernames[i], 34);
GiveHeroSkill(playernames[i], 35);
GiveHeroSkill(playernames[i], 130);
--more similar code giving the heroes stuff
|
Now the code that fails while compiling
| Code: |
numhumanplayer = GetCurrentPlayer();
startnumberofheroes = length(GetPlayerHeroes(numhumanplayer));
function addskills()
print("Add skills Function");
print(GetDate(DAY));
print(humanplayer);
print(startnumberofheroes);
playernames = GetPlayerHeroes(numhumanplayer);
print(length(playernames));
for i = startnumberofheroes, length(playernames)
print(playernames[i]);
--[b]This is the line where I get a nil[/b]
for x = 36, 43 do
if HasArtefact(playernames[i], x) ~= 1 then
GiveArtefact(playernames[i], x);
end;
end;
GiveArtefact(playernames[i], 36);
GiveArtefact(playernames[i], 37);
GiveArtefact(playernames[i], 38);
GiveArtefact(playernames[i], 39);
GiveArtefact(playernames[i], 40);
GiveArtefact(playernames[i], 41);
GiveArtefact(playernames[i], 42);
GiveArtefact(playernames[i], 43);
if HasArtefact(playernames[i], 25) ~= 1 then
GiveArtefact(playernames[i], 25);
end;
--[b]None o these lines is executed because of the nil, so I delete that the print(playernames[i]); line and I get an Invalid argument for GiveArtefact, wrong argument line where I get a nil[/b]
|
How in one code is the lines that contain playernames[i]; fail in one instance and a similar code works in another? I'm unable to discern the contradiction, can anyone?
|
|
| Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1069 Location: 0x90
|
Posted: Sat Dec 16, 2023 3:40 pm Post subject: |
|
|
We would have to see the whole code to give you informed advice because there's no indication where you have declared the playernames array.
Last edited by LeFiXER on Sat Dec 16, 2023 9:23 pm; edited 1 time in total |
|
| Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 586
|
Posted: Sat Dec 16, 2023 8:08 pm Post subject: |
|
|
| LeFiXER wrote: | | We would have to see the whole code to give you informed advice because there's indication where you have declared the playernames array. |
I can do that but they are well over 3000 lines. The declaration is in the first post,
playernames = GetPlayerHeroes(numhumanplayer);
and numhumanplayer = GetCurrentPlayer(); was prior to the if and for statements both codes.
Anyway this is the code that works. To help my added code is the function function addskills()
Pasting has been a problem as it doesn't paste what I'm attempting.
[code]
-- only do this the first day
path = "Maps/SingleMissions/Shadow Dreams/"; -- shorthand
---------------------------------------------------
--determine human player and set global variables--
---------------------------------------------------
whoishuman = GetCurrentPlayer(); --determine human player, always goes first
humanheroelist = GetPlayerHeroes(whoishuman); --get human's heroe choice
humanmainheroe = humanheroelist[0]; --human heroe choice assigned as main heroe
humansecondaryheroe = humanmainheroe;--this will store rescued heroe later
theThievesDen_visited= 0
heroewhofights = "test"--this is the heroe who enters a region to fight
kingblessing = 1;--set haven king statue bonus
numhumanplayer = GetCurrentPlayer();
academygravemess = 0;
theThievesDen_visited = 0;
theFaeryRing_visited = 0;
academyprison = 0;
sylvanprison = 0;
fortressprison = 0;
havenprison = 0;
FairyRingVisited = 0; --reset movement bonus for humanmainheroe (Sylvan only)
sleptyet = 1; --reset for humanmainheroe (Haven only)(for tavern)
greybonus = 1;
magmashrinevisited = 0;
--------------------------------------------------------------------------
--determine difficulty level: easy(1), normal(2), hard(3) or heroic(4) --
--------------------------------------------------------------------------
difficultylevel = 1;
if GetDifficulty() == DIFFICULTY_HEROIC then
difficultylevel = 4;
end;
if GetDifficulty() == DIFFICULTY_HARD then
difficultylevel = 3;
end;
if GetDifficulty() == DIFFICULTY_NORMAL then
difficultylevel = 2;
end;
--LevelUpHero (humanmainheroe); --For debuging. When enabled if hero does not level up, new script has syntax error.
------------------------------------------------
--Initial Objectives----------------------------
------------------------------------------------
SetObjectiveState ("Instant Travel Dream", OBJECTIVE_ACTIVE,whoishuman);
SetObjectiveVisible ("Instant Travel Dream", false, whoishuman);
SetObjectiveState ("Defeat the Red Slayer", OBJECTIVE_ACTIVE,whoishuman);
SetObjectiveVisible ("Defeat the Red Slayer", true, whoishuman);
if whoishuman == 1 then
SetObjectiveState ("Find Tower Grump", OBJECTIVE_ACTIVE,PLAYER_1);
SetObjectiveVisible ("Find Tower Grump", true, PLAYER_1);
SetObjectiveState ("Rescue Cyrus", OBJECTIVE_ACTIVE,PLAYER_1);
SetObjectiveVisible ("Rescue Cyrus", true, PLAYER_1);
end;
if whoishuman == 2 then
SetObjectiveState ("FaeryRingTrouble", OBJECTIVE_ACTIVE,PLAYER_2);
SetObjectiveVisible ("FaeryRingTrouble", true, PLAYER_2);
SetObjectiveState ("Rescue Alaron", OBJECTIVE_ACTIVE,PLAYER_2);
SetObjectiveVisible ("Rescue Alaron", true, PLAYER_2);
end;
if whoishuman == 4 then
SetObjectiveState ("Thieves Guild Trouble", OBJECTIVE_ACTIVE,PLAYER_4);
SetObjectiveVisible ("Thieves Guild Trouble", true, PLAYER_4);
end;
----------------------------------------------------
--Block various areas-------------------------------
----------------------------------------------------
--Computer can get hung up at Tomb of Warrior due to a bug in the game programming--
--causing game to slow down. Therefore, block both Tombs from the computer players--
SetRegionBlocked("rgnTombofWarrior1", 1, 1);
SetRegionBlocked("rgnTombofWarrior1", 1, 2);
SetRegionBlocked("rgnTombofWarrior1", 1, 3);
SetRegionBlocked("rgnTombofWarrior1", 1, 4);
SetRegionBlocked("rgnTombofWarrior1", 1, 5);
SetRegionBlocked("rgnTombofWarrior1", 1, 6);
SetRegionBlocked("rgnTombofWarrior1", 1, 7);
SetRegionBlocked("rgnTombofWarrior1", off, whoishuman);
SetRegionBlocked("rgnTombofWarrior2", 1, 1);
SetRegionBlocked("rgnTombofWarrior2", 1, 2);
SetRegionBlocked("rgnTombofWarrior2", 1, 3);
SetRegionBlocked("rgnTombofWarrior2", 1, 4);
SetRegionBlocked("rgnTombofWarrior2", 1, 5);
SetRegionBlocked("rgnTombofWarrior2", 1, 6);
SetRegionBlocked("rgnTombofWarrior2", 1, 7);
SetRegionBlocked("rgnTombofWarrior2", off, whoishuman);
--Don't allow computer access to Haven Stables so doesn't invade too fast.
SetRegionBlocked("rgnHavenStables", 1, 1);
SetRegionBlocked("rgnHavenStables", 1, 2);
SetRegionBlocked("rgnHavenStables", 1, 3);
SetRegionBlocked("rgnHavenStables", 1, 4);
SetRegionBlocked("rgnHavenStables", 1, 5);
SetRegionBlocked("rgnHavenStables", 1, 6);
SetRegionBlocked("rgnHavenStables", 1, 7);
SetRegionBlocked("rgnHavenStables", off, whoishuman);
--Only allow human Academy acces to The Grey Tower
SetRegionBlocked("rgnTheGreyTower", 1, 1);
SetRegionBlocked("rgnTheGreyTower", 1, 2);
SetRegionBlocked("rgnTheGreyTower", 1, 3);
SetRegionBlocked("rgnTheGreyTower", 1, 4);
SetRegionBlocked("rgnTheGreyTower", 1, 5);
SetRegionBlocked("rgnTheGreyTower", 1, 6);
SetRegionBlocked("rgnTheGreyTower", 1, 7);
if whoishuman == 1 then --unblock for human Academy
SetRegionBlocked("rgnTheGreyTower", off, 1);
end;
--Grumpy is too grumpy to help anyone but the Academy
SetRegionBlocked("rgnGrumpyOldWizard", 1, 1);
SetRegionBlocked("rgnGrumpyOldWizard", 1, 2);
SetRegionBlocked("rgnGrumpyOldWizard", 1, 3);
SetRegionBlocked("rgnGrumpyOldWizard", 1, 4);
SetRegionBlocked("rgnGrumpyOldWizard", 1, 5);
SetRegionBlocked("rgnGrumpyOldWizard", 1, 6);
SetRegionBlocked("rgnGrumpyOldWizard", 1, 7);
--SetRegionBlocked("rgnGrumpyOldWizard", off, 1);
if whoishuman == 1 then --unblock for human Academy
SetRegionBlocked("rgnGrumpyOldWizard", off, 1);
end;
--Reserve Dwarven Stables for dwarves
SetRegionBlocked("rgnDwarvenStables", 1, 1);
SetRegionBlocked("rgnDwarvenStables", 1, 2);
SetRegionBlocked("rgnDwarvenStables", 1, 3);
SetRegionBlocked("rgnDwarvenStables", 1, 4);
SetRegionBlocked("rgnDwarvenStables", 1, 5);
SetRegionBlocked("rgnDwarvenStables", 1, 6);
SetRegionBlocked("rgnDwarvenStables", 1, 7);
--SetRegionBlocked("rgnGrumpyOldWizard", off, 1);
if whoishuman == 3 then --unblock for human Fortress
SetRegionBlocked("rgnDwarvenStables", off, 3);
end;
--Reserve Obelisk (therefore Grail) for the human player
SetRegionBlocked("rgnBlockObelisk", 1, 1);
SetRegionBlocked("rgnBlockObelisk", 1, 2);
SetRegionBlocked("rgnBlockObelisk", 1, 3);
SetRegionBlocked("rgnBlockObelisk", 1, 4);
SetRegionBlocked("rgnBlockObelisk", 1, 5);
SetRegionBlocked("rgnBlockObelisk", 1, 6);
SetRegionBlocked("rgnBlockObelisk", 1, 7);
SetRegionBlocked("rgnBlockObelisk", off, whoishuman);
--Reserve Second Faery Tree for human only (any faction)
SetRegionBlocked("rgnSecondFaeryTree", 1, 1);
SetRegionBlocked("rgnSecondFaeryTree", 1, 2);
SetRegionBlocked("rgnSecondFaeryTree", 1, 3);
SetRegionBlocked("rgnSecondFaeryTree", 1, 4);
SetRegionBlocked("rgnSecondFaeryTree", 1, 5);
SetRegionBlocked("rgnSecondFaeryTree", 1, 6);
SetRegionBlocked("rgnSecondFaeryTree", 1, 7);
SetRegionBlocked("rgnSecondFaeryTree", off, whoishuman);
--Reserve Wolf Dens for human player
SetRegionBlocked("rgnWolfDen", 1, 1);
SetRegionBlocked("rgnWolfDen", 1, 2);
SetRegionBlocked("rgnWolfDen", 1, 3);
SetRegionBlocked("rgnWolfDen", 1, 4);
SetRegionBlocked("rgnWolfDen", 1, 5);
SetRegionBlocked("rgnWolfDen", 1, 6);
SetRegionBlocked("rgnWolfDen", 1, 7);
SetRegionBlocked("rgnWolfDen", off, whoishuman);
SetRegionBlocked("rgnWolfDen2", 1, 1);
SetRegionBlocked("rgnWolfDen2", 1, 2);
SetRegionBlocked("rgnWolfDen2", 1, 3);
SetRegionBlocked("rgnWolfDen2", 1, 4);
SetRegionBlocked("rgnWolfDen2", 1, 5);
SetRegionBlocked("rgnWolfDen2", 1, 6);
SetRegionBlocked("rgnWolfDen2", 1, 7);
SetRegionBlocked("rgnWolfDen2", off, whoishuman);
--Reserve Endgame for the human player
SetRegionBlocked("rgnBlockFinalRegion", 1, 1);
SetRegionBlocked("rgnBlockFinalRegion", 1, 2);
SetRegionBlocked("rgnBlockFinalRegion", 1, 3);
SetRegionBlocked("rgnBlockFinalRegion", 1, 4);
SetRegionBlocked("rgnBlockFinalRegion", 1, 5);
SetRegionBlocked("rgnBlockFinalRegion", 1, 6);
SetRegionBlocked("rgnBlockFinalRegion", 1, 7);
SetRegionBlocked("rgnBlockFinalRegion", off, whoishuman);
--Reserve Endgame for the human main heroe only (block this area and use a touch teleporter)
SetRegionBlocked("rgnBlockFinalRegion2", 1, 1);
SetRegionBlocked("rgnBlockFinalRegion2", 1, 2);
SetRegionBlocked("rgnBlockFinalRegion2", 1, 3);
SetRegionBlocked("rgnBlockFinalRegion2", 1, 4);
SetRegionBlocked("rgnBlockFinalRegion2", 1, 5);
SetRegionBlocked("rgnBlockFinalRegion2", 1, 6);
SetRegionBlocked("rgnBlockFinalRegion2", 1, 7);
--Keep Red Slayer in Prison
SetRegionBlocked("rgnApproachRedSlayer", 1, 1);
SetRegionBlocked("rgnApproachRedSlayer", 1, 2);
SetRegionBlocked("rgnApproachRedSlayer", 1, 3);
SetRegionBlocked("rgnApproachRedSlayer", 1, 4);
SetRegionBlocked("rgnApproachRedSlayer", 1, 5);
SetRegionBlocked("rgnApproachRedSlayer", 1, 6);
SetRegionBlocked("rgnApproachRedSlayer", 1, 7);
SetRegionBlocked("rgnApproachRedSlayer", off, whoishuman);
--Reserve Relics for the human player
SetRegionBlocked("rgnRelicU1", 1, 1);
SetRegionBlocked("rgnRelicU1", 1, 2);
SetRegionBlocked("rgnRelicU1", 1, 3);
SetRegionBlocked("rgnRelicU1", 1, 4);
SetRegionBlocked("rgnRelicU1", 1, 5);
SetRegionBlocked("rgnRelicU1", 1, 6);
SetRegionBlocked("rgnRelicU1", 1, 7);
SetRegionBlocked("rgnRelicU1", off, whoishuman);
--Reserve Relics for the human player
SetRegionBlocked("rgnRelicU2", 1, 1);
SetRegionBlocked("rgnRelicU2", 1, 2);
SetRegionBlocked("rgnRelicU2", 1, 3);
SetRegionBlocked("rgnRelicU2", 1, 4);
SetRegionBlocked("rgnRelicU2", 1, 5);
SetRegionBlocked("rgnRelicU2", 1, 6);
SetRegionBlocked("rgnRelicU2", 1, 7);
SetRegionBlocked("rgnRelicU2", off, whoishuman);
--Reserve Relics for the human player
SetRegionBlocked("rgnRelicU3", 1, 1);
SetRegionBlocked("rgnRelicU3", 1, 2);
SetRegionBlocked("rgnRelicU3", 1, 3);
SetRegionBlocked("rgnRelicU3", 1, 4);
SetRegionBlocked("rgnRelicU3", 1, 5);
SetRegionBlocked("rgnRelicU3", 1, 6);
SetRegionBlocked("rgnRelicU3", 1, 7);
SetRegionBlocked("rgnRelicU3", off, whoishuman);
--Reserve Relics for the human player
SetRegionBlocked("rgnRelicU4", 1, 1);
SetRegionBlocked("rgnRelicU4", 1, 2);
SetRegionBlocked("rgnRelicU4", 1, 3);
SetRegionBlocked("rgnRelicU4", 1, 4);
SetRegionBlocked("rgnRelicU4", 1, 5);
SetRegionBlocked("rgnRelicU4", 1, 6);
SetRegionBlocked("rgnRelicU4", 1, 7);
SetRegionBlocked("rgnRelicU4", off, whoishuman);
--Reserve Relics for the human player
SetRegionBlocked("rgnRelicU5", 1, 1);
SetRegionBlocked("rgnRelicU5", 1, 2);
SetRegionBlocked("rgnRelicU5", 1, 3);
SetRegionBlocked("rgnRelicU5", 1, 4);
SetRegionBlocked("rgnRelicU5", 1, 5);
SetRegionBlocked("rgnRelicU5", 1, 6);
SetRegionBlocked("rgnRelicU5", 1, 7);
SetRegionBlocked("rgnRelicU5", off, whoishuman);
--Reserve Relics for the human player
SetRegionBlocked("rgnRelicU6", 1, 1);
SetRegionBlocked("rgnRelicU6", 1, 2);
SetRegionBlocked("rgnRelicU6", 1, 3);
SetRegionBlocked("rgnRelicU6", 1, 4);
SetRegionBlocked("rgnRelicU6", 1, 5);
SetRegionBlocked("rgnRelicU6", 1, 6);
SetRegionBlocked("rgnRelicU6", 1, 7);
SetRegionBlocked("rgnRelicU6", off, whoishuman);
-------------------------------------------------------
--Initially block underground stairwells for inferno/dark elves--
-------------------------------------------------------
SetRegionBlocked("rgnUnderEastBlock", 1, 5);
SetRegionBlocked("rgnUnderEastBlock", 1, 6);
SetRegionBlocked("rgnUnderWestBlock", 1, 5);
SetRegionBlocked("rgnUnderWestBlock", 1, 6);
SetRegionBlocked("rgnUnderWestBlock", off, whoishuman); --If one chooses either 5 or 6
SetRegionBlocked("rgnUnderEastBlock", off, whoishuman); --If one chooses either 5 or 6
-----------------------------------------------------------------
--Initially block surface stairwells for surface computer races--
-----------------------------------------------------------------
SetRegionBlocked("rgnBlockWestSurface", 1, 1);
SetRegionBlocked("rgnBlockWestSurface", 1, 2);
SetRegionBlocked("rgnBlockWestSurface", 1, 3);
SetRegionBlocked("rgnBlockWestSurface", 1, 4);
SetRegionBlocked("rgnBlockWestSurface", off, whoishuman);
SetRegionBlocked("rgnBlockEastSurface", 1, 1);
SetRegionBlocked("rgnBlockEastSurface", 1, 2);
SetRegionBlocked("rgnBlockEastSurface", 1, 3);
SetRegionBlocked("rgnBlockEastSurface", 1, 4);
SetRegionBlocked("rgnBlockEastSurface", off, whoishuman);
---------------------------------------------------
--Initially Protect Prisons from hostile computer--
---------------------------------------------------
SetRegionBlocked("rgnAcademyPrison", 1, 2);
SetRegionBlocked("rgnAcademyPrison", 1, 3);
SetRegionBlocked("rgnAcademyPrison", 1, 4);
SetRegionBlocked("rgnAcademyPrison", 1, 5);
SetRegionBlocked("rgnAcademyPrison", 1, 6);
SetRegionBlocked("rgnAcademyPrison", 1, 7);
SetRegionBlocked("rgnSylvanPrison", 1, 1);
SetRegionBlocked("rgnSylvanPrison", 1, 3);
SetRegionBlocked("rgnSylvanPrison", 1, 4);
SetRegionBlocked("rgnSylvanPrison", 1, 5);
SetRegionBlocked("rgnSylvanPrison", 1, 6);
SetRegionBlocked("rgnSylvanPrison", 1, 7);
SetRegionBlocked("rgnFortressPrison", 1, 1);
SetRegionBlocked("rgnFortressPrison", 1, 2);
SetRegionBlocked("rgnFortressPrison", 1, 4);
SetRegionBlocked("rgnFortressPrison", 1, 5);
SetRegionBlocked("rgnFortressPrison", 1, 6);
SetRegionBlocked("rgnFortressPrison", 1, 7);
SetRegionBlocked("rgnHavenPrison", 1, 1);
SetRegionBlocked("rgnHavenPrison", 1, 2);
SetRegionBlocked("rgnHavenPrison", 1, 3);
SetRegionBlocked("rgnHavenPrison", 1, 5);
SetRegionBlocked("rgnHavenPrison", 1, 6);
SetRegionBlocked("rgnHavenPrison", 1, 7);
--------------------------------------------------------
--Introduction------------------------------------------
--------------------------------------------------------
MessageBox("Maps/SingleMissions/Shadow Dreams/Intro1.txt");
MessageBox(path.."Intro2.txt");
--------------------------------------------------------
--computer starting bonuses based on difficulty level--
--------------------------------------------------------
for i = 1, 7, 1 do --do for each computer player
if i ~= whoishuman then --don't do for human
for j = 0, 5, 1 do --do for each resource
resource = GetPlayerResource(i, j) + 10*difficultylevel;--give resource bonus
if ((j == 0) or (j == 1)) then --give more ore/wood
resource = resource + 40;
end;
SetPlayerResource(i, j, resource);
end;
goldbonus = GetPlayerResource(i, 6) + 10000*difficultylevel;--give gold bonus
SetPlayerResource(i, 6, goldbonus);
end;
end;
-------------------------------------------------------------------------------------------------------
--Transform Town in center to player town type (only the 4 surface types are playable);initial quests--
--Note: Transforming a town destroys the script name and all scripts on it-----------------------------
-------------------------------------------------------------------------------------------------------
if whoishuman == 1 then
TransformTown ("Feschnia", 5); --Academy
end;
if whoishuman == 2 then
TransformTown ("Feschnia", 4); --Sylvan
end;
if whoishuman == 3 then
TransformTown ("Feschnia", 9); --Fortress
end;
if whoishuman == 4 then
TransformTown ("Feschnia", 3); --Haven
end;
---------------------------------------------------------------------
--Skeleton encounter in player's house-------------------------------
---------------------------------------------------------------------
function skelefight()
StartCombat(humanmainheroe,nil,4,29,10,29,10,29,10,29,10,nil,"winlose_skelefight");
function winlose_skelefight()
MessageBox(path.."beatskeletons.txt");
MessageBox(path.."onelife.txt");
MessageBox (path.."duties.txt");
ChangeHeroStat(humanmainheroe, STAT_MANA_POINTS, 100);--restore mana
end;
end;
skelefight();--fight the skeletons in the player's house
-----------------------------------------------------------------------
--Computer Starting Troop Bonuses
-----------------------------------------------------------------------
if GetObjectOwner ("FirstAcademy") ~= whoishuman then
AddObjectCreatures("FirstAcademy", 57, 10*difficultylevel); --gremlin
AddObjectCreatures("FirstAcademy", 59, 7*difficultylevel); --S gargoyle
AddObjectCreatures("FirstAcademy", 61, 4*difficultylevel); --I golem
end;
if GetObjectOwner("FirstSylvan") ~= whoishuman then
AddObjectCreatures("FirstSylvan", 43, 5*difficultylevel); --pixie
AddObjectCreatures("FirstSylvan", 45, 4*difficultylevel); --blade dancer
AddObjectCreatures("FirstSylvan", 47, 3*difficultylevel); --hunter
end
if GetObjectOwner("FirstFortress") ~= whoishuman then
AddObjectCreatures("FirstFortress", 92, 7*difficultylevel); --defender
AddObjectCreatures("FirstFortress", 94, 5*difficultylevel); --spear
AddObjectCreatures("FirstFortress", 96, 4*difficultylevel); --bear
end;
if GetObjectOwner ("FirstHaven") ~= whoishuman then
AddObjectCreatures("FirstHaven", 1, 11*difficultylevel); --peasant
AddObjectCreatures("FirstHaven", 3, 6*difficultylevel); --archer
AddObjectCreatures("FirstHaven", 5, 5*difficultylevel); --footman
end;
if GetObjectOwner("FirstDarkE") ~= whoishuman then
AddObjectCreatures("FirstDarkE", 71, 4*difficultylevel); --scout
AddObjectCreatures("FirstDarkE", 73, 3*difficultylevel); --blood maiden
AddObjectCreatures("FirstDarkE", 75, 4*difficultylevel); --minotaur
end;
if GetObjectOwner("FirstDemon") ~= whoishuman then
AddObjectCreatures("FirstDemon", 15, 8*difficultylevel); --imp
AddObjectCreatures("FirstDemon", 17, 7*difficultylevel); --horned demon
AddObjectCreatures("FirstDemon", 19, 4*difficultylevel); --hell hound
end;
--------------------------------------------------------
--Regions in front of towns(Computer boosts)------------
--------------------------------------------------------
function AcademyFront(heroename)
if ((GetCurrentPlayer () ~= whoishuman) and (GetHeroLevel (heroename) < GetHeroLevel (humanmainheroe)) ) then
LevelUpHero (heroename);
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnAcademy1");
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnAcademy1", "AcademyFront");
function SylvanFront(heroename)
if ((GetCurrentPlayer () ~= whoishuman) and (GetHeroLevel (heroename) < GetHeroLevel (humanmainheroe)) ) then
LevelUpHero (heroename);
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnSylvan1");
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnSylvan1", "SylvanFront");
function FortressFront(heroename)
if ((GetCurrentPlayer () ~= whoishuman) and (GetHeroLevel (heroename) < GetHeroLevel (humanmainheroe)) ) then
LevelUpHero (heroename);
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnFortress1");
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnFortress1", "FortressFront");
function HavenFront(heroename)
if ((GetCurrentPlayer () ~= whoishuman) and (GetHeroLevel (heroename) < GetHeroLevel (humanmainheroe)) ) then
LevelUpHero (heroename);
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnHaven1");
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnHaven1", "HavenFront");
function DemonFront(heroename)
if ((GetCurrentPlayer () ~= whoishuman) and (GetHeroLevel (heroename) < GetHeroLevel (humanmainheroe)) ) then
LevelUpHero (heroename);
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnDemon1");
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnDemon1", "DemonFront");
function DarkEFront(heroename)
if ((GetCurrentPlayer () ~= whoishuman) and (GetHeroLevel (heroename) < GetHeroLevel (humanmainheroe)) ) then
LevelUpHero (heroename);
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnDarkE1");
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnDarkE1", "DarkEFront");
function ImperialFront(heroename)
if ((GetCurrentPlayer () ~= whoishuman) and (GetHeroLevel (heroename) < GetHeroLevel (humanmainheroe)) ) then
LevelUpHero (heroename);
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnImperialCity");
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnImperialCity", "ImperialFront");
-----------------------------------------------------
--Prisons--------------------------------------------
-----------------------------------------------------
function CyrusRescued()
if GetCurrentPlayer () == whoishuman and GetCurrentPlayer () == PLAYER_1 and academyprison == 0 then
MessageBox(path.."Academy Heroe Rescued.txt");
GiveExp ("Tan", 8000);
humansecondaryheroe = "Tan";
academyprison = 1;
SetObjectiveState ("Rescue Cyrus", OBJECTIVE_COMPLETED,PLAYER_1);
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Cyrus's Prison", nil );
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Cyrus's Prison", "CyrusRescued" );
function AlaronRescued()
if GetCurrentPlayer () == whoishuman and GetCurrentPlayer () == PLAYER_2 and sylvanprison == 0 then
MessageBox(path.."Sylvan Heroe Rescued.txt");
humansecondaryheroe = "Ildar";
GiveExp ("Ildar", 8000);
sylvanprison = 1;
SetObjectiveState ("Rescue Alaron", OBJECTIVE_COMPLETED,PLAYER_2);
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Alaron's Prison", nil );
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Alaron's Prison", "AlaronRescued" );
function WulfstanRescued()
if GetCurrentPlayer () == whoishuman and GetCurrentPlayer () == PLAYER_3 and fortressprison == 0 then
MessageBox(path.."Fortress Heroe Rescued.txt");
humansecondaryheroe = "Wulfstan";
GiveExp ("Wulfstan", 8000);
fortressprison = 1;
SetObjectiveState ("Rescue Wulfstan", OBJECTIVE_COMPLETED,PLAYER_3);
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Wulfstan's Prison", nil );
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Wulfstan's Prison", "WulfstanRescued" );
function NicolaiRescued()
if GetCurrentPlayer () == whoishuman and GetCurrentPlayer () == PLAYER_4 and havenprison == 0 then
MessageBox(path.."Haven Heroe Rescued.txt");
humansecondaryheroe = "Nicolai";
GiveExp ("Nicolai", 8000);
havenprison = 1;
SetObjectiveState ("Rescue Nicolai", OBJECTIVE_COMPLETED,PLAYER_4);
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Nicolai's Prison", nil );
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Nicolai's Prison", "NicolaiRescued" );
---------------------------------
--Haven Thieves Den--------------
---------------------------------
function theThievesDen(heroName)
heroewhofights = heroName;
-- ask fight thieves Y/N
if whoishuman == 4 then --human Haven only
if(theThievesDen_visited == 0) then
QuestionBox(path.."fightthievesYN.txt", "theThievesDenYes", "theThievesDenNo");
end;
end;
end;
Trigger (REGION_ENTER_AND_STOP_TRIGGER, "rgntheThievesDen", "theThievesDen" );
-- initiate combat
function theThievesDenYes(heroName)
StartCombat(heroewhofights,nil,4,71,10,73,5,73,5,71,10,nil,"winlose_theThievesDen");
end;
function winlose_theThievesDen() --gold, ore, wood if heroe lives
if IsHeroAlive( heroewhofights)~= nil then
theThievesDen_visited= 1 -- flag that den has been visited
resource = GetPlayerResource(4, 0) + random(3) + 5;
SetPlayerResource(4, 0, resource); --ore
resource = GetPlayerResource(4, 1) + random(3) + 5;
SetPlayerResource(4, 1, resource); --wood
resource = GetPlayerResource(4, 6) + random(2501) + 1000;--gold
SetPlayerResource(4, 6, resource);
MessageBox(path.."theThievesDenYes.txt");
theThievesDen_visited= 1;
SetObjectiveState ("Thieves Guild Trouble", OBJECTIVE_COMPLETED,PLAYER_4);
end;
end;
function theThievesDenNo()
MessageBox(path.."theThievesDenNo.txt"); --no combat, return later
end;
----------------------------------------------------------
--Sylvan Faery Ring (Magic Garden) Quest------------------
----------------------------------------------------------
function theFaeryRing(heroName)
heroewhofights = heroName;
-- ask fight demons Y/N
if whoishuman == 2 then --human Sylvan only
if(theFaeryRing_visited == 0) then
QuestionBox(path.."fightimpsYN.txt", "theFaeryRingYes", "theFaeryRingNo");
end;
end;
end;
Trigger (REGION_ENTER_AND_STOP_TRIGGER, "rgntheFaeryRing", "theFaeryRing" );
-- initiate combat
function theFaeryRingYes(heroName)
StartCombat(heroewhofights,nil,4,15,15,17,15,15,15,17,15,nil,"winlose_theFaeryRing");
end;
function winlose_theFaeryRing() --gold, ore, wood if heroe lives
if IsHeroAlive(heroewhofights)~= nil then
theFaeryRing_visited= 1 -- flag that garden has been visited
resource = GetPlayerResource(2, 0) + random(3) + 5;
SetPlayerResource(2, 0, resource); --ore
resource = GetPlayerResource(2, 1) + random(3) + 5;
SetPlayerResource(2, 1, resource); --wood
resource = GetPlayerResource(2, 6) + random(2501) + 1000;--gold
SetPlayerResource(2, 6, resource);
AddHeroCreatures(heroewhofights, 44, 10);
-- ChangeHeroStat (herowhofights, 7, 600); --bonus movement points
theFaeryRing_visited= 1;
SetObjectiveState ("FaeryRingTrouble", OBJECTIVE_COMPLETED,PLAYER_2);
MessageBox(path.."theFaeryRingYes.txt");
end;
end;
function theFaeryRingNo()
MessageBox(path.."theFaeryRingNo.txt"); --no combat, return later
end;
---------------------------------------------------------------------
-------Sylvan Touch Scripts------------------------------------------
---------------------------------------------------------------------
function FairyRing1Touched(heroname)
if ( (heroname == humanmainheroe) and (FairyRingVisited == 0) and (GetCurrentPlayer () == PLAYER_2) ) then
FairyRingVisited = 1;
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing1");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing1","FairyRing1Touched");
function FairyRing2Touched(heroname)
if ( (heroname == humanmainheroe) and (FairyRingVisited == 0) and (GetCurrentPlayer () == PLAYER_2) ) then
FairyRingVisited = 1;
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing2");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing2","FairyRing2Touched");
function FairyRing3Touched(heroname)
if ( (heroname == humanmainheroe) and (FairyRingVisited == 0) and (GetCurrentPlayer () == PLAYER_2) ) then
FairyRingVisited = 1;
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing3");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing3","FairyRing3Touched");
function FairyRing4Touched(heroname)
if ( (heroname == humanmainheroe) and (FairyRingVisited == 0) and (GetCurrentPlayer () == PLAYER_2) ) then
FairyRingVisited = 1;
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing4");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing4","FairyRing4Touched");
function FairyRing5Touched(heroname)
if ( (heroname == humanmainheroe) and (FairyRingVisited == 0) and (GetCurrentPlayer () == PLAYER_2) ) then
FairyRingVisited = 2;
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing5");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing5","FairyRing5Touched");
function FairyRing6Touched(heroname)
if ( (heroname == humanmainheroe) and (FairyRingVisited == 0) and (GetCurrentPlayer () == PLAYER_2) ) then
FairyRingVisited = 2;
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing6");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing6","FairyRing6Touched");
function FairyRing7Touched(heroname)
if ( (heroname == humanmainheroe) and (FairyRingVisited == 0) and (GetCurrentPlayer () == PLAYER_2) ) then
FairyRingVisited = 2;
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing7");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "FairyRing7","FairyRing7Touched");
---------------------------------------------------------------------
-------Dwarven Touch Scripts------------------------------------------
---------------------------------------------------------------------
function MagmaShrine1Touched(heroname)
if ( (heroname == humanmainheroe) and (magmashrinevisited == 0) and (GetCurrentPlayer () == PLAYER_3) ) then
magmashrinevisited = 1;
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
ChangeHeroStat(heroname, STAT_MANA_POINTS, 1000);--restore mana
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Magma Shrine1");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Magma Shrine1","MagmaShrine1Touched");
function MagmaShrine2Touched(heroname)
if ( (heroname == humanmainheroe) and (magmashrinevisited == 0) and (GetCurrentPlayer () == PLAYER_3) ) then
magmashrinevisited = 1;
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
ChangeHeroStat(heroname, STAT_MANA_POINTS, 1000);--restore mana
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Magma Shrine2");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Magma Shrine2","MagmaShrine2Touched");
----------------------------------------------------------------------
--Haven King Statue---------------------------------------------------
----------------------------------------------------------------------
function KingTouched(heroname)
if GetCurrentPlayer () == whoishuman then
if GetCurrentPlayer () == PLAYER_4 then
if kingblessing >= 1 then
MessageBox(path.."KingStatue1.txt");
ChangeHeroStat (heroname, 0, 1000+GetHeroLevel(heroname)*250);--increase experience
ChangeHeroStat (heroname, 7, 600*(1+random(3)));--movement bonus
kingblessing = 0;
end;
end;
end;
Trigger(OBJECT_TOUCH_TRIGGER, "Shrine of Kings");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Shrine of Kings","KingTouched");
function InnTouched(heroname)
if sleptyet >= 1 then
if GetCurrentPlayer () == whoishuman then
if GetCurrentPlayer () == PLAYER_4 then
ChangeHeroStat (heroname, 7, 600*(1+random(3))); --movement bonus for main haven heroe
sleptyet = 0;
end;
end;
ChangeHeroStat(heroname, STAT_MANA_POINTS, 1000);--restore mana for any heroe
end;
Trigger(OBJECT_TOUCH_TRIGGER, "Haven of Rest Inn");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Haven of Rest Inn","InnTouched");
function TempleTeleporter(heroname) --teleport human main heroe to endgame
if heroname == humanmainheroe then
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
SetObjectPosition(humanmainheroe, 152, 157, -1);
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Temple Teleporter");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Temple Teleporter","TempleTeleporter");
function TempleTeleporter2(heroname) --teleport human main heroe to endgame
if heroname == humanmainheroe then
ChangeHeroStat (heroname, 7, 600*(1+random(3)));
SetObjectPosition(humanmainheroe, 141, 155, -1);
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Temple Teleporter2");
end;
Trigger (OBJECT_TOUCH_TRIGGER, "Temple Teleporter2","TempleTeleporter2");
-----------------------------------------------------------
--Endgame messages----------------------------
-----------------------------------------------------------
function AncientTunnel(heroename)
if GetCurrentPlayer() == whoishuman then
MessageBox (path.."Ancient Tunnel.txt");
end;
Trigger (REGION_ENTER_AND_STOP_TRIGGER,"rgnBlockFinalRegion",nil);
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"rgnBlockFinalRegion","AncientTunnel");
function AncientLibrary(heroename)
if GetCurrentPlayer() == whoishuman then
MessageBox (path.."Underworld Library.txt");
end;
Trigger (REGION_ENTER_AND_STOP_TRIGGER,"rgnUnderLibrary",nil);
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"rgnUnderLibrary","AncientLibrary");
function AncientPrison(heroename)
if GetCurrentPlayer() == whoishuman then
MessageBox (path.."Red Slayer Prison.txt");
end;
Trigger (REGION_ENTER_AND_STOP_TRIGGER,"rgnRedSlayerPrison",nil);
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"rgnRedSlayerPrison","AncientPrison");
function ApproachSlayer(heroename)
if GetCurrentPlayer() == whoishuman then
MessageBox (path.."Approach Red Slayer.txt");
end;
Trigger (REGION_ENTER_AND_STOP_TRIGGER,"rgnApproachRedSlayer",nil);
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"rgnApproachRedSlayer","ApproachSlayer");
-------------------------------------------------------
--Graveyard Functions
-------------------------------------------------------
function AcademyGraveyard(heroename)
if (GetCurrentPlayer() == whoishuman and GetCurrentPlayer() == PLAYER_1) then
MessageBox ("Maps/SingleMissions/Shadow Dreams/EnterAcademyGraveyard.txt");
end;
Trigger (REGION_ENTER_AND_STOP_TRIGGER,"rgnAcademyGraveyard",nil);
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"rgnAcademyGraveyard","AcademyGraveyard");
function SylvanGraveyard(heroename)
if (GetCurrentPlayer() == whoishuman and GetCurrentPlayer() == PLAYER_2) then
MessageBox (path.."EnterSylvanGraveyard.txt");
end;
Trigger (REGION_ENTER_AND_STOP_TRIGGER,"rgnSylvanGraveyard",nil);
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"rgnSylvanGraveyard","SylvanGraveyard");
function FortressGraveyard(heroename)
if (GetCurrentPlayer() == whoishuman and GetCurrentPlayer() == PLAYER_3) then
MessageBox (path.."EnterFortressGraveyard.txt");
end;
Trigger (REGION_ENTER_AND_STOP_TRIGGER,"rgnFortressGraveyard",nil);
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"rgnFortressGraveyard","FortressGraveyard");
function HavenGraveyard(heroename)
if (GetCurrentPlayer() == whoishuman and GetCurrentPlayer() == PLAYER_4) then
MessageBox (path.."EnterHavenGraveyard.txt");
end;
Trigger (REGION_ENTER_AND_STOP_TRIGGER,"rgnHavenGraveyard",nil);
end;
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"rgnHavenGraveyard","HavenGraveyard");
---------------------------------------------------------------
--Grumpy Old Wizard: Yeah, I make a cameo apearance------------
---------------------------------------------------------------
function GrumpyOldWizardMessage(heroname)
if (GetCurrentPlayer() == whoishuman and GetCurrentPlayer() == PLAYER_1) then
MessageBox(path.."GrumpyOldWizardIntro.txt");
SetObjectiveState ("Find Tower Grump", OBJECTIVE_COMPLETED,PLAYER_1);
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnGrumpyOldWizard", nil );
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnGrumpyOldWizard", "GrumpyOldWizardMessage");
function GreyTowerBonus(heroname)
if greybonus == 1 and heroname == humanmainheroe then
ChangeHeroStat (heroname, 7, 600*(1+random(3))); --movement bonus for main haven heroe
ChangeHeroStat(heroname, STAT_MANA_POINTS, 1000);--restore mana
greybonus = 0;
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnTheGreyTower", nil );
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnTheGreyTower", "GreyTowerBonus");
-------------------------------------------------------------------
--Sea Events-------------------------------------------------------
-------------------------------------------------------------------
function SeaEvent01 (heroname)
if GetCurrentPlayer ()== whoishuman then --events only for human
eventoccur = random (2); --50% chance of event (for test purposes)
if eventoccur == 1 then --a random event happens (equal weight for test)
eventtypeis = random (2); --what kind of event?
if eventtypeis == 0 then -----event is message type
themessageis = random ( ; --specific message
if themessageis == 0 then
MessageBox(path.."SeaWhale.txt");
end;
if themessageis == 1 then
MessageBox(path.."SeaBirds.txt");
end;
if themessageis == 2 then
MessageBox (path.."SeaFishTales.txt");
end;
if themessageis == 3 then
MessageBox (path.."SeaWaterSpout.txt");
end;
if themessageis == 4 then
MessageBox (path.."SeaPirateCaptainClothes.txt");
end;
if themessageis == 5 then
MessageBox (path.."SeaPirateHook.txt");
end;
if themessageis == 6 then
MessageBox (path.."SeaParotSon.txt");
end;
if themessageis == 7 then
MessageBox (path.."SeaRoaches.txt");
end;
end;
if eventtypeis == 1 then -- Positive event type
theeventis = random (9); --specific positive event
if theeventis == 0 then
MessageBox(path.."SeaExperience.txt", ChangeHeroStat (heroname, 0, 1000+GetHeroLevel(heroname)*250));
end;
if theeventis == 1 then
MessageBox(path.."SeaMovement.txt", ChangeHeroStat (heroname, 7, 10));
end;
if theeventis == 2 then
MessageBox(path.."SeaGold.txt");
gold = GetPlayerResource(whoishuman, 6) + 1000 + random(2501);
SetPlayerResource(whoishuman, 6, gold);
end;
if theeventis == 3 then
for i = 2, 5, 1 do
resource = GetPlayerResource(whoishuman, i) + 1;
SetPlayerResource(whoishuman, i, resource);
end;
end;
if theeventis == 4 then
MessageBox(path.."SeaMovement2.txt", ChangeHeroStat (heroname, 7, 5 + random (6)));
end;
if eventis == 5 then
MessageBox(path.."SeaAttack.txt", ChangeHeroStat (heroname, 1, 1));
end;
if eventis == 6 then
MessageBox(path.."SeaDefense.txt", ChangeHeroStat (heroname, 2, 1));
end;
if eventis == 7 then
MessageBox(path.."SeaKnowledge.txt", ChangeHeroStat (heroname, 4, 1));
end;
if eventis == 8 then
MessageBox(path.."SeaSpellPower.txt", ChangeHeroStat (heroname, 3, 1));
end;
end;
end;
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnSea01");
end;
Trigger( REGION_ENTER_AND_STOP_TRIGGER, "rgnSea01", "SeaEvent01");
-----------------------------------------------------
--Messages for Quests: used on state-change triggers for objective
-----------------------------------------------------
function CapturedBridgeGarrison1() --(Armon) bridge
if whoishuman == 1 then
if GetObjectiveState("Recapture Armon", PLAYER_1) == OBJECTIVE_COMPLETED then
MessageBox(path.."CapturedBridgeGarrison1.txt");
end;
end;
end;
function SylvanCapturedBridgeGarrison() --(Armon) bridge
if whoishuman == 2 then
if GetObjectiveState("Sylvan Recapture Armon", PLAYER_2) == OBJECTIVE_COMPLETED then
MessageBox(path.."CapturedBridgeGarrison1.txt");
end;
end;
end;
function FortressCapturedBridgeGarrison() --(Armon) bridge
if whoishuman == 3 then
if GetObjectiveState("Fortress Recapture Armon", PLAYER_3) == OBJECTIVE_COMPLETED then
MessageBox(path.."CapturedBridgeGarrison2.txt");
end;
end;
end;
function HavenCapturedBridgeGarrison() --(Armon) bridge
if whoishuman == 4 then
if GetObjectiveState("Haven Recapture Armon", PLAYER_4) == OBJECTIVE_COMPLETED then
MessageBox(path.."CapturedBridgeGarrison2.txt");
end;
end;
end;
function TheMadPriests ()--for Fortress "Rogue Rune Priests"
if whoishuman == 3 then
if GetObjectiveState ("Rogue Rune Priests", PLAYER_3) == OBJECTIVE_COMPLETED then
MessageBox (path.."Tower of Fire Captured.txt");
end;
end;
end;
function TheGreyTowerLibrary ()
if whoishuman == 1 then
if GetObjectiveState ("Recapture the Grey Tower", PLAYER_1) == OBJECTIVE_COMPLETED then
MessageBox (path.."The Grey Tower Library.txt");--display when complete
else MessageBox (path.."Undead at the Grey Tower.txt");--display when quest given
end;
end;
end;
function thedickBadWolfDen ()
if whoishuman == 2 then
if GetObjectiveState ("The Big Bad Wolf", PLAYER_2) == OBJECTIVE_COMPLETED then
MessageBox (path.."BigBadWolfDead.txt");
end;
end;
end;
function StoneHavenDruids ()
if whoishuman == 2 then
if GetObjectiveState ("Druids Gone Wild", PLAYER_2) == OBJECTIVE_COMPLETED then
MessageBox (path.."Stone Haven Captured.txt");
else
MessageBox (path.."Stone Haven Madness.txt");
end;
end;
end;
function theGrailQuest ()
if GetObjectiveState ("Find the Tear", whoishuman) == OBJECTIVE_COMPLETED then
MessageBox (path.."Found Tear.txt");
else MessageBox (path.."Grail Quest.txt");
end;
end;
function RedSlayerDefeated ()
if GetObjectiveState ("Defeat the Red Slayer", whoishuman) == OBJECTIVE_COMPLETED then
MessageBox (path.."Defeated Red Slayer.txt", Win());
end;
end;
function StoneDemonsDefeated()
if GetObjectiveState ("Get Stoned", whoishuman) == OBJECTIVE_COMPLETED then
MessageBox (path.."StoneDemonsDefeated.txt");
end;
end;
-----------------------------------------------------------------
--Combat Scripts
-----------------------------------------------------------------
------------------------------------------------------------------
--Quest Huts
------------------------------------------------------------------
-----------------------------------------------
--check for stuff to do on various days--------
-----------------------------------------------
function reducecount()
startnumberofheroes = startnumberofheroes - 1
end;
function addskills()
print("Add skills Function");
--print(GetDate(DAY));
--print(humanplayer);
print(startnumberofheroes);
playernames = GetPlayerHeroes(numhumanplayer);
print(length(playernames));
for i = startnumberofheroes, length(playernames) - 1 do
--print(startnumberofheroes);
--print(length(playernames));
print(playernames[i]);
GiveArtefact(playernames[i], 4);
GiveArtefact(playernames[i], 95);
GiveArtefact(playernames[i], 34);
GiveArtefact(playernames[i], 35);
GiveArtefact(playernames[i], 21);
GiveArtefact(playernames[i], 22);
GiveArtefact(playernames[i], 24);
GiveArtefact(playernames[i], 37);
GiveArtefact(playernames[i], 40);
ChangeHeroStat(playernames[i], 1, 15);
ChangeHeroStat(playernames[i], 2, 10);
ChangeHeroStat(playernames[i], 3, 10);
ChangeHeroStat(playernames[i], 4, 10);
ChangeHeroStat(playernames[i], 8, 50);
for x = 1, 3 do
GiveHeroSkill(playernames[i], 2);
GiveHeroSkill(playernames[i], 3);
GiveHeroSkill(playernames[i], 6);
GiveHeroSkill(playernames[i], 7);
GiveHeroSkill(playernames[i], 9);
GiveHeroSkill(playernames[i], 1);
GiveHeroSkill(playernames[i], 4);
GiveHeroSkill(playernames[i], 5);
GiveHeroSkill(playernames[i], ;
GiveHeroSkill(playernames[i], 10);
GiveHeroSkill(playernames[i], 11);
GiveHeroSkill(playernames[i], 12);
end;
GiveHeroWarMachine(playernames[i], 1);
GiveHeroWarMachine(playernames[i], 3);
GiveHeroWarMachine(playernames[i], 4);
GiveHeroSkill(playernames[i], 74);
GiveHeroSkill(playernames[i], 8 ;
GiveHeroSkill(playernames[i], 139);
GiveHeroSkill(playernames[i], 100);
GiveHeroSkill(playernames[i], 126);
GiveHeroSkill(playernames[i], 22);
GiveHeroSkill(playernames[i], 23);
GiveHeroSkill(playernames[i], 24);
GiveHeroSkill(playernames[i], 25);
GiveHeroSkill(playernames[i], 34);
GiveHeroSkill(playernames[i], 35);
GiveHeroSkill(playernames[i], 130);
GiveHeroSkill(playernames[i], 117);
GiveHeroSkill(playernames[i], 104);
GiveHeroSkill(playernames[i], 91);
GiveHeroSkill(playernames[i], 76);
GiveHeroSkill(playernames[i], 36);
GiveHeroSkill(playernames[i], 3 ;
GiveHeroSkill(playernames[i], 39);
GiveHeroSkill(playernames[i], 118);
GiveHeroSkill(playernames[i], 144);
GiveHeroSkill(playernames[i], 131);
GiveHeroSkill(playernames[i], 105);
GiveHeroSkill(playernames[i], 37);
GiveHeroSkill(playernames[i], 44);
GiveHeroSkill(playernames[i], 82);
GiveHeroSkill(playernames[i], 146);
GiveHeroSkill(playernames[i], 133);
GiveHeroSkill(playernames[i], 120);
GiveHeroSkill(playernames[i], 94);
GiveHeroSkill(playernames[i], 43);
GiveHeroSkill(playernames[i], 45);
GiveHeroSkill(playernames[i], 40);
GiveHeroSkill(playernames[i], 41);
GiveHeroSkill(playernames[i], 42);
GiveHeroSkill(playernames[i], 81);
GiveHeroSkill(playernames[i], 93);
GiveHeroSkill(playernames[i], 119);
GiveHeroSkill(playernames[i], 132);
GiveHeroSkill(playernames[i], 145);
GiveHeroSkill(playernames[i], 138);
GiveHeroSkill(playernames[i], 112);
GiveHeroSkill(playernames[i], 73);
GiveHeroSkill(playernames[i], 19);
GiveHeroSkill(playernames[i], 20);
GiveHeroSkill(playernames[i], 21);
GiveHeroSkill(playernames[i], 86);
GiveHeroSkill(playernames[i], 125);
GiveHeroSkill(playernames[i], 2 ;
GiveHeroSkill(playernames[i], 29);
GiveHeroSkill(playernames[i], 30);
GiveHeroSkill(playernames[i], 115);
GiveHeroSkill(playernames[i], 75);
GiveHeroSkill(playernames[i], 89);
GiveHeroSkill(playernames[i], 128);
GiveHeroSkill(playernames[i], 141);
GiveHeroSkill(playernames[i], 116);
GiveHeroSkill(playernames[i], 129);
GiveHeroSkill(playernames[i], 142);
GiveHeroSkill(playernames[i], 31);
GiveHeroSkill(playernames[i], 32);
GiveHeroSkill(playernames[i], 33);
GiveHeroSkill(playernames[i], 80);
GiveHeroSkill(playernames[i], 46);
GiveHeroSkill(playernames[i], 47);
GiveHeroSkill(playernames[i], 4 ;
GiveHeroSkill(playernames[i], 95);
GiveHeroSkill(playernames[i], 121);
GiveHeroSkill(playernames[i], 134);
GiveHeroSkill(playernames[i], 147);
GiveHeroSkill(playernames[i], 49);
GiveHeroSkill(playernames[i], 50);
GiveHeroSkill(playernames[i], 51);
GiveHeroSkill(playernames[i], 81);
GiveHeroSkill(playernames[i], 7 ;
GiveHeroSkill(playernames[i], 96);
GiveHeroSkill(playernames[i], 109);
GiveHeroSkill(playernames[i], 122);
GiveHeroSkill(playernames[i], 135);
GiveHeroSkill(playernames[i], 148);
GiveHeroSkill(playernames[i], 52);
GiveHeroSkill(playernames[i], 53);
GiveHeroSkill(playernames[i], 54);
GiveHeroSkill(playernames[i], 84);
GiveHeroSkill(playernames[i], 97);
GiveHeroSkill(playernames[i], 110);
GiveHeroSkill(playernames[i], 123);
GiveHeroSkill(playernames[i], 136);
GiveHeroSkill(playernames[i], 169);
GiveHeroSkill(playernames[i], 163);
ChangeHeroStat(playernames[i], 0, 170000);
for x = 1, 15 do
TeachHeroSpell(playernames[i], x);
end;
for x = 17, 21 do
TeachHeroSpell(playernames[i], x);
end;
for x = 23, 26 do
TeachHeroSpell(playernames[i], x);
end;
for x = 28, 29 do
TeachHeroSpell(playernames[i], x);
end;
for x = 38, 43 do
TeachHeroSpell(playernames[i], x);
end;
for x = 48, 51 do
TeachHeroSpell(playernames[i], x);
end;
for x = 35, 35 do
TeachHeroSpell(playernames[i], x);
end;
MakeHeroReturnToTavernAfterDeath(playernames[i], not nil, 1);
--addperks(playernames[i]);
--print(playernames[i]);
--print(playernames[i]); --Print the name whose skills altered
end;
startnumberofheroes = length(playernames);
end;
if GetDate(DAY) == 1 then
print("Set Reources");
for x = 0, 6 do
if x < 6 then
SetPlayerResource(numhumanplayer, x, 1000);
else SetPlayerResource(numhumanplayer, x, 100000);
end;
end;
startnumberofheroes = 0;
--print(startnumberofheroes);
addskills()
end;
function NewDayTrigger()
playernames = GetPlayerHeroes(numhumanplayer);
--print(playernames);
print("Add Perks Function");
if mod(GetDate(DAY),7) == 0 then
if GetCurrentPlayer() == numhumanplayer then
for i = 0, length(playernames) do
if HasHeroSkill(playernames[i], 13) then
--Add Haven Creastures
AddHeroCreatures(playernames[i], 2, 30);
AddHeroCreatures(playernames[i], 4, 24);
AddHeroCreatures(playernames[i], 6, 1 ;
AddHeroCreatures(playernames[i], 8, 12);
AddHeroCreatures(playernames[i], 10, 6);
AddHeroCreatures(playernames[i], 12, 4);
AddHeroCreatures(playernames[i], 14, 2);
elseif HasHeroSkill(playernames[i], 14) then
--Add Inferno Creatures
AddHeroCreatures(playernames[i], 16, 30);
AddHeroCreatures(playernames[i], 18, 24);
AddHeroCreatures(playernames[i], 20, 1 ;
AddHeroCreatures(playernames[i], 22, 12);
AddHeroCreatures(playernames[i], 24, 6);
AddHeroCreatures(playernames[i], 26, 4);
AddHeroCreatures(playernames[i], 28, 2);
elseif HasHeroSkill(playernames[i], 15) then
--Add Necro Creatures
AddHeroCreatures(playernames[i], 30, 30);
AddHeroCreatures(playernames[i], 32, 24);
AddHeroCreatures(playernames[i], 34, 1 ;
AddHeroCreatures(playernames[i], 36, 12);
AddHeroCreatures(playernames[i], 38, 6);
AddHeroCreatures(playernames[i], 40, 4);
AddHeroCreatures(playernames[i], 42, 2);
elseif HasHeroSkill(playernames[i], 16) then
--Add Sylvan Creatures
AddHeroCreatures(playernames[i], 44, 30);
AddHeroCreatures(playernames[i], 46, 24);
AddHeroCreatures(playernames[i], 48, 1 ;
AddHeroCreatures(playernames[i], 50, 12);
AddHeroCreatures(playernames[i], 52, 6);
AddHeroCreatures(playernames[i], 54, 4);
AddHeroCreatures(playernames[i], 56, 2);
elseif HasHeroSkill(playernames[i], 17) then
--Add Academy Creatures
AddHeroCreatures(playernames[i], 58, 30);
AddHeroCreatures(playernames[i], 60, 24);
AddHeroCreatures(playernames[i], 62, 1 ;
AddHeroCreatures(playernames[i], 64, 12);
AddHeroCreatures(playernames[i], 66, 6);
AddHeroCreatures(playernames[i], 68, 4);
AddHeroCreatures(playernames[i], 70, 2);
elseif HasHeroSkill(playernames[i], 1 then
--Add Dungeon Creatues
AddHeroCreatures(playernames[i], 72, 30);
AddHeroCreatures(playernames[i], 74, 24);
AddHeroCreatures(playernames[i], 76, 1 ;
AddHeroCreatures(playernames[i], 78, 12);
AddHeroCreatures(playernames[i], 80, 6);
AddHeroCreatures(playernames[i], 82, 4);
AddHeroCreatures(playernames[i], 84, 2);
--else;
end;
end;
--else;
end;
end;
for i = startnumberofheroes, length(playernames) - 1 do
GiveHeroSkill(playernames[i], 74);
GiveHeroSkill(playernames[i], 8 ;
GiveHeroSkill(playernames[i], 139);
GiveHeroSkill(playernames[i], 100);
GiveHeroSkill&#
|
|
| Back to top |
|
 |
LeFiXER Grandmaster Cheater Supreme
Reputation: 20
Joined: 02 Sep 2011 Posts: 1069 Location: 0x90
|
Posted: Sat Dec 16, 2023 9:25 pm Post subject: |
|
|
| You could have attached it as a file, or used pastebin, or something similar.
|
|
| Back to top |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 37
Joined: 16 Feb 2017 Posts: 1527
|
Posted: Sun Dec 17, 2023 3:15 pm Post subject: |
|
|
Go back to the error code (first post) and fix this line;
| Code: | print(length(playernames));
for i = startnumberofheroes, length(playernames)
print(playernames[i]); |
| Code: | | for i = startnumberofheroes, length(playernames) |
Use (do)
| Code: | | for i = startnumberofheroes, length(playernames) do |
Edit:
If you're sure it's a table, shorten the code;
| Code: | function length(table)
if type(table)=="table" then
--print(#table,table[2])
return #table
else
return "not table"
end
end
tbl = {"a","b","c","d"}
print(11, length(tbl))
tbl1 = 12
print(12, length(tbl1))
--- use
exnumber = 2
for i=exnumber, #tbl do
print(i,tbl[i])
end |
_________________
|
|
| Back to top |
|
 |
bknight2602 Grandmaster Cheater
Reputation: 0
Joined: 08 Oct 2012 Posts: 586
|
Posted: Tue Dec 19, 2023 2:47 pm Post subject: |
|
|
Well what I did was delete all the new code and then recopied the one that works, and it works fine. Thanks.
AylinCE two answers, the original for statement did have a do in it and I don't know why it didn't paste. As for the table, yes it should be, but your code suggestion is way over my head. Thanks for the time though.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|