Heroes of Might and Magic Community
visiting hero! Register | Today's Posts | Games | Search! | FAQ/Rules | AvatarList | MemberList | Profile


Age of Heroes Headlines:  
5 Oct 2016: Heroes VII development comes to an end.. - read more
6 Aug 2016: Troubled Heroes VII Expansion Release - read more
26 Apr 2016: Heroes VII XPack - Trial by Fire - Coming out in June! - read more
17 Apr 2016: Global Alternative Creatures MOD for H7 after 1.8 Patch! - read more
7 Mar 2016: Romero launches a Piano Sonata Album Kickstarter! - read more
19 Feb 2016: Heroes 5.5 RC6, Heroes VII patch 1.7 are out! - read more
13 Jan 2016: Horn of the Abyss 1.4 Available for Download! - read more
17 Dec 2015: Heroes 5.5 update, 1.6 out for H7 - read more
23 Nov 2015: H7 1.4 & 1.5 patches Released - read more
31 Oct 2015: First H7 patches are out, End of DoC development - read more
5 Oct 2016: Heroes VII development comes to an end.. - read more
[X] Remove Ads
LOGIN:     Username:     Password:         [ Register ]
HOMM1: info forum | HOMM2: info forum | HOMM3: info mods forum | HOMM4: info CTG forum | HOMM5: info mods forum | MMH6: wiki forum | MMH7: wiki forum
Heroes Community > Heroes 5 - Modders Workshop > Thread: Newbie scripter needing help
Thread: Newbie scripter needing help This thread is 2 pages long: 1 2 · NEXT»
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 27, 2007 07:40 PM

Newbie scripter needing help

Soooo I decided to finally get more in-depth into the HV script and all that, so I went to modding wiki to try Kronos' tutorial.

So far so good, but when I went to experiment a bit more, I got stuck. Getting a message to appeat say, day 3, works just fine.

When I wanted to have a message appear on day 2 and 3, it didn't work. At first I thought I somehow screwed up the script (I copy / pasted the first function that worked and gave it a different name), but when I further experimented and added a third function, I found that both the first two functions are annoyed. Doesn't matter what order I put the junk, only the last function is performed, the others are simply ignored.

function bobbie()
if GetDate(DAY_OF_WEEK) == 3 then
MessageBox("Maps/SingleMissions/Elf tutorial/text3.txt")
end;
end;

Trigger(NEW_DAY_TRIGGER, "bobbie");

function bob()
if GetDate(DAY_OF_WEEK) == 2 then
MessageBox("Maps/SingleMissions/Elf tutorial/text2.txt")
end;
end;

Trigger(NEW_DAY_TRIGGER, "bob");

function abe()
if GetDate(DAY_OF_WEEK) == 4 then
MessageBox("Maps/SingleMissions/Elf tutorial/text3.txt")
end;
end;

Trigger(NEW_DAY_TRIGGER, "abe");


The text files are fine, no problem with that. It just ignores the first two functions. Doesn't matter what order I put them, it only performs the last one.

Also, what's the point of adding () at the end of the function name?

Also, how come the script says the function is invalid (while in-game, it just works), while when you add " and " to the function name, so the script checker says it's OK, in-game it DOESN't work ? Corrupt scriptchecker?

PS: Yes I'm new at this so you lot will probably get more questions about scripting.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kronos1000
Kronos1000


Promising
Supreme Hero
Frysln Boppe
posted September 27, 2007 07:56 PM
Edited by Kronos1000 at 19:58, 27 Sep 2007.

Read closely, you must not add multiple functions with the same argumments so not like this:

Quote:
function bobbie()
if GetDate(DAY_OF_WEEK) == 3 then
MessageBox("Maps/SingleMissions/Elf tutorial/text3.txt")
end;
end;

Trigger(NEW_DAY_TRIGGER, "bobbie");

function bob()
if GetDate(DAY_OF_WEEK) == 2 then
MessageBox("Maps/SingleMissions/Elf tutorial/text2.txt")
end;
end;

Trigger(NEW_DAY_TRIGGER, "bob");

function abe()
if GetDate(DAY_OF_WEEK) == 4 then
MessageBox("Maps/SingleMissions/Elf tutorial/text3.txt")
end;
end;

Trigger(NEW_DAY_TRIGGER, "abe");


But like:

function bobbie()
if GetDate(DAY_OF_WEEK) == 3 then
MessageBox("Maps/SingleMissions/Elf tutorial/text3.txt")
end;

if GetDate(DAY_OF_WEEK) == 4 then
MessageBox("Maps/SingleMissions/Elf tutorial/text3.txt")
end;

if GetDate(DAY_OF_WEEK) == 2 then
MessageBox("Maps/SingleMissions/Elf tutorial/text2.txt")
end;
end;

Trigger(NEW_DAY_TRIGGER, "bobbie");

You see all in one function a function can have multiple if's I thought I wrote it in my Tutorial.

And the () is required for for any function, but it only has a purpose in harder functions I'll not spoil that (I believe it's in the Advanced guide )
____________
Hwr cwom mearg? Hwr cwom mago?
Hwr cwom maumgyfa? - 'The Wanderer'

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 27, 2007 09:13 PM

Well yeah it did mention you can add multiple ifs but it never said it was REQUIRED

Sooo, basicly, when do you know you need to make a new function? Which ones need to be grouped? All the ones featuring the same trigger requirement? Such as  the NEW_DAY_TRIGGER trigger? Or is some other needed?

Thanks for clarifying this btw

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
dschingi
dschingi


Famous Hero
the guy with the dragon golem
posted September 27, 2007 09:48 PM

IIRC there can be only one function connected with the NEW_DAY_TRIGGER at a time, so if you associate 3 functions with it it won't work. That's probably why Kronos said you need to put everything in one function.
Do you need functions for other purposes than the NEW_DAY_TRIGGER? I think it's easier to explain on specific cases here.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kronos1000
Kronos1000


Promising
Supreme Hero
Frysln Boppe
posted September 27, 2007 10:32 PM

Actually since he is a novice scripter I didn't want to say something like: Only one function can be used with the same kind of arrguments. For those who can't follow me I'll explain: NEW_DAY_TRIGGER has no argumments so it's the simplest Trigger to use, so you need to use only ONE, if you take OBJECT_CAPTURE_TRIGGER for example, that's a function with four arrguments after the function, like this: function(oldowner, newowner, heroname, objectname) you can only use the different argumments if they have different values, if they have the same or haven't got any you may only use them once. It might be a bit difficult, but will be easy when you get better.
____________
Hwr cwom mearg? Hwr cwom mago?
Hwr cwom maumgyfa? - 'The Wanderer'

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 28, 2007 12:25 AM

Ah well, I'm already pleased to have figured out how to add creatures to the hero's army when he enters a certain region without asking for help The tutorial helped decently in it!

Here's a little challenge for you Kronos, perhaps:

Is there a way to trigger an event where you get ambushed by a bunch of creatures (thus, when you enter a region that you go to the battle screen), where the bunch of creatures can be more than 1 type and their upgrades? Like fighting a garrisson without the actual building being there... Is this possible? It was in Heroes 3.

Cheers!

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 28, 2007 10:53 AM

Well then, I've got the Bolean thing down (fortunately I have a lot of experience with Dungeon Keeper scripting so I know what most junk does), however, there's one complication. Although the commands do not trigger anymore like they should, the hero still stops in his tracks (Since the trigger says stop...)... Is there any way to resolve this or is it a little annoyance you just have to deal with?

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Maurice
Maurice

Hero of Order
Part of the furniture
posted September 28, 2007 11:26 AM

I haven't actually created scripts myself yet (just deciphered the game scripts and played around with commands in the console ), but I've read a thing or two about the "sleep" command. It is required to break from certain functions and return control to the rest of the script. Otherwise you get a deadlock in that particular function.

I don't fully understand this, but I recommend that you take a look into that "sleep" function.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kronos1000
Kronos1000


Promising
Supreme Hero
Frysln Boppe
posted September 28, 2007 01:39 PM

A script, for an ambush? Easy!

Won = 0

function Ambush(heroname, objectname)

if GetCurrentPlayer() == PLAYER_1 and Won == 0 then
StartCombat(heroname, nil, x, y, z .....)
Won = 1
end;
end;

Trigger(REGION_ENTER_AND_STOP_TRIGGER, "Region", "Ambush")

In this case,

x = The number of stacks
y = The Creature type
z = Number of that stack

continue y and z untill you reached the number of stacks you gave earlier.

You can also Randomsize it to double the fun.

function Ambush(heroname, objectname)
RandumNumber = random(1)

if GetCurrentPlayer() == PLAYER_1 and RandomNumber == 0 then
StartCombat(heroname, nil, x, y, z .....)
end;
end;

Trigger(REGION_ENTER_AND_STOP_TRIGGER, "Region", "Ambush")

This way it only executes if the RandomNumber == 0 if it's 1 nothing happens.


About the boleon Hero stops thing, you'll have to live with that in HoF if you have an older version you can use:

function Ambush(heroname, objectname)

if GetCurrentPlayer() == PLAYER_1 then
StartCombat(heroname, nil, x, y, z .....)
Trigger(REGION_ENTER_AND_STOP_TRIGGER, "Region", nil)
end;
end;

Trigger(REGION_ENTER_AND_STOP_TRIGGER, "Region", "Ambush")

Trigger(REGION_ENTER_AND_STOP_TRIGGER, "Region", nil) removes the function this does not work in HoF

Take a good look in Nival's HoF Campaigns the Hero also stops
____________
Hwr cwom mearg? Hwr cwom mago?
Hwr cwom maumgyfa? - 'The Wanderer'

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 28, 2007 01:58 PM

Ahhh thanks! Exactly what I needed!

Fortunately I don't have HOF, so that nil command will be of help too. Again thanks!

And we go on with yet another question

How do you set up a script to confine an enemy AI hero to a specific area? So he can't wander where you don't want him to wander?

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kronos1000
Kronos1000


Promising
Supreme Hero
Frysln Boppe
posted September 28, 2007 02:02 PM

To make an AI Hero stand still you can use the EnableHeroAI command wich works like this:

EnableHeroAI(heroname, true/false)

The heroname is obvious and true allows him to walk, false makes him stand still that's probably what you want.
____________
Hwr cwom mearg? Hwr cwom mago?
Hwr cwom maumgyfa? - 'The Wanderer'

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 28, 2007 02:38 PM

Well I can use that, although if there is a script way to allow the AI to run lose but only in a set area, or making an area which he cannot move into, that would be better. Like some sort of invisable wall the AI won't cross (like in the Sylvan campaign with the 5 border buildings, the AI would never cross them into your terrain).



Also I screwed something up with the Boleon thing I think. I used var1, Var2, var3 etc for different boleons, and for some reason it screwed up my entire script (nothing worked). Are there specific rules for the boleon variables? Such as that it cant contain numbers or something? (The capitals wasnt the problem).

It makes me wonder though why something like that would even screw over my entire script, even the simple message box command at the start which has no requirements. Even that wouldn't run. (I fixed it so far by removing the boleons and instead using the trigger nil thing... )

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 28, 2007 10:37 PM

Aaaand here's more trouble

I found I wasn't capable of adding 4 pitlords to an enemy hero (grok). However, when I (in the script) changed it to add the creatures to my own hero (Itil) it DID work.  

So, here's my 2 questions on this:

A) Could the fact Grok is garrissoned within a town have something to do with this? Or is it the fact the script is triggered by Itil and thus can only affect Itil ?

B) How do I fix this? I want to add a bunch of infernal creatures to the demon's town / main hero, whichever, but in both cases I fail.


Oh, and the command to make the enemy hero stand still doesn't work. (I'm using V1.5, not HOF. Could that be the problem?)

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 30, 2007 01:42 PM

*bump* Uhmm, yeah, still stuck with this.

It's not like I can't work around it, I could just plant a border guard to restrict him, and give him the required army from the start, but, that won't help me understanding scripting. And I'd really like to master these basic things before moving on to that advanced tutorial... So if anyone could spare some 10 mins of their time to answer, that would be really appreciated although I know I probably ask too much, but yeah...

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kronos1000
Kronos1000


Promising
Supreme Hero
Frysln Boppe
posted September 30, 2007 03:29 PM

All right I'll answer:

Blocked Area: You need the SetRegionBlocked function wich I have given lots of attention in my guide so if you want to look it up I do not need to write it again. Thanks.

Grok Question: I only have one possible solution you're not using the Script name. Is that it?


____________
Hwr cwom mearg? Hwr cwom mago?
Hwr cwom maumgyfa? - 'The Wanderer'

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 30, 2007 04:01 PM

Nope, the script ID gave his name as "Grok" so I used that. I'll look the restricting up on the modding wiki though, thanks!

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kronos1000
Kronos1000


Promising
Supreme Hero
Frysln Boppe
posted September 30, 2007 04:54 PM

About the Grok thing, can you show me your script?
____________
Hwr cwom mearg? Hwr cwom mago?
Hwr cwom maumgyfa? - 'The Wanderer'

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 30, 2007 06:58 PM

EnableHeroAI(Grok, false)


Like you told me to

And this is odd, for some reason the editor tells me it can no longer open the map because either it's corrupted, its from a different version, or the file is not in the maps folder.... wtf? The game itself doesn't see the map anymore either. Now that's just weird... 3 days of hard work down the drain.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Kronos1000
Kronos1000


Promising
Supreme Hero
Frysln Boppe
posted September 30, 2007 07:54 PM

Sorry for your map but you haven't worked long on this so it shouldn't be hard to restore.

A note I see the mistake you say:
EnableHeroAI(Grok, false)
It should be:
EnableHeroAI("Grok", false)
The "" are very important I said in my guide that names and paths always require ""

Mijn gids is completer dan je denkt
____________
Hwr cwom mearg? Hwr cwom mago?
Hwr cwom maumgyfa? - 'The Wanderer'

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Moonlith
Moonlith


Bad-mannered
Supreme Hero
If all else fails, use Fiyah!
posted September 30, 2007 08:06 PM
Edited by Moonlith at 20:07, 30 Sep 2007.

D'oh!!! Thanks >< I'll try that. But, that's kind of confusing... Since when I set the name to Itil, (without the "and" ), it DID work, but not anymore when I set it to Grok. (the creature adding to the hero that is)... But I'll try it anyway and give an update about wether it worked or not.

Not a lot of work? 3 days, 20+ hours... Spent LOTS of time on detailing the entire environment to give it that perfect atmosphere. Bah x.x All for nothing... And I have no clue why it suddenly claimed it became corrupt. A bug?

Anyways, thanks Ik zal je gids verder doorwerken.

P.S.: Anyone up for a LOTR campaign once the Tribes of the East comes out?


 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Jump To: « Prev Thread . . . Next Thread » This thread is 2 pages long: 1 2 · NEXT»
Post New Poll Post New Topic Post New Reply

Page compiled in 0.0437 seconds