Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
2 years ago
Auto-translated
If you look at the DialogBox code, you can assume that the problem lies in the use of GetCurrentPlayer there. TalkBox expects the first argument to be not the player number, but its filter. For players 1 and 2, the filter is equal to the number, but for 3+, it is not. Therefore, it probably only works for the first two players. If the problem is this, then the solution would be to wrap the first argument of DialogBox - GetPlayerFilter(GetCurrentPlayer()).
User Avatar
2 years ago
Auto-translated

I tried swapping objects 1 and 3, but left the code as is.

It was like this:
first player = object "1"
second player = object "2", and so on.
The 3rd player and the 3rd object, and so on up to the 8th, didn't work.

Now it's like this:
the first player touches object "3" and everything works.
the third player touches object "1" and doesn't work.

This means the code is correct and works for all 8 functions.

It seems the problem is with the player number - it works for 2 players, but not for 6.
I'll have to abandon the great idea of a bonus that the human player can choose.



Added 28 minutes later
Gerter
Well, if you look at the DialogBox code, you can assume that the problem is with the use of GetCurrentPlayer there. TalkBox expects the first argument to be not the player number, but its filter. For the 1st and 2nd player, the filter is equal to the number, but not for 3+. Therefore, it probably only works for the first two players. If the problem is this, then the solution would be to wrap the first argument of DialogBox - GetPlayerFilter(GetCurrentPlayer())
I added the filter retrieval, everything works now, thank you
User Avatar
2 years ago
Auto-translated
I would like to warn you right away that if you plan to use talkboxes in multiplayer over a network, it is best to abandon this idea, as this function corrupts saves in multiplayer.
In reply to green belly
User Avatar
2 years ago
Auto-translated
green belly

I tried swapping object 1 with object 3, but I left the code the same.

It was like this:
first player = object "1"
second player = object "2", and so on.
The 3rd player and the 3rd object, and so on up to 8, didn't work

Now it's like this:
the first player touches object "3" and everything works.
the third player touches object "1" and doesn't work.

This means the code is correct and works for all 8 functions.

It seems the problem is with the player number - it works for 2 players, but not for 6.
I'll have to abandon the cool idea of a bonus that the player can choose (((

 



Added 28 minutes later
I added the filter retrieval, everything works now, thank you.
 
For all functions that are named ...BoxForPlayers, the argument for the player ID works strangely. Player 1 = 1, Player 2 = 2, Player 3 = 4, Player 4 = 8, Player 5 = 16, Player 6 = 32, Player 7 = 64, Player 8 = 128. I'm not sure about the last 2, I only checked for 6 players.
In reply to Долгий
User Avatar
2 years ago
Auto-translated
Long

For all functions that are named ...BoxForPlayers, the argument for the player ID works strangely. Player 1 = 1, Player 2 = 2, Player 3 = 4, Player 4 = 8, Player 5 = 16, Player 6 = 32, Player 7 = 64, Player 8 = 128. I'm not sure about the last two; I only checked for 6 players.

This is a bitmask, so that the same message can be displayed for multiple players at once. For example, if you need it for players 1, 3, and 5, you can pass PLAYERFLT_1 + PLAYERFLT_3 + PLAYERFLT_5.
1 year ago
Auto-translated

Good evening, I wanted to use a script to give a hero mana, similar to the "Secret Advantage" skill, so that it would ignore the hero's maximum mana. I tried using ChangeHeroStat(), but it didn't work. The funny thing is, when I first started working on the map, I actually managed to implement ignoring the maximum mana, but I needed it to go up to the maximum, and now it's the other way around, and I can't remember how I did it. I found a solution on the forum on how to give a hero up to 300 mana using ChangeHeroStat(), but as I mentioned above, it didn't work.

In reply to Shiroyasha2910
User Avatar
1 year ago
Auto-translated
Shiroyasha2910

Good evening, I wanted to give a hero mana through a script, like with the "Secret Advantage" skill, so that it ignores the hero's maximum mana. I tried using ChangeHeroStat(), but it didn't work. The funny thing is that when I just started working on the map, I actually managed to ignore the maximum mana, but I needed it to go up to the maximum, and now it's the other way around, and I can't remember how I did it. I found an answer on the forum on how to give a hero mana up to 300 using ChangeHeroStat(), but as I wrote above, it didn't work.


Possible solution: temporarily add Knowledge to the hero, and after increasing the amount of mana, return the Knowledge to its previous value. Example:

ChangeHeroStat("Deleb", STAT_KNOWLEDGE, 10)
ChangeHeroStat("Deleb", STAT_MANA_POINTS, 100)
ChangeHeroStat("Deleb", STAT_KNOWLEDGE, -10)

I quickly checked it through the console. Yes, it works, the mana remains above the maximum value. For now, I'll do it this way; maybe someone knows how to do it with a single command.
In reply to Magnificent
1 year ago
Auto-translated
Magnificent
Possible solution: temporarily add Knowledge to the hero, and after increasing the amount of mana, return the Knowledge to its previous value. Example:

ChangeHeroStat("Deleb", STAT_KNOWLEDGE, 10)
ChangeHeroStat("Deleb", STAT_MANA_POINTS, 100)
ChangeHeroStat("Deleb", STAT_KNOWLEDGE, -10)

I quickly checked it through the console. Yes, it works, the mana remains above the maximum value. For now, this is how it's done; perhaps someone knows how to do it with a single command.
I was thinking about this, but I hoped that I was just being stupid and didn't know a better way. But still, thank you. Damn, how did I do it with a single command that time?
User Avatar
1 year ago
Auto-translated
Perhaps you remember increasing mana in battle using the SetUnitManaPoints function; there are no restrictions on the maximum mana.

In my mod, health points are technically implemented as a hero's mana, and there is no such problem. ChangeHeroStat increases the mana pool beyond what the hero's knowledge allows.
1 year ago
Auto-translated

Hello, I have a simple task: create a script in the map editor that, for example, grants X experience to any hero who kills a neutral creature.

However, I can't seem to implement it. What's the error here?

GetPlayerHeroes(0);
SetGameVar(whotoup, 0);
whotoup = GetPlayerHeroes(0);
ChangeHeroStat(whotoup[0], 0, 999999999)

In reply to CetusSantis
User Avatar
1 year ago
Auto-translated
CetusSantis

Good afternoon, I have a simple task: to create a script in the map editor that, for example, when a neutral creature is killed, any hero who does it receives X experience.

But I can't seem to implement it. What's the error here?

GetPlayerHeroes(0);
SetGameVar(whotoup, 0);
whotoup = GetPlayerHeroes(0);
ChangeHeroStat(whotoup[0], 0, 999999999)



You can achieve a simpler result with workarounds, but if you need precise logic, so that ANY hero receives experience for defeating a SPECIFIC stack, and not a total number of creatures, here's my idea:

Give a name to the unit on the map. For example, UnitExp

function FightUnitExp(hero, unit)
 while isObjectExists(hero) == not nil and isObjectExists(unit) == not nil do
  sleep(5)
 end 
 if isObjectExists(unit) == nil then
  ChangeHeroStat(hero, 0, 999999999)
 end
end
Trigger(OBJECT_TOUCH_TRIGGER, "UnitExp", "FightUnitExp")
In reply to Долгий
1 year ago
Auto-translated

Right away, two silly questions:

How do I assign this name to a unit?

Where should I add this script? To the unit itself? If so, should it be a script or a combat script?

In reply to CetusSantis
User Avatar
1 year ago
Auto-translated
CetusSantis

Two silly questions right away)

How do I give a unit this name?

Where should I add this script? To this unit? If so, is it a script or a combat script?


The name is added to the Name parameter of the unit in the map editor. I've attached a screenshot; the area is highlighted in green.

The script goes into the general script for the map.
Attachments 1
1 file attached • Total size: 368.4 KB
In reply to Долгий
1 year ago
Auto-translated
Understood. Is this trick compatible with the Heroes 5.5 mod? Because it also has its own scripts.
In reply to Долгий
User Avatar
1 year ago
Auto-translated
I checked the script. There is 1 error: the function isObjectExists should be capitalized: IsObjectExists

Added after 1 minute
CetusSantis
I see, and is this trick compatible with the heroes5.5 mod? Because it has its own scripts too.
I don't know, I haven't checked. It might work, or it might not. I checked on vanilla, and it works

Statistics

Welcome our newest member: recijeb