Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
2 years ago
Auto-translated
Hello everyone. After a long break, I've finally returned to working on maps. I've forgotten a few things, but that's not the main issue. I've been trying for a long time to create a function that would check what "level" a hero is on – on the surface or in a dungeon. It's this parameter, and not the overall location, that I need, because I'll then need to pass this "level" value to another function. Can anyone suggest how to implement this check efficiently?
User Avatar
2 years ago
Auto-translated
BlueHeavenHero, if you write
local x, y, f = GetObjectPosition(hero_name);
then f will be the floor number.
In reply to Jack_of_shadows
User Avatar
2 years ago
Auto-translated
Jack_of_shadows
BlueHeavenHero, if you write
local x, y, f = GetObjectPosition(hero_name);
then f will be the floor number.
I didn't think it could be that simple. Thanks, I'll try to do it again now.
User Avatar
2 years ago
Auto-translated
Hello! I have a question: if I split my script into several files (move some parts of the code to files that should only be executed at certain times), and then run them at the right time using doFile, will that stop the code from being read from those files? In other words, will this reduce the load on the map, or does it make no difference whether or not to split the code, and will there still be lag?
User Avatar
2 years ago
Auto-translated
I don't think it will make any difference, as loading code via an interpreter is a very fast operation. If we're talking about its execution (e.g., setting up a location at the start of the map or when entering that location), then of course, you can save resources, but for that, it's not necessary to split it into files; just put the code in a function that is called at a specific time.
User Avatar
2 years ago
Auto-translated
I have a question: how do I change the cost of forgetting a skill in the mentor building?
In reply to BlueHeavenHero
User Avatar
2 years ago
Auto-translated
BlueHeavenHero
I didn't think it could be this easy. Thanks, I'll try to do it again now.
Something isn't working for me... I still don't understand how to pass the result of the floor obtained from GetObjectPosition to a global variable.
User Avatar
2 years ago
Auto-translated

BlueHeavenHero, I wrote such a function for my map:

function WhereAmI(obj)
local x, y, z = GetObjectPosition(obj);
if z == 0 then
return 0
elseif z == 1 then
return 1
end
end

Usage:

    if heroName == "Duncan" then
if WhereAmI( heroName ) == 0 then
DuncanInGround = 1
elseif WhereAmI( heroName ) == 1 then
DuncanInGround = 0
end
end
User Avatar
2 years ago
Auto-translated
Any variable that isn't declared as local is a global variable. Let's remove one word from the example:
x, y, f = GetObjectPosition(hero_name);
It's recommended to give these variables longer names since they are visible throughout the entire script.
User Avatar
2 years ago
Auto-translated

Hello everyone, I've been reading information about the talkboxforplayer function on the forum and elsewhere. Everything seems to be working except for one thing: the function doesn't recognize the hero that triggers it. The dialog box with options appears, the response texts are there, and the buttons are there, but the hero isn't recognized, and the army isn't granted.
The idea is this: a random hero touches a building, chooses a response, and receives an army.

The code itself was taken from Jack_of_shadows' Manuals:
The green color highlights the correct code that I copied, and the red color highlights the code that I wrote myself, which, of course, contains an error somewhere.

function DialogBox(icon, title, text, mode, callback, ...)
hero = human
if arg.n==1 then
TalkBoxForPlayers(GetCurrentPlayer(), icon, nil, text, nil, callback, mode, title, nil, 0, arg[1])
elseif arg.n==2 then
TalkBoxForPlayers(GetCurrentPlayer(), icon, nil, text, nil, callback, mode, title, nil, 0, arg[1], arg[2])
elseif arg.n==3 then
TalkBoxForPlayers(GetCurrentPlayer(), icon, nil, text, nil, callback, mode, title, nil, 0, arg[1], arg[2], arg[3])
elseif arg.n==4 then
TalkBoxForPlayers(GetCurrentPlayer(), icon, nil, text, nil, callback, mode, title, nil, 0, arg[1], arg[2], arg[3], arg[4])
elseif arg.n==5 then
TalkBoxForPlayers(GetCurrentPlayer(), icon, nil, text, nil, callback, mode, title, nil, 0, arg[1], arg[2], arg[3], arg[4], arg[5])
end;
end

Trigger (OBJECT_TOUCH_TRIGGER, "pokrov1", "Talk1");

function Talk1()
DialogBox("/UI/MessageBox/Message.xdb#xpointer(/Texture)","/UI/MessageBox/TalkBox/text.txt", "/Maps/Multiplayer/arena/voenachalnik1.txt", 1, "Talk1Callback", "/Maps/Multiplayer/arena/voenachalnik2.txt", "/Maps/Multiplayer/arena/voenachalnik3.txt", "/Maps/Multiplayer/arena/voenachalnik4.txt")
end

function Talk1Callback(pl, ans)
if (ans==1) and HasHeroSkill (human, 57)
then
AddHeroCreatures (human, 106, 50);
elseif (ans==2) and HasHeroSkill (human, 57)
then
AddHeroCreatures (human, 107, 50);
elseif (ans==3) and HasHeroSkill (human, 57)
then
AddHeroCreatures (human, 108, 50);
end;
end;

Thank you for your help.

User Avatar
2 years ago
Auto-translated
green belly, I immediately see that your trigger doesn't pass any arguments to the function with the DialogBox, i.e., to Talk1. Also, you seem to have incorrectly defined the assignment of the hero variable, with whom you need to do something. First, remove the line hero = human from DialogBox (it's simply not needed there), replace the line function Talk1() with function Talk1(hero), and add the line human = hero to the function itself. Now, the script will know who human is so that it can give him creatures.
In reply to Азгалор
User Avatar
2 years ago
Auto-translated
Azgalor
green belly, I immediately see that your trigger isn't passing any arguments to the function with the DialogBox, i.e., to Talk1. Also, you seem to have incorrectly assigned the hero variable, with which you need to do something. First, you should remove the line hero = human from DialogBox (it's simply not needed there), replace the line function Talk1() with function Talk1(hero), and add the line human = hero to the function itself. Now, the script will know who human is so that it can give him creatures.


Thank you, I did it, and it worked.
Previously, I didn't specify or pass any variables or arguments.
User Avatar
2 years ago
Auto-translated

Here I am again with TalkBoxForPlayers.

The problem is this: there's a working code snippet, and it's written 8 times for 8 players, triggered by touching 8 different objects. And that's where the biggest issue starts.

For the first 2 functions, everything works perfectly.

For functions 3-8, the dialog box isn't called.

For these same functions 3-8, the else messagebox line is called....

Here's the code:

function pokrov1F(hero)
human = hero
if HasHeroSkill(human, 80)
then
DialogBox("/UI/MessageBox/Message.xdb#xpointer(/Texture)","/UI/MessageBox/TalkBox/text.txt", "/Maps/Multiplayer/arena/pokrov1.txt", 1, "pokrov1otvetF", "/Maps/Multiplayer/arena/pokrov2.txt", "/Maps/Multiplayer/arena/pokrov3.txt", "/Maps/Multiplayer/arena/pokrov4.txt", "/Maps/Multiplayer/arena/pokrov5.txt")
Trigger (OBJECT_TOUCH_TRIGGER, "pokrov1", nil);
else MessageBox("/Maps/Multiplayer/arena/netpokrov.txt");
end;
end;
Trigger (OBJECT_TOUCH_TRIGGER, "pokrov1", "pokrov1F");

function pokrov1otvetF(pl, ans)
if (ans==1)
then
ChangeHeroStat(human, STAT_ATTACK, 3);
elseif (ans==2)
then
ChangeHeroStat(human, STAT_SPELL_POWER, 3);
elseif (ans==3)
then
ChangeHeroStat(human, STAT_KNOWLEDGE, 3);
elseif (ans==4)
then
ChangeHeroStat(human, STAT_LUCK, 2);
end;
end;

Of course, I change the parameters so that it works for different players.

I change them to the numbers 2, 3, and so on, up to 8; I've highlighted the parameters that are being changed in yellow.

I don't know where the problem is because in ALL the functions, the presence of perk 80 is actually checked, because when it's not present, the else messagebox is shown, but how is it that it works for numbers 1 and 2, but not after that?

User Avatar
2 years ago
Auto-translated
green belly, check out comment #3900
User Avatar
2 years ago
Auto-translated
green belly, I think the issue isn't with TalkBoxForPlayers(), but with the non-functional HasHeroSkill() check. Try to break down the problem, for example, simply write @print(HasHeroSkill("name_of_corresponding_hero", 80)) in the console for each player and see if the result is the same everywhere.

Statistics

Welcome our newest member: recijeb