Witch hut scripting

Maps and the art of mapmaking.
User avatar
fiur
Pixie
Pixie
Posts: 129
Joined: 06 Jan 2006

Witch hut scripting

Unread postby fiur » 26 Dec 2007, 22:07

I've search the forum for this kind of script:
I wanna give an spesific witch hut an spesific skill
how do I make this script?

User avatar
fiur
Pixie
Pixie
Posts: 129
Joined: 06 Jan 2006

Unread postby fiur » 27 Dec 2007, 08:18

well I manage to get the script to work (alomst)
it's for H5 tote.....

here is the scrips (it gives logistics).... :
SetObjectEnabled("hut", nil);
function WitchHut(heroName)
GiveHeroSkill(heroName, 1);
MarkObjectAsVisited("hut", heroName);
Trigger(OBJECT_TOUCH_TRIGGER, "hut",nil);
end;
Trigger(OBJECT_TOUCH_TRIGGER, "hut", "WitchHut");

but it only works for the first visitng hero... :8 I want it to work for any heroes...
and another thing (I manage to put an message in ("you got logistics")
but I want onw more...... (when you right click on the hut I want an message who tells you what skills you can get)......

Neckie
Peasant
Peasant
Posts: 67
Joined: 05 Oct 2006
Location: Quebec, Canada

Unread postby Neckie » 27 Dec 2007, 14:41

You really should look at my All For One (HoF) map everything is there but here is what you want.

Code: Select all

humanplayer = GetCurrentPlayer();
visitedHut={} 
skills={"Logistics","Warmachines","Learning","Leadership","Luck","Offense","Defenseskill","Sorcery","DestructiveMagic","DarkMagic","LightMagic","SummoningMagic"}
skill_level={"Basic","Advanced","Expert"}
SetObjectEnabled("hut", nil);
hut_skill = random(12)+1

OverrideObjectTooltipNameAndDescription("hut", , GetMapDataPath().."HutDesc/"..skills[hut_skill]..'.txt');

hero = 0

function WitchHut(heroName)
if GetCurrentPlayer() == humanplayer then
	hero = heroname;
	numberofskills = 0;
		for i = 1, 12 do									
			if HasHeroSkill(hero, i) == true then
				numberofskills = numberofskills + 1;
			end;
		end;
        if visitedHut[hero]~=1 and GetHeroSkillMastery(hero, hut_skill) <= 2 and numberofskills < 5 then
		QuestionBox({GetMapDataPath()..'hutCoice.txt'; skillname = GetMapDataPath().."Skills/"..skills[hut_skill]..'.txt', skillmastery = GetMapDataPath().."Skills/"..skill_level[(GetHeroSkillMastery(hero, hut_skill)+1)]..'.txt'}, "hutyes");
	elseif visitedHut[hero]==1 then
		MessageBox(GetMapDataPath()..'HutSecondVisit.txt');	
	else
		MessageBox(GetMapDataPath()..'Hutcantlearn.txt');	
	end;
else	
	GiveHeroSkill (heroName, hut_skill);
	SetAIHeroAttractor('Hut', heroName, -1);
end;
end;

Trigger(OBJECT_TOUCH_TRIGGER, "hut", "WitchHut");

 function hutyes()
	visitedHut[hero]=1;
	GiveHeroSkill(hero, hut_skill);
	MarkObjectAsVisited("hut", hero);
end;
In hutChoice.txt you should write :
Do you want <value=skillmastery> <value=skillname> ?

You should have folders Skills and HutDesc at
mapname.h5m\Maps\SingleMissions\mapname\Skills
mapname.h5m\Maps\SingleMissions\mapname\HutDesc

In the Skills folder you should have txt files named exactly the same as in your skill and skill_level arrays where the only thing you write in it is for example :
for Expert.txt : expert
for LightMagic.txt : Light Magic

In the HutDesc folder you should have txt files named exactly the same as in your skill array where you will write the correct description for each of them.

Nothing of this code is tested so it will most likely have an "end" missing or something so you should make the corrections but you've got the main script.

I never used the OverrideObjectTooltipNameAndDescription function so I can't say it will work but it should.

For the function itself, its some parts of some of my functions in my map "All For One (HoF)" put together.

One part I'm not so sure if it will work is skill_level[(GetHeroSkillMastery(hero, hut_skill)+1)] maybe you'll have to do something like :
temp = GetHeroSkillMastery(hero, hut_skill)+1
[...] skill_level[temp] [...]

If it's a single mission or a multiplayer map with like 2 players (with messageboxforplayer for ids 1 and 2) you will be able to manage the computer/human players but its impossible to do it for more players. Since the normal messageboxes are global (every player gets it and only the first to press Ok will get the callback function) and the messageboxforplayer function only works for IDs 1 and 2 (see here).
I hope it works !
Last edited by Neckie on 28 Dec 2007, 18:21, edited 1 time in total.

User avatar
fiur
Pixie
Pixie
Posts: 129
Joined: 06 Jan 2006

Unread postby fiur » 27 Dec 2007, 23:59

thanks alot Neckie but I'm an complete "newbie" in scripting.. so this is way to much for me to handle... :(

the skill I want the hut to give is Logistics only... is there a way to simplify the script....???

Neckie
Peasant
Peasant
Posts: 67
Joined: 05 Oct 2006
Location: Quebec, Canada

Unread postby Neckie » 28 Dec 2007, 03:48

Code: Select all

SetObjectEnabled("hut", nil); 
visitedHut={} 
hero = 0 
humanplayer = GetCurrentPlayer(); 

function WitchHut(heroName) 
if GetCurrentPlayer() == humanplayer then 
        hero = heroName; 
        if visitedHut[hero]~=1 and GetHeroSkillMastery(hero,1) <= 2 then 
                QuestionBox(GetMapDataPath()..'HutFirstVisit.txt', "hutyes"); 
        elseif visitedHut[hero]==1 then 
                MessageBox(GetMapDataPath()..'HutSecondVisit.txt');    
        else 
                MessageBox(GetMapDataPath()..'Hutcantlearn.txt');    
        end; 
else    
        GiveHeroSkill (heroName, 1); 
        SetAIHeroAttractor('Hut', heroName, -1); 
end; 
end;

function hutyes() 
        visitedHut[hero]=1; 
        GiveHeroSkill(hero, 1); 
        MarkObjectAsVisited("hut", hero); 
end; 
Trigger(OBJECT_TOUCH_TRIGGER, "hut", "WitchHut"); 
To change the object description just create a new shared value of your building based on the witch hut one but with a new description.

You can write what you want in the 3 texts files which are in the WitchHut function. You could put only 1 messagebox instead of 2 depending on what you write in those texts.

I hope it's what you wanted. If not plz give more details :).
Last edited by Neckie on 28 Dec 2007, 18:20, edited 1 time in total.

User avatar
fiur
Pixie
Pixie
Posts: 129
Joined: 06 Jan 2006

Unread postby fiur » 28 Dec 2007, 16:32

well Necike I've testet the script and my hut always give random skills...
:(
I've modified the scrips a bit but still same result.... therefore I've uploaded an test map so you can look into it by yourself (if you please...and got the time to do it...)
it's only 2 towns and 1 witch hut on the map....
(I want the hut to always give you logistics and to all visiting heroes....)

on the map where I wanna use this "hut" I need 2 witch hut's can I copy the "scripted" one over to the opponent side of the map or do I need to make an new script for another hut?

Test map

Neckie
Peasant
Peasant
Posts: 67
Joined: 05 Oct 2006
Location: Quebec, Canada

Unread postby Neckie » 28 Dec 2007, 18:29

I updated my last post with the script you should copy and paste in your script (overwrite your last one) so that it works. There were 3 problems :
1- You changed GetMapDataPath().. for your map path but that function do it for yourself. If you really want the full path the correct syntax is "/Maps/Multiplayer/mapname/text.txt".
2- I forgot an end; in the first function.
3- wrote visitedSchool instead of visitedHut in second function (copy/paste error from my map)

If you want more than 1 hut to execute that script you need to give another script name to the other hut (like hut2) and then in the script add :
SetObjectEnabled("hut2", nil);
Trigger(OBJECT_TOUCH_TRIGGER, "hut2", "WitchHut");

User avatar
fiur
Pixie
Pixie
Posts: 129
Joined: 06 Jan 2006

Unread postby fiur » 29 Dec 2007, 00:03

Neckie wrote:
If you want more than 1 hut to execute that script you need to give another script name to the other hut (like hut2) and then in the script add :
SetObjectEnabled("hut2", nil);
Trigger(OBJECT_TOUCH_TRIGGER, "hut2", "WitchHut");
well Neckie I'm close now... (hopefully...)
when I only has one hut with the script on the map it works like an sharm... but when I add the second hut (with the name hut2) the scrpit get messed up... so my question is.. how would the script look like with 2 huts....? (if you could put the two lines into the script for me.... plz....) :)

Neckie
Peasant
Peasant
Posts: 67
Joined: 05 Oct 2006
Location: Quebec, Canada

Unread postby Neckie » 29 Dec 2007, 14:11

Code: Select all

SetObjectEnabled("hut", nil);
SetObjectEnabled("hut2", nil);
visitedHut={}
hero = 0
humanplayer = GetCurrentPlayer();

function WitchHut(heroName)
if GetCurrentPlayer() == humanplayer then
        hero = heroName;
        if visitedHut[hero]~=1 and GetHeroSkillMastery(hero,1) <= 2 then
                QuestionBox(GetMapDataPath()..'HutFirstVisit.txt', "hutyes");
        elseif visitedHut[hero]==1 then
                MessageBox(GetMapDataPath()..'HutSecondVisit.txt');   
        else
                MessageBox(GetMapDataPath()..'Hutcantlearn.txt');   
        end;
else   
        GiveHeroSkill (heroName, 1);
        SetAIHeroAttractor('Hut', heroName, -1);
end;
end;

function hutyes()
        visitedHut[hero]=1;
        GiveHeroSkill(hero, 1);
        MarkObjectAsVisited("hut", hero);
end;
Trigger(OBJECT_TOUCH_TRIGGER, "hut", "WitchHut"); 
Trigger(OBJECT_TOUCH_TRIGGER, "hut2", "WitchHut"); 

User avatar
fiur
Pixie
Pixie
Posts: 129
Joined: 06 Jan 2006

Unread postby fiur » 29 Dec 2007, 14:48

Neckie wrote:

Code: Select all

SetObjectEnabled("hut", nil);
SetObjectEnabled("hut2", nil);
visitedHut={}
hero = 0
humanplayer = GetCurrentPlayer();

function WitchHut(heroName)
if GetCurrentPlayer() == humanplayer then
        hero = heroName;
        if visitedHut[hero]~=1 and GetHeroSkillMastery(hero,1) <= 2 then
                QuestionBox(GetMapDataPath()..'HutFirstVisit.txt', "hutyes");
        elseif visitedHut[hero]==1 then
                MessageBox(GetMapDataPath()..'HutSecondVisit.txt');   
        else
                MessageBox(GetMapDataPath()..'Hutcantlearn.txt');   
        end;
else   
        GiveHeroSkill (heroName, 1);
        SetAIHeroAttractor('Hut', heroName, -1);
end;
end;

function hutyes()
        visitedHut[hero]=1;
        GiveHeroSkill(hero, 1);
        MarkObjectAsVisited("hut", hero);
end;
Trigger(OBJECT_TOUCH_TRIGGER, "hut", "WitchHut"); 
Trigger(OBJECT_TOUCH_TRIGGER, "hut2", "WitchHut"); 
well Neckie thats what I did.... and for the first player it works fine... but when its the 2'nd players turn all messages for the first player shows up and when he visit his hut he get's adv. log... and then I can't enter the detail view of the hero..... so something must be wrong here....??

Neckie
Peasant
Peasant
Posts: 67
Joined: 05 Oct 2006
Location: Quebec, Canada

Unread postby Neckie » 29 Dec 2007, 20:21

Oops sorry my bad for the wrong code... thats the reason why i used multiple functions in my map.

Code: Select all

SetObjectEnabled("hut", nil);
SetObjectEnabled("hut2", nil);
visitedHut={}
visitedHut2={}
hero = 0

function WitchHut(heroName)
if GetCurrentPlayer() == 1 or GetCurrentPlayer() == 2 then
        hero = heroName;
        if visitedHut[hero]~=1 and GetHeroSkillMastery(hero,1) <= 2 then
                QuestionBoxForPlayers(GetCurrentPlayer(),GetMapDataPath()..'HutFirstVisit.txt', "hutyes");
        elseif visitedHut[hero]==1 then
                MessageBoxForPlayers(GetCurrentPlayer(),GetMapDataPath()..'HutSecondVisit.txt');   
        else
                MessageBoxForPlayers(GetCurrentPlayer(),GetMapDataPath()..'Hutcantlearn.txt');   
        end;
else   
      if visitedHut[heroName]~=1 then
        GiveHeroSkill(heroName, 1);
	  visitedHut[heroName]=1;
        SetAIHeroAttractor('hut', heroName, -1);
	else
	  SetAIHeroAttractor('hut', heroName, -1);
	end;
end;
end;

function hutyes()
        visitedHut[hero]=1;
        GiveHeroSkill(hero, 1);
        MarkObjectAsVisited("hut", hero);
end;

function WitchHut2(heroName)
if GetCurrentPlayer() == 1 or GetCurrentPlayer() == 2 then
        hero = heroName;
        if visitedHut2[hero]~=1 and GetHeroSkillMastery(hero,1) <= 2 then
                QuestionBoxForPlayers(GetCurrentPlayer(),GetMapDataPath()..'HutFirstVisit.txt', "hutyes2");
        elseif visitedHut2[hero]==1 then
                MessageBoxForPlayers(GetCurrentPlayer(),GetMapDataPath()..'HutSecondVisit.txt');   
        else
                MessageBoxForPlayers(GetCurrentPlayer(),GetMapDataPath()..'Hutcantlearn.txt');   
        end;
else   
      if visitedHut2[heroName]~=1 then
        GiveHeroSkill(heroName, 1);
	  visitedHut2[heroName]=1;
        SetAIHeroAttractor('hut2', heroName, -1);
	else
	  SetAIHeroAttractor('hut2', heroName, -1);
	end;
end;
end;

function hutyes2()
        visitedHut2[hero]=1;
        GiveHeroSkill(hero, 1);
        MarkObjectAsVisited("hut2", hero);
end;
Trigger(OBJECT_TOUCH_TRIGGER, "hut", "WitchHut"); 
Trigger(OBJECT_TOUCH_TRIGGER, "hut2", "WitchHut2");
Ok this is really important :
There CANT be more than 2 human player in the map and they MUST be ids 1 and 2 else IT WONT WORK. Thats because those message/question box for players functions are bugged and only works for IDs 1 and 2.

There is a way to make the script work with only one function but its complicated and this works just fine so why not use it.

You could make the script work for any number of human player but that would require that you remove the message boxes and replace them with flying messages and you could make that the first time the hero visits the flying message tells the player that he must revisit if he wants to learn logistics.


Return to “Mapmaking Guild”

Who is online

Users browsing this forum: No registered users and 1 guest