Scripting help please

The old Heroes games developed by New World Computing. Please specify which game you are referring to in your post.
User avatar
RobB
Scout
Scout
Posts: 160
Joined: 16 Nov 2006
Location: Perth W Australia

Scripting help please

Unread postby RobB » 11 May 2007, 22:47

Scripting help

I've run into a scripting problem that I just can't figure out. In this scenario, you have to own 5 named towns and kill/capture the enemy baddy (I'll call him "Badd" for now and give the towns simple labels). I have to allow for the fact the towns can be recaptured and that Badd can get killed by other colours or even by guarding stacks.

After trying out various scripts based on the towns and on Badd himself, I finally started using a series of map continuous script roughly as follows:

Continuous script: counttowns

sequence
conditional action
if TownOne is owned by red player
then variable town1= 1
else town1 = 0

and so on for the other towns.

Continuous script: checktowns

conditional action
if
and (several times over)
town1 = 1 and town2 = 1 and town3 = 1 etc.
then variable towns = 1
else towns = 0

Continuous script: checkbad
conditional action
if hero Badd is dead
then variable evil = 1
else evil = 0

Then there are two more conditonal actions considering (towns=1; evil=0) and (towns=0; evil=1) which just display messages telling you what you need to do to win. And then finally:

Continuous script: havewewon
conditional action
if
and
(equals) towns-1 and evil=1
then sequence
display [complicated message]
red player has won
else do nothing.

Now, the last time I played this, I had killed the villain and taken all the towns and nothing happened. I was going to change the script so it read "is dead or captured", but first I checked the prisons in all the towns: Badd is not there. I can't remember whether I got the message that [colour] player is eliminated, but that is exactly what I was trying to avoid by disabling standard victory and going this complicated way. I don't want to have to chase one lonely pikeman hiding behind a tree.

Any ideas why my scripts don't work and any suggestions? Please!
RobB

User avatar
eekstah
Scout
Scout
Posts: 187
Joined: 12 Apr 2006

Unread postby eekstah » 12 May 2007, 00:21

Uhm ... Isn't the standard winning condition "be the only player to own towns"?

If those five town that you have to capture are the only towns besides your own, then you may safely enable standard winning condition after you have killed/captured that Baddy guy.

If not, this ...
conditional action
if
and (several times over)
town1 = 1 and town2 = 1 and town3 = 1 etc.
then variable towns = 1
else towns = 0
... is not the most efficient way to count whether or not you have captured all the needed towns.

You could just set a variable 'towns' to 0.

Then make a triggarable script in each town: Call it for instance "count towns" (the name must be same in all the towns). The only required command line is "set Towns to 'Towns + 1'. Then make sure you uncheck all other colors than yourself in the "only run if player is".

If all the towns were the same (i.e. were of same alignment, set to start with the same garrison, buildings etc, AND facing the same way), you could even copy-paste the first town four times and so only have to make the script once.

When this is done you only need to check if "Towns = 5".

And you don't need to make that "if baddy is killed or captured" an continiuos script, you can put it in the standard "defeated" event. I imagine that all this will save the cpu some stress, as H4 is slow enough as it is.

User avatar
RobB
Scout
Scout
Posts: 160
Joined: 16 Nov 2006
Location: Perth W Australia

Unread postby RobB » 12 May 2007, 00:58

Thank you for you detailed reply. I wish I could remember exactly why I wanted to do it this way and not just go for Standard Victory. I think it was to do with the fact that I want the player to see the baddy's dying words, and with Standard Victory, you only have to capture and hold all the towns for 3 days. Something like that anyway.

I totally agree about my way being long-winded, although I was surprised that it did not slow the game down at all on my Mac. (H4 was extremely slow on my last Mac, but now the game goes like a breeze).

You can imagine how long it took me to type/select all those continuous conditions. The only problem I see with your suggested method is what to do if one of the towns is recaptured - put it in the "captured" event? It was trying to do something like that that went wrong with my original version.

It may not be elegant, but I still can't see what is going wrong with the script as I have it. Even more puzzling is what happened to the baddy. I know I killed him and got the message about being held in X prison, but I didn't read which one, and, as I said, when I checked all the prisons, he wasn't there even though I owned every town. Very weird. Maybe he truly died.

What I want is:
capture all the towns, get a message the baddy must still be found, get him and win

OR
get the baddy and his dying message, get a message to capture all towns, do that and win.

What I don't want, as sometimes happens, is to capture all towns and baddy, and then have to go looking for a single enemy archer who has hidden himself behind a rock.

Once again, thanks for looking.
RobB

User avatar
wimfrits
Round Table Knight
Round Table Knight
Posts: 2050
Joined: 06 Jan 2006
Location: Utrecht, the Netherlands

Re: Scripting help please

Unread postby wimfrits » 12 May 2007, 06:21

Don't know why your script fails, but think it is in the 'hero is dead' check.

Aside from that, I don't know if so many interlocking continuous events still work and would urge you to use as little continuous events as possible as they can degrade game performance.

An alternative would be the following, with the use of 3 variables:
towns_captured
Badd_defeated
progress_message_shown

1. on all of the towns a triggered script named checktown1 to 5:

Code: Select all

IF owner = red 
   SET towns_captured TO towns_captured + 1 
END-IF 
2. On hero Badd defeated tab :

Code: Select all

SEQUENCE:
SET Badd_defeated to TRUE 
IF CURRENT PLAYER = red
   TRIGGER CUSTOM EVENT objective_check 
END-IF
3. On each of the towns captured tabs:

Code: Select all

IF CURRENT PLAYER = red 
   TRIGGER CUSTOM EVENT objective_check
END-IF
4. the objective_check script in scenario properties:

Code: Select all

SEQUENCE:

SET towns_captured TO 0

TRIGGER CUSTOM EVENT checktown1
TRIGGER CUSTOM EVENT checktown2
TRIGGER CUSTOM EVENT checktown3
TRIGGER CUSTOM EVENT checktown4
TRIGGER CUSTOM EVENT checktown5

IF towns_captured = 5 AND Badd_defeated, SEQUENCE
   DISPLAY MESSAGE "Blablayouwin"
   red player WINS
END-IF

IF NOT progress_message_shown, SEQUENCE
   IF towns_captured = 5 AND NOT Badd_defeated, SEQUENCE
      DISPLAY MESSAGE "You still need to get Badd!"
      SET progress_message_shown to TRUE
   END-IF
   IF towns_captured < 5 AND Badd_defeated, SEQUENCE
      DISPLAY MESSAGE "You forgot to take the towns!"
      SET progress_message_shown to TRUE
   END-IF
END-IF
5. And finally, because Badd may be defeated during another players turn, a backup timed event repeating every day during red's turn:

Code: Select all

TRIGGER CUSTOM EVENT objective_check
Last edited by wimfrits on 12 May 2007, 17:42, edited 1 time in total.
Are you suggesting coconuts migrate?

User avatar
eekstah
Scout
Scout
Posts: 187
Joined: 12 Apr 2006

Re: Scripting help please

Unread postby eekstah » 12 May 2007, 15:37

wimfrits wrote:1. on all of the towns a triggered script named checktown1 to 5:

Code: Select all

IF current player = red 
   SET towns_captured TO towns_captured + 1 
END-IF 
This is pretty much what I suggested, except that the triggered events doesn't have to have different names. They can all be called the same, so you don't need to trigger five different scripts.

Second, "IF current player = red" is obviously a wrong condition, unless this is only triggered on the CAPTURED event, but now it's triggered continously. Triggering it only on Captured is pretty clever though.

And the "hero Badd defeated" event has to concider if Badd actually has been killed or captured (he may also have surrendered or fled from the battle, and with that still be at large).

User avatar
wimfrits
Round Table Knight
Round Table Knight
Posts: 2050
Joined: 06 Jan 2006
Location: Utrecht, the Netherlands

Re: Scripting help please

Unread postby wimfrits » 12 May 2007, 17:40

eekstah wrote:This is pretty much what I suggested, except that the triggered events doesn't have to have different names. They can all be called the same, so you don't need to trigger five different scripts.
I like to keep things as straightforward as possible. Multiple scripts with the same name blurs things and may cause unwanted effects later when designing a complicated map.
Each to his own though.
Second, "IF current player = red" is obviously a wrong condition,
Oops. Should have been owner. I'll fix that. Thanks for noticing!
And the "hero Badd defeated" event has to concider if Badd actually has been killed or captured (he may also have surrendered or fled from the battle, and with that still be at large).
AFAIK, fleeing does not count as defeated.
Are you suggesting coconuts migrate?

User avatar
RobB
Scout
Scout
Posts: 160
Joined: 16 Nov 2006
Location: Perth W Australia

Unread postby RobB » 12 May 2007, 23:38

I thought with wimfits that it might have been the check for dead baddie at the root of the problem. I"ve saved everybody's comments so far to disk, and I think I'll have to print them out to study them properly.

Wimfrits mentioned an "objective_check" script in scenario properties. I can't remember seeing any option like this, although I must admit, I only recently noticed that "scenario" and "map" properties were different.
RobB

User avatar
Robenhagen
Admin
Admin
Posts: 1247
Joined: 21 Nov 2005
Location: Aarhus, Denmark
Contact:

Unread postby Robenhagen » 13 May 2007, 07:49

There is no pre-defined 'objective_check', but you can script it yourself, I believe that is what he meant.
I was lookin’ back to see if you were lookin’ back at me to see me lookin’ back at you.

User avatar
wimfrits
Round Table Knight
Round Table Knight
Posts: 2050
Joined: 06 Jan 2006
Location: Utrecht, the Netherlands

Unread postby wimfrits » 13 May 2007, 08:55

Yes, it's just the name of a script like Robenhagen said. Just like putting them on adventure objects, you can also script custom events in the main scenario properties menu.

This can be useful since it allows you to 'store' scripts in one central place and keep an overview of things. But, scripts here can not influence a specific object directly, so the use is limited.
I use it mostly for either complex part of scripts or scripts that can be triggered in multiple ways.
Are you suggesting coconuts migrate?

User avatar
Humakt
Swordsman
Swordsman
Posts: 582
Joined: 06 Jan 2006

Re: Scripting help please

Unread postby Humakt » 13 May 2007, 10:19

RobB wrote:Scripting help
I've run into a scripting problem that I just can't figure out. In this scenario, you have to own 5 named towns and kill/capture the enemy baddy (I'll call him "Badd" for now and give the towns simple labels). I have to allow for the fact the towns can be recaptured and that Badd can get killed by other colours or even by guarding stacks.
!
So you need to take into account also whether Badd is liberated or resurrected? In that case, I feel the continous event is the simplest to do and should be better than timed event definitely here. If you own at the start of scenario towns, just put the numeric variable at the town amount at the start of scenario by timed event.

On every town (On Capture tab):
If owner is human
then set Towns_Owned to Towns_Owned + 1
else
If current player is Human or opposing player is Human
then set Towns_Owned to Towns_Owned - 1

I'm not sure which one is valid statement in latter condition above, but thanks to "or" it doesn't matter.

Continous event.
If hero named Badd is dead or hero named Badd is in prison
then
If Towns_Owned greater than or equals to 5
then Red Player Wins.

Assuming Red Player is human player here.

That's all you should need.
Thundermaps
"Death must be impartial. I must sever my ties, lest I shield my kin."

User avatar
Siegfried
Pixie
Pixie
Posts: 124
Joined: 13 Jan 2006
Contact:

Unread postby Siegfried » 14 May 2007, 09:13

RobB wrote:Thank you for you detailed reply. I wish I could remember exactly why I wanted to do it this way and not just go for Standard Victory. I think it was to do with the fact that I want the player to see the baddy's dying words, and with Standard Victory, you only have to capture and hold all the towns for 3 days. Something like that anyway.
I think here is the main misunderstanding. What eekstah meant was:

First, on map creation, disable standard victory condition, Then, after beating the hero, reenable standard victory condition by script.

User avatar
Humakt
Swordsman
Swordsman
Posts: 582
Joined: 06 Jan 2006

Unread postby Humakt » 14 May 2007, 21:46

Siegfried wrote: I think here is the main misunderstanding. What eekstah meant was:

First, on map creation, disable standard victory condition, Then, after beating the hero, reenable standard victory condition by script.
If so, then it's even simpler. However continuous event would still be required (doing it without wouldn't be nearly as simple or practical).

Continuous event.
If hero named Badd is dead or hero named Badd is in prison
then enable standard victory condition
else disable standard victory condition.


That should be suitable..
Thundermaps
"Death must be impartial. I must sever my ties, lest I shield my kin."

User avatar
RobB
Scout
Scout
Posts: 160
Joined: 16 Nov 2006
Location: Perth W Australia

Unread postby RobB » 15 May 2007, 01:29

Humakt's suggestion looks very much like the original scripts I had which didn't work - but nearly did - but there is a difference with the continuous script to check Badd, whereas I had only defeated and victorious scripts on the character himself.

I'm going to have to make a test copy of the scenario so I can get around it a bit faster.
RobB

User avatar
Siegfried
Pixie
Pixie
Posts: 124
Joined: 13 Jan 2006
Contact:

Unread postby Siegfried » 15 May 2007, 10:09

Humakt wrote:
If so, then it's even simpler. However continuous event would still be required (doing it without wouldn't be nearly as simple or practical).

Continuous event.
If hero named Badd is dead or hero named Badd is in prison
then enable standard victory condition
else disable standard victory condition.


That should be suitable..
I think that could be even simpler. On the map, simply deactivate the standard victory condition. That means that you have to script a game win yourself. Then, in the "Hero defeated" script slot, simply reactivate the standard voctory condition.

Normally, such a "hero defeated" script would show a message, then sets win for whoever. Simply omit thes win script part and reenable standard victory condition.

User avatar
Humakt
Swordsman
Swordsman
Posts: 582
Joined: 06 Jan 2006

Unread postby Humakt » 15 May 2007, 15:39

Siegfried wrote: I think that could be even simpler. On the map, simply deactivate the standard victory condition. That means that you have to script a game win yourself. Then, in the "Hero defeated" script slot, simply reactivate the standard voctory condition.

Normally, such a "hero defeated" script would show a message, then sets win for whoever. Simply omit thes win script part and reenable standard victory condition.
I know. But the continuous event ensures that the hero must be either dead or in prison for player to win. Doing it with just defeated branch would allow standard victory condition be enabled once Badd is defeated, and that would remain so no matter the state of Badd. The continuous event does take into the possibility that Badd is later liberated or raised from dead.

Besides, Badd may die to neutral troops early and then get resurrected bit later, that would mean that player could again win without never having to defeat Badd in case of doing it with defeated branch. Continuous event ensures that scenario won't happen.
Thundermaps
"Death must be impartial. I must sever my ties, lest I shield my kin."

User avatar
RobB
Scout
Scout
Posts: 160
Joined: 16 Nov 2006
Location: Perth W Australia

Unread postby RobB » 15 May 2007, 23:52

That last bit was my main worry. Badd is sort of confined to an island; ie he has no ships, but his colour has two castles where ships are available and, although the passage is a bit tricky, there is nothing to stop a same-coloured ally coming over. I never actually spotted that happening, but I did find Badd in an area that could only have been reached by ship on one occasion, so he can easily be rescued if the AI accidentally does something smart.
RobB

User avatar
Siegfried
Pixie
Pixie
Posts: 124
Joined: 13 Jan 2006
Contact:

Unread postby Siegfried » 16 May 2007, 13:51

In that case indeed you need a small continuous script. Just check if the hero is on the map, and if he is, then disable standard victory condition again.

I think the most significant problem arises if he is killed by a neutral stack. This may activate standard victory condition, but you would never see the special victory message.

User avatar
Robenhagen
Admin
Admin
Posts: 1247
Joined: 21 Nov 2005
Location: Aarhus, Denmark
Contact:

Unread postby Robenhagen » 16 May 2007, 15:57

RobB wrote:... although the passage is a bit tricky...
Keep in mind that even if you think the passage is tricky, the computer 'sees' things in another way; if there's a free passage the AI can see it clearly, even if a player can't see it because of map objects blocking the view.
I was lookin’ back to see if you were lookin’ back at me to see me lookin’ back at you.

User avatar
RobB
Scout
Scout
Posts: 160
Joined: 16 Nov 2006
Location: Perth W Australia

Unread postby RobB » 17 May 2007, 00:25

Siegfried wrote:In that case indeed you need a small continuous script. Just check if the hero is on the map, and if he is, then disable standard victory condition again.

I think the most significant problem arises if he is killed by a neutral stack. This may activate standard victory condition, but you would never see the special victory message.
That is my main worry. I was a bit liberal with sea monsters around his island, and it being able to see the special message (that makes sense of subsequent scenarios) that got me into this mess in the first place.
RobB

User avatar
RobB
Scout
Scout
Posts: 160
Joined: 16 Nov 2006
Location: Perth W Australia

Three pigs bugs?

Unread postby RobB » 20 May 2007, 22:44

While still trying to get my thoughts together before chaning the scripts in my scenario and replaying it several times, I had a replay of Beebee and the Three Pigs. I played in my usual casual, explore-every-corner manner, so I had some interesting battles - for the 29 hydras and 13 b. dragons, Beebee actually required some outside help - but anyway, all towns and enemies killed or captured, but the game will not end.

I enjoyed myself for a while knocking off some of the enormous stacks that had built up, like my hero wasn't going to tackle 186 thunderbirds, and took 100 hydras plus large numbers of efreeti for a walk, stomping on nasties, but after a while this got boring. I haven't looked at the scripts, but I am guessing this is another case where "certain hero is dead" is not working properly.
RobB


Return to “Heroes I-IV”

Who is online

Users browsing this forum: No registered users and 2 guests