Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to }{0TT@6bI4
3 years ago
Auto-translated
}{0TT@6bI4
I think the issue is that the green and orange players are AI-controlled. And, I assume, in my case, everything works correctly, and the MessageBoxForPlayers message for AI players is simply redirected to the human players. But in your case... we'll find out. Leave the print statement, but in the number variable, revert to your old formula for calculating the player number.

I reverted everything to how it was, tried it out, and it seems like it worked the same way with my script as well.
User Avatar
3 years ago
Auto-translated
Then I recommend adding a check: if IsAIPlayer(number) then, and only if the statement is true, offer a promotion.
In reply to }{0TT@6bI4
3 years ago
Auto-translated

}{0TT@6bI4
Then I recommend adding a check: if IsAIPlayer(number) then, and only if the statement is true, offer the upgrade.

In short, Azgalor suggested the following:

"Try using GetPlayerFilter(GetCurrentPlayer()) in the MessageBox instead of GetObjectOwner(hero)."

In the end, it worked, thank you both for your help.

User Avatar
3 years ago
Auto-translated
By the way, that's a good idea. We could also use GetPlayerFilter(GetObjectOwner(hero)). I think that would even be better. The thing is, the player filter doesn't match the player number: 1—1 2—2 3—4 4—8 ... That's why I'm against checking GetCurrentPlayer, because heroes can move not only during their turn.
In reply to }{0TT@6bI4
3 years ago
Auto-translated
}{0TT@6bI4
By the way, that's a smart idea. You could also use GetPlayerFilter(GetObjectOwner(hero)). I think that would even be better.

The thing is, the player filter doesn't match the player number:
1—1
2—2
3—4
4—8
...

That's why I'm against checking GetCurrentPlayer, because heroes can move not only during their turn.


Whether it's fun or not, I did it that way yesterday, because in a multiplayer game, when players move simultaneously, everyone receives the messages. As a result, I came up with this script:

function TeleportFinal(hero, object)
    if HasArtefact(hero,53) then
       if object == 'TeleportTreeOne' then
            SetObjectPosition(hero,51,316,-1,-1)
       elseif object == 'TeleportTreeTwo' then
            SetObjectPosition(hero,51,291,-1,-1)
       end
        RemoveArtefact(hero,53)
        Trigger (OBJECT_TOUCH_TRIGGER, object, nil)
    elseif IsAIPlayer(GetObjectOwner(hero)) then
    MessageBoxForPlayers(GetPlayerFilter(GetObjectOwner(hero)),"Maps/Multiplayer/JoyPatriot/Teks/FinalTp.txt", nil)
    end
end

SetObjectEnabled("TeleportTreeOne",nil);
SetObjectEnabled("TeleportTreeTwo",nil);
Trigger(OBJECT_TOUCH_TRIGGER,"TeleportTreeOne","TeleportFinal");
Trigger(OBJECT_TOUCH_TRIGGER,"TeleportTreeTwo","TeleportFinal");

 

P.S

Everything is fine with Owner; for some reason, the website won't let me remove the extra space.

User Avatar
3 years ago
Auto-translated
It would be great to embed the code in a code block; this will enable syntax highlighting, provide a separate window for the code, and use a convenient font.
Attachments 1
1 file attached • Total size: 6.1 KB
3 years ago
Auto-translated

Hello, I decided to create a script that requires one trigger for multiple functions (there are 5 planned, and 2 are currently written), but after a specific function is used, it should stop working. The problem is that I tried to solve this by checking global variables, but I encountered an issue where they don't work; specifically, an error occurs stating that the value "false" is not found.

FORTUNATE_ADVENTURER_DONE = false -- Is this how global variables are declared, correctly?
ESTATES_DONE = false

function FORTUNATE_ADVENTURER (hero)
local playerID = GetObjectOwner(hero)
local art_1 = {1,5,8,12,14,18,19,20,27,31,32,34,55,56,57,58,60,61,62,64,65,66,70,74,75,80,87}
local art_2 = {2,4,9,16,17,21,23,25,35,36,37,38,40,41,42,43,52,63,71,82}
local art_3 = {6,11,13,15,22,33,39,44,45,46,47,48,49,50,51,59,67,68,69,76,77,78,79,81,83,85,86}
local id_1 = art_1[random(length(art_1))]
local id_2 = art_2[random(length(art_2))]
local id_3 = art_3[random(length(art_3))]
local LUCK = GetHeroSkillMastery(hero, SKILL_LUCK)
local Fortunate_adventurer = GetHeroSkillMastery(hero, PERK_FORTUNATE_ADVENTURER)
print(hero, playerID)
if Fortunate_adventurer == 1 then
if LUCK == 1 then
GiveArtifact(hero, id_1, 1)
elseif LUCK == 2 then
GiveArtifact(hero, id_2, 1)
elseif LUCK == 3 then
GiveArtifact(hero, id_3, 1)
end
end
FORTUNATE_ADVENTURER_DONE = true -- Changing the variable's value
end
-----------------------------Dop_Golda------------------------------------------
function ESTATES (hero)
local number = GetObjectOwner(hero)
local playerID = number
local Gold = GetPlayerResource(number,6)
local ESTATE = GetHeroSkillMastery(hero, PERK_ESTATES)
print(hero,playerID)
if ESTATE == 1 then
SetPlayerResource(playerID, 6,Gold+8000)
end
ESTATES_DONE = true -- Changing the variable's value
end

function pp (hero) -- Main function
if not FORTUNATE_ADVENTURER_DONE then
FORTUNATE_ADVENTURER(hero)
end
if not ESTATES_DONE then
ESTATES(hero)
end
end

for i = 1,53 do
for x = 1,4 do
Trigger(OBJECT_TOUCH_TRIGGER,"PortalP" .. x.. "_" ..i,"pp")
end
end
User Avatar
3 years ago
Auto-translated
Shiroyasha2910, let's start by replacing `false` and `true` in the variables with 0 (instead of `false`) and 1 (instead of `true`). The variables store names and numbers, while `true` and `false` (not nil and nil) are defined in the handler functions (GetObjectOwner, IsHeroAlive, HasArtifact, EnableHeroAI, etc.).
User Avatar
3 years ago
Auto-translated
Not according to the code, but just for understanding: any variable is global if it is not declared as local or is not a function argument. The approach with uppercase letters is good.

Instead of false, it is preferable to use nil, and instead of true, use 1. In addition, the reward is only awarded if a skill is present, and the flag variable is set to "false" upon any contact. That is, the approach without a skill means you will never receive the reward again, even if you approach with the skill. Obviously, changing the flag should be moved inside the conditional block.
User Avatar
3 years ago
Auto-translated

Hi! So, I previously asked about creating a counter for killed creatures, and I have this script:

function Duncan_Revenge( combatIndex )
if GetSavedCombatArmyHero( combatIndex, 1 ) == "Duncan" then
if GetSavedCombatArmyCreaturesCount( combatIndex, 0, 112 ) >= 1 then
n_stacks = GetSavedCombatArmyCreaturesCount( combatIndex, 0 );
for i = 0,(n_stacks-1) do
local revenge_target, count, died = GetSavedCombatArmyCreatureInfo( combatIndex, 0, i );
if revenge_target == 112 and died >= 1 then
enemieskilledcounter = enemieskilledcounter + died;
ShowFlyingSign({GetMapDataPath().."Duncan_Counter.txt"; showcounter=enemieskilledcounter}, "Duncan", 1, 10)
end
end
end
end
end

The script works, but it's annoying that the message with the number of killed creatures is displayed multiple times. I understand that this is due to multiple stacks. Is it possible to modify the script so that the message is displayed only once, showing the total number of killed creatures?

User Avatar
3 years ago
Auto-translated

First, calculate all possible losses for each stack, and then display a message if there are any.

local enemieskilledcounter = 0            
n_stacks = GetSavedCombatArmyCreaturesCount( combatIndex, 0 );
for i = 0,(n_stacks-1) do
local revenge_target, count, died = GetSavedCombatArmyCreatureInfo( combatIndex, 0, i );
if revenge_target == 112 and died >= 1 then
enemieskilledcounter = enemieskilledcounter + died;
end
end
if enemieskilledcounter > 0 then
ShowFlyingSign({GetMapDataPath().."Duncan_Counter.txt"; showcounter=enemieskilledcounter}, "Duncan", 1, 10)
end
In reply to Gerter
User Avatar
3 years ago
Auto-translated
Gerter, thank you! I had to make a few minor adjustments so that the counter wouldn't display after each battle, but now it works exactly as intended.
3 years ago
Auto-translated

I'm almost finished creating a map, but I've run into a problem: I need to create a custom bonus for a set of artifacts, and I have no idea how to do it. The idea is that if a hero has the following artifacts: Necromancer's Helmet, Cursed Ring, Ring of Broken Spirit, and Necromancer's Amulet, then:

It guarantees that at the start of the battle, all creatures in the enemy army will be affected by the spells "Slow," "Misfortune," "Weakness," and "Curse." The effect lasts for 10 turns.

Please help.

In reply to Shiroyasha2910
User Avatar
3 years ago
Auto-translated
Shiroyasha2910

I'm almost finished making a map, but I've run into a problem: I need to create a custom bonus for a set of artifacts, and I have no idea how to do it. The idea is that if a hero has the following artifacts: Necromancer's Helmet, Cursed Ring, Ring of Broken Spirit, and Necromancer's Amulet, then:

It guarantees that at the start of the battle, all creatures in the enemy army will be affected by the spells "Slow," "Misfortune," "Weakness," and "Curse." The effect lasts for 10 turns.

Please help.


While this is feasible, it involves a whole range of tasks, starting with disabling the standard bonus for the Necromancer artifact set (if you want a custom bonus instead of a combination of the custom and standard bonuses), writing a complex combat script, and then linking this combat script for the hero with these artifacts in the regular script.
In reply to Grigoriy
3 years ago
Auto-translated
Grigoriy
While such a request is feasible, it involves a whole range of tasks, starting with disabling the standard bonus for the Necromancer artifact set (if you want it to have its own unique bonus, rather than a combination of its own and the standard bonus), writing a complex combat script, and then linking this combat script to the hero with these artifacts in the regular script.

There's no need to disable the standard bonus; checking for the presence of artifacts is very easy. The second part does indeed seem very complex. Do you want to say that it's best to forget about it for now?

Statistics

Welcome our newest member: recijeb