[h4 editor] scripting a house, where I can buy levels

Maps and the art of mapmaking.

Moderator: Moderators

nikon
Leprechaun
Leprechaun
Posts: 4
Joined: 22 Sep 2006

[h4 editor] scripting a house, where I can buy levels

Postby nikon » Sep 22 2006, 17:21

hi there

I'd like to have a house (for example a quest hut) where I can buy level-ups. First, there should be the chance to choose the hero, who should get the level up, second the price should be told (current level multiplied with 500 gold...or something else), and at last, the question if the player would like to spend his money.

Further this must be available infinite times.


Is this possible?

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Re: [h4 editor] scripting a house, where I can buy levels

Postby alavris » Sep 22 2006, 18:34

Hi! It's possible. Here's the script I've just written:

Code: Select all

function fun1(oldowner, newowner, heroname, townname)
   if GetPlayerResource(newowner, GOLD) >= GetHeroLevel(heroname)*500 then
      MessageBox("Maps/Multiplayer/Alavris 1/wiad1.txt");
      LevelUpHero(heroname);
      SetPlayerResource(newowner, GOLD, GetPlayerResource(newowner, GOLD)-GetHeroLevel(heroname)*500);
      SetObjectOwner("peasant_boss", PLAYER_NONE);
   else
      MessageBox("Maps/Multiplayer/Alavris 1/wiad2.txt");
   end;
end;

Trigger(OBJECT_CAPTURE_TRIGGER, "peasant_boss", "fun1");


In the eiditor, name any peasant hut as "peasant_boss". When you enter this hut, the script starts working.

In this script I think it's not possible to ask heroe if he want to level up... he just must (beacuse of angry peasant ;)). The hero that will be leveled up is the hero that enters this hut. Everything else is as you wished.

If something isn't clear enough or you have same questions, just ask. I'll try to help. :)
.

nikon
Leprechaun
Leprechaun
Posts: 4
Joined: 22 Sep 2006

Postby nikon » Sep 22 2006, 19:00

hm thanks, but I don't understand 8|

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Postby alavris » Sep 22 2006, 19:38

nikon wrote:hm thanks, but I don't understand 8|


Ok, so let's start from the beginning :).

1. Making the hut.

Place peasant hut which you want to be your leveling-heroe-up building.
Then mark it by cursor, so it's whole in red colour. Now press CTRL+SPACE... object propersties tree opens. In this tree change "Name" cell vaule to "peasant_boss".


2. Making message.

We have to make two diffirent messages that will appear in box when entering the hut. First (named "wiad1.txt") tells that you lose some money but your hero levels up. Second (named "wiad2.txt") tells that you have not enough money to level up your hero. So, in the editor, select View-->Map properties tree. Choose "Add" as shown:

Image

Now click on "New" buttow as shown:

Image

Write a name for your text file (first message must be named "wiad1.txt"), then click "Ok". New window appears. Here you can write text of your message. When finished, click "Ok".

Now repeat this process to create second message named "wiad2.txt".


3. Writing the script

In the editor, select View-->Map properties. New window appears. Now, select "Script" bookmark. Click "Edit Script" button. Now, paste here whole code I wrote in my previous post. But there are two places in this code which must be changed:

Code: Select all

MessageBox("Maps/Multiplayer/Alavris 1/wiad1.txt");

and

Code: Select all

MessageBox("Maps/Multiplayer/Alavris 1/wiad2.txt");

Instead of writing "Maps/Multiplayer/Alavris 1/wiad1.txt", paste here copied value of SaveFilenameFileRef cell, which just has been edited by you (see second picture). Do similar with "wiad2.txt". When it's done, click "Ok". Now, again click "Ok".



Hmm, I think it is all you should know... but ask if something goes wrong.
.

User avatar
alavris
Scout
Scout
Posts: 164
Joined: 06 Jan 2006
Location: Poland
Contact:

Postby alavris » Sep 22 2006, 19:55

Ha ha! :) :) :) :-D Sorry man, I've just realized that in topic name was "h4", not "h5". So my replys are not useful for you (maybe for someone else).

nikon
Leprechaun
Leprechaun
Posts: 4
Joined: 22 Sep 2006

Postby nikon » Sep 22 2006, 21:25

ah ok

tried a few things, and the big problem is, that I can't say "take 'variable' gold from player", there has to be a number

dumb editor :D

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

Postby wimfrits » Sep 23 2006, 8:43

nikon wrote:tried a few things, and the big problem is, that I can't say "take 'variable' gold from player", there has to be a number


Indeed. So you can either script an amount for each hero level or you can measure amount of gold the player owns versus hero level to check whether the hero is 'eligible'. The latter has the downside that you cannot show the amounts the player needs to pay.

Also, you cannot allow the player to choose a specific hero; unless all heroes have fixed names. Easiest way around that is probably to have the quest hut grant a level to the most powerful hero in the visiting army.

Allowing the script to run infinite times requires you to use the TRIGGERED tab.

There are multiple ways to handle this. One of them is to:

1. Leave the proposal message, progress message and completion script empty and insert an impossible quest requirement.

2. Under the triggered tab, put:

Code: Select all

SEQUENCE:

IF [introduction shown]
  IF number of heroes in army = 0
    DISPLAY: "Sorry, but only heroes can use this quest hut"
  END-IF
ELSE
  SEQUENCE:
  SET [introduction shown] to TRUE
  DISPLAY MESSAGE: "Blahblah quest hut, level up, costs money blahblah"
END-IF

IF number of heroes in army > 0
  IF experience level of most powerful hero in army = 1
    IF amount of gold player owns is >= 500
      ASK "Do you want to pay 500 gold for an increase in level?"
      IF YES:
        DISPLAY MESSAGE "ALright. There you go"
        SUBACTION1: take 500 gold from player
        SUBACTION2: increase experience level of most powerful hero in army by +1
      IF NO:
        DISPLAY MESSAGE: "Suit yourself"
    ELSE
      DISPLAY MESSAGE: "You do not have enough gold"
    END-IF
  END-IF
END-IF

IF number of heroes in army > 0
  IF experience level of most powerful hero in army = 2
    IF amount of gold player owns is >= 1000
...etc....


Note that if you script this in sequence 1-2-3-4-5-6-7 etc, the hero will be able to level up multiple times in 1 visit if player owns enough gold.
If you only want to allow 1 level up per visit, you need to script this in 7-6-5-4-3-2-1 sequence.
Are you suggesting coconuts migrate?

nikon
Leprechaun
Leprechaun
Posts: 4
Joined: 22 Sep 2006

Postby nikon » Sep 23 2006, 9:47

ouch! 70 times
needs too much time

anyway, thanks

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

Postby wimfrits » Sep 23 2006, 10:48

You could allow less than 69 level ups ;)

Or you could try the alternative scripting path; which is to:

1. Measure current amount of gold through a re-iterating take gold script (and give gold back afterwards) to determine maximum level up that is allowed. E.g. if cost is [500 gold * level], determine how many chunks of 500 fit in the player's total amount of gold.

2. Measure current hero level and check if it is lower or equal than the maximum allowed level according to 1.

3. If level up is allowed, ask if the player wants to level up. If so, take [current level * 500 gold] through a reiterating script and give a level.

Although this is a lot less scripting, it has the downside that it does not show the exact amount of gold to the player.
Are you suggesting coconuts migrate?


Return to “Mapmaking Guild”

Who is online

Users browsing this forum: No registered users and 2 guests