Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to Shiroyasha2910
User Avatar
3 years ago
Auto-translated
Shiroyasha2910

There's no need to disable the standard bonus; the check for artifacts is very easy. The second part does seem quite complex, do you want to suggest that it's best to forget about it for now?

I'm not sure why such powerful debuffs are needed, to the point where even disabling the standard debuff isn't necessary, but Hottabych had a guide on combat scripts with examples. In any case, I forgot to mention that it's impossible to set a specific duration and strength for these spells – everything will depend on the parameters of the hero from whose perspective the scripted spell will be cast.
Моя кампания:
"Упорство самурая"

Мои карты:

Сценарий "Ответный удар"
Сценарий "Воронье отчаяние"
Сценарий "Дикий шторм"
User Avatar
3 years ago
Auto-translated
Hello! Has anyone encountered this bug? In my combat script, I have it set up so that the hero casts the "Haste" spell at the beginning of each battle. It works fine until the hero equips the "Book of Light Magic," after which, during the battle, the console complains that the hero cannot cast the "Haste" spell. Is there any way to fix this?
In reply to Азгалор
User Avatar
3 years ago
Auto-translated
Azgalor
Hello! Has anyone encountered this bug? In my combat script, I have it set so that the hero casts the "Haste" spell at the beginning of each battle. It works fine until the hero equips the "Tome of Light," after which, during the battle, the console complains that the hero cannot cast the "Haste" spell. Is there any way to fix this?

Perhaps the hero didn't have enough mana when you tested it with the tome?
Моя кампания:
"Упорство самурая"

Мои карты:

Сценарий "Ответный удар"
Сценарий "Воронье отчаяние"
Сценарий "Дикий шторм"
In reply to Grigoriy
User Avatar
3 years ago
Auto-translated
Grigoriy

Perhaps the hero didn't have enough mana at the time of the test with the tome?
Hmm, that's strange. My script is written so that mana for the spell is given first, and then the spell itself is cast. For some reason, if the hero doesn't have enough mana for the spell at the beginning of the battle, even after the mana is given, the game doesn't cast it.

Added 18 minutes later
In general, I added mana to the preparation stage, now it works even if the hero has 0 mana before the battle.
In reply to Shiroyasha2910
User Avatar
3 years ago
Auto-translated
Shiroyasha2910

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

The hero 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.


If you understand how to link the execution of a combat script to heroes wearing specific artifacts, then the rest is quite simple:
function Start()
  for side=0,1 do
    if GetHero(side) then
      if GetHeroName(GetHeroSide()) then --Your in-battle check for the hero. I recommend creating a global variable in the adventure map script, such as "hero".."_NecArtSet," and setting it to 1 if the set is present (and 0 if it's not), and then writing a check like if GetGameVar(GetHeroName(GetHeroSide()).."_NecArtSet")+0==1 then
        startThread(function(side)
        combatSetPause(1)
        SummonCreature(side, CREATURE_YETI, 1)
        for n, unit in GetCreatures(side) do if GetCreatureType(unit)==CREATURE_YETI then local _helper = unit break; end; end
        while not exist(_helper) do sleep() end
        for n, spell in {SPELL_MASS_SLOW, ...} --List of mass-cast spells
          UnitCastGlobalSpell(_helper, spell)
        end
        removeUnit(_helper)
        combatSetPause(nil)
        )
      end
    end
  end
end

I wrote the script without testing, so please adapt and test it. You will also need to replace the mana cost in the Neutrals/Yeti creature's characteristics with ~200 and the skill in the school so that it lasts 10 turns. Or play around with the number of summoned creatures.

С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
User Avatar
3 years ago
Auto-translated
Hello, how would I write a function with an array or table to save the coordinates of creatures so that I can use them later for respawning new ones? The coordinates for spawning would, accordingly, be chosen randomly from the saved list, and new creatures wouldn't be placed if the position is already occupied by their rightful owners.
User Avatar
3 years ago
Auto-translated
Both in battle and on the adventure map, when spawning a creature onto an occupied cell, it will spawn on the nearest available cell.

Overall, there is nothing particularly complicated.
function SaveCreaturePos(table, mob)
local x, y, z = GetObjectPosition(mob)
creature_coord_table[mob] = {x=x, y=y, floor=z}
end --Something like this
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
User Avatar
3 years ago
Auto-translated
}{0TT@6bI4
Both in combat and on the adventure map, when a creature is spawned on an occupied tile, it will spawn on the nearest available tile.

Overall, there's nothing particularly complicated about it.
function SaveCreaturePos(table, mob)
local x, y, z = GetObjectPosition(mob)
creature_coord_table[mob] = {x=x, y=y, floor=z}
end --Something like this

 

Still, it's not quite working. I wrote a script to save coordinates like this:
function SaveCoordinates( table )
local monster_list = {};
local k = 0;
for i=1,500 do
monster = "m"..i;
if IsObjectExists( monster ) then
k = k + 1;
monster_list[k] = monster;
local x, y, z = GetObjectPosition(monster_list[k])
creatures_positions[k] = {x=x, y=y, floor=z}
end;
end;
end;

Then, in another function, I try to take a random position from this list and place a creature on it, but the game gives an error because x, y, and z are empty. In another function, I wrote the coordinate retrieval like this:

for k=1, length(creatures_positions) do
local x, y, z = random(length(creatures_positions[k]))
User Avatar
3 years ago
Auto-translated
Firstly, you can avoid the hassle of naming all the monsters individually and use the function GetObjectNamesByType("MONSTER"). Secondly, it's clearly incorrect to try to store a single value, which is returned by a RANDOM function that receives a TABLE, into 3 VARIABLES. This is just nonsensical. Just use x = creatures_position[k].x, y = ..., z = ...
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
User Avatar
3 years ago
Auto-translated
}{0TT@6bI4
First, you don't need to bother naming all the mobs; you can use the GetObjectNamesByType("MONSTER") function.

Second, it's obviously wrong to try to write a single value, which is returned by a RANDOM function, into 3 VARIABLES, when a TABLE is passed to it. That's just... something.

Just x=creatures_position[k].x, y=..., z = ...

So, I took the developers' script for spawning bots from map 3 of the campaign for Freya, Lord of the North, and modified it for my needs, also using a script for spawning red heroes near cities from the last map with Freya. Here's what I got:

function SaveCoordinats( table )
local monster_list = {};
local k = 0;
for i=1,500 do
monster = "m"..i;
if IsObjectExists( monster ) then
k = k + 1;
monster_list[k] = monster;
creatures_positions[k] = GetObjectPosition(monster_list[k])
end;
end;
creatures_positions_list = length(creatures_positions)
end;

function RespawnUnitsByLuck()
-- if ( GetDate(WEEK) == 3 ) and ( GetDate(DAY_OF_WEEK) == random(6) + 1 ) then
local WR_luck = GetHeroStat(WR, STAT_LUCK)
local respawns_types = { CREATURE_AIR_ELEMENTAL, CREATURE_PHOENIX }
local respawns_quantities = { 100 * diff, 10 * diff }
local respawns_mood = {3, 0}
local respawns_courage = {1, 2}
local respawns_num = 20 + diff
local previous_pos = {}
local respawns_id = 0
local CanRespawnUnitsByLuck = random(100) + (10*(WR_luck+1)) * mod((WR_luck+1),diff)

if CanRespawnUnitsByLuck >= mod(70,(WR_luck+2)) + (60+diff) then --( 70 + (10+diff) ) then
print("Chance ", CanRespawnUnitsByLuck ,". Spawning units")
elseif CanRespawnUnitsByLuck < mod(70,(WR_luck+2)) + (60+diff) then --( 50 + (10+diff) ) then
print("Chance ", CanRespawnUnitsByLuck ,". Not spawning anyone")
return
end

if WR_luck >= 7 then
courage = {1, 0}
respawns_num = 20 * diff
respawns_quantities = { 200 * diff, 20 * diff }
end
for k=1, creatures_positions_list do
if ( IsTilePassable(creatures_positions[k][3]) ) then
local type = random( 1 ) + 1
if type == 2 and WR_luck < 3 then
type = 1
end
local creaturetype = respawns_types[ type ]
local quantity = respawns_quantities[ type ]
local mood = respawns_mood[ type ]
local courage = respawns_courage[ type ]
respawns_id = respawns_id + 1;
local respawnsname = 'respawns' .. respawns_id;
CreateMonster( respawnsname, creaturetype, quantity, creatures_positions[k][3], mood, courage, random( 360 ) );
end;
end;
-- end;
end;

The game complains about "attempt to index a number value". I'm running out of ideas on how to fix this spawn so that it works properly 🙃 The original, developer's version worked, but my map is large, with many bushes, and filling each cell with a mask so that a bot doesn't spawn there is not ideal. It's easier to spawn them on existing monsters, so I already have the coordinates for that on the map.

User Avatar
3 years ago
Auto-translated
Let me point out the exact error right away. When you assign the return value of the GetObjectPosition function to crearure_positions[k], the corresponding element becomes a number instead of a table of three elements. Therefore, you need to do this again: creature_positions[k][1], creature_positions[k][2], creature_positions[k][3] = GetObjectPosition(monster).
And in the IsTilePassable check, you first need to save the corresponding elements of the table in local x, y, and z, and then pass them to IsTilePassable.
And it is precisely because of this that the error "attempt to index a number" occurs. After all, creature[k] is just a number.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
User Avatar
3 years ago
Auto-translated
}{0TT@6bI4
Let me start by pointing out a definite error. When you assign the return value of the GetObjectPosition function to creature_positions[k], that element becomes a number instead of a table with three elements. Therefore, you need to do this again: creature_positions[k][1], creature_positions[k][2], creature_positions[k][3] = GetObjectPosition(monster)
And in the IsTilePassable check, you should first save the corresponding elements of the table into local x, y, and z, and then pass them to IsTilePassable.
And this is precisely why you're getting the "attempt to index a number" error. Because creature[k] is just a number.

This one didn't work, but your previous version did!) However, I had to make some more adjustments, as IsTilePassable was complaining about an incorrect 3rd argument. In general, everything works, but the existing spawn points are selected strictly from the list, not randomly, which is quite disappointing. How can I randomize this without breaking anything?

 

Another question. I have a check for luck (GetHeroStat(hero, STAT_LUCK)), and I noticed in the console that even if I set a hero's luck to 10, it will only display up to 5. So, if I put a condition in the script that luck must be greater than 6, will that condition always be false?

User Avatar
3 years ago
Auto-translated
In other words, you want to replace all creatures from 1 to k when a certain condition is met, with a random selection, but you want this to happen:
a) Non-sequentially
b) Without repetitions
c) With all k elements

Then you need an interesting algorithm:
local used_indexes = {}
for i=1, k do
repeat N=random(k)+1
until not used_indexes[N]
used_indexes[N] = 1;
--Actions with the creature with number N (not k!!)
end
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________
In reply to }{0TT@6bI4
User Avatar
3 years ago
Auto-translated
Hi everyone! I need help with a script. I wrote the following script:
function ChristianAttacked()
DeployReserveHero("Christian", 98, 108, 0)
sleep(1)
MoveHero("Christian", 126, 139, -1)
if IsHeroAlive(hero) and GetObjectOwner("castle") == PLAYER_1 then
StartDialogScene("/DialogScenes/FallenKnight/S3/DialogScene.xdb#xpointer(/DialogScene)")
sleep(1)
SetObjectiveState("prim6", OBJECTIVE_ACTIVE, 1)
else SetObjectiveState("prim5", OBJECTIVE_FAILED, 1)
loose()
end;
end;

It seems like everything is correct, BUT - the function below doesn't work! Everything else, including the else part, works perfectly. What's the error? I'm sure the path to the video is correct...

if IsHeroAlive(hero) and GetObjectOwner("castle") == PLAYER_1 then
StartDialogScene("/DialogScenes/FallenKnight/S3/DialogScene.xdb#xpointer(/DialogScene)")
sleep(1)
SetObjectiveState("prim6", OBJECTIVE_ACTIVE, 1)

Мои карты:
Падший рыцарь
Сердце Хаоса

Мои моды:
Визуальные:
Изменение внешнего вида героев-некромантов
Существа-жители и кое-что по мелочи в городах Ордена Порядка, Некрополиса и Инферно

NCF-существа:
Странствующие рыцари
Наемники

User Avatar
3 years ago
Auto-translated
Because the hero is not defined. Check in the console. The variable hero contains nil, and obviously, the IsHeroAlive check returns false.
С уважением, }{0TT@6bI4
_________________
Группа картостроителей
Там ответы на вопросы, руководства, гайды и прочее
Discord-сервер "Герои 5: S.T.A.L.K.E.R"
Сервер по модификации "Герои 5: S.T.A.L.K.E.R"
_________________

Statistics

Welcome our newest member: recijeb