Skip to content

Posts from Scripts

4.8 (8 ratings)
In reply to OrnsteinDragonslayer
User Avatar
8 years ago
Auto-translated
OrnsteinDragonslayer
I wrote a function based on your advice:
But after destroying all the demons, nothing happens. Can you tell me where the error is?

In the startThread function, it should be written without quotes:
startThread(cherti);
Perhaps that's why it's not working.
OrnsteinDragonslayer

And also, is it possible to create a hidden connection between quests? I'll try to come up with a simple example:
Quest - destroy an enemy hero
Secondary quest - destroy a neutral.

When you approach the enemy hero, dialogue #1 plays, but if you have destroyed the neutrals, dialogue #2 will play.
Also, if you simply fight the enemy hero, his army will have 5 phoenixes.
But if you defeat the neutrals, it will have 250 wolves and some artifact will be found.
Is it possible to implement such things?
You can create a connection, but how depends on the situation. For example, in the case of wolves and phoenixes, when the additional quest is completed, you can immediately replace the enemy hero's army and add an artifact.
There are two options for the dialogue. The first is to replace the trigger on the enemy hero when the additional quest is completed, which will lead to the second dialogue.
The second is to use the GetObjectiveState function to check whether the additional quest has been completed and, depending on whether the condition has been met, provide one or the other option.
But I would recommend the second option; I had a lot of trouble with the first one.
And by the way, there is a third option - create a variable, equal to, for example, 0, and when the additional quest is completed, change its value to 1. And when you touch the enemy hero, check if the variable is equal to 1. But this is essentially the same as the second option, only it takes up an extra variable
User Avatar
8 years ago
Auto-translated
But after destroying all the demons, nothing happens. Can you tell me where the error is?
Also, instead of the Exists function, use IsObjectExists.
In reply to Jack_of_shadows
User Avatar
8 years ago
Auto-translated
Jack_of_shadows
Instead of the Exists function, use IsObjectExists.

Thank you, but the issue was resolved by removing the quotes in the start thread. I didn't know they weren't needed there.
8 years ago
Auto-translated
Hello. Can you write a function for dwellings: when a player visits Orc dwellings (for example), a message appears prompting them to destroy the dwellings, after which the player receives resources, but the computer can still interact with them normally before that?
User Avatar
8 years ago
Auto-translated
There's an enemy hero. I need him to "resurrect" after he's killed. And these resurrections should continue until the player character captures all the mines. I've written a few functions, but something isn't working. I don't know how to connect them. Maybe you can help?
function ImmortalNecr()
while (1) do
sleep(2);
if (Exists('mine1') == nil) and (Exists('mine2') == nil) and (Exists('mine3') == nil) and (Exists('mine4') == nil) and (Exists('mine5') == nil) and (Exists('mine6') == nil) then
DefeatNecr();
break
end;
end;
end;

startThread(ImmortalNecr);

function DefeatNecr()
RemoveObject("Aberrar");
end;

function RessurectNecr(heroname,winner)
if heroname=='Aberrar' then
DeployReserveHero('Aberrar', 46, 140, GROUND);
end;
end;
In reply to OrnsteinDragonslayer
8 years ago
Auto-translated
OrnsteinDragonslayer
There is an enemy hero. After he is killed, he should "resurrect." These resurrections will continue until the player captures all the mines. I wrote a few functions, but something isn't working. I don't know how to connect them. Maybe you can help?

I'm not very good with scripts, but this function should work, considering that the AI has a city and the mines have script names:
function start()
MakeHeroReturnToTavernAfterDeath("Aberrar",1,1)
for i = 1,6 do
sleep(1)
Trigger(OBJECT_CAPTURE_TRIGGER,"mine"..i,"ImmortalNecr")
end
end

startThread(start)

function ImmortalNecr()
if GetObjectOwner("mine1") == 1 and GetObjectOwner("mine2") == 1 and GetObjectOwner("mine3") == 1 and GetObjectOwner("mine4") == 1 and GetObjectOwner("mine5") == 1 and GetObjectOwner("mine6") == 1 then
RemoveObject("Aberrar")
MakeHeroReturnToTavernAfterDeath("Aberrar",nil)
end
end
User Avatar
8 years ago
Auto-translated
You can use the `COMBAT_RESULTS_TRIGGER` and, if the hero that needs to be resurrected is defeated in battle, check the owner of the mines and act accordingly. Something like this:
function fightResult(fightID)

local LooserName = GetSavedCombatArmyHero(fightID, 0)
if(LooserName == 'Aberrar') then
if(GetObjectOwner("mine1") == 1) and
(GetObjectOwner("mine2") == 1) and
(GetObjectOwner("mine3") == 1) and
(GetObjectOwner("mine4") == 1) and
(GetObjectOwner("mine5") == 1) and
(GetObjectOwner("mine6") == 1) then
UnreserveHero('Aberrar')
else
DeployReserveHero('Aberrar', 46, 140, GROUND)
end
end

end

Trigger(COMBAT_RESULTS_TRIGGER, 'fightResult')
Hello. Can you write a function for dwellings: when a player visits Orc dwellings (for example), a message about their destruction is displayed, after which the player receives resources, but the computer can interact with them normally until then?

Attach the `OBJECT_CAPTURE_TRIGGER` to the dwelling, and when it triggers, write the necessary actions:
function Capture(n1, n2, s1, s2)

if(n2 == 1) then
MessageBox(...)
SetPlayerResource(...)
RemoveObject(...) or RazeBuilding(...), if you need to destroy it
end

end

Trigger(OBJECT_CAPTURE_TRIGGER, 'object name', 'Capture')
In reply to Gerter
User Avatar
8 years ago
Auto-translated
Gerter
You can attach the COMBAT_RESULTS_TRIGGER and, if the hero that needs to be resurrected loses a battle, check the owner of the mines and act accordingly. Something like this:
function fightResult(fightID)

local LooserName = GetSavedCombatArmyHero(fightID, 0)
if(LooserName == 'Aberrar') then
if(GetObjectOwner("mine1") == 1) and
(GetObjectOwner("mine2") == 1) and
(GetObjectOwner("mine3") == 1) and
(GetObjectOwner("mine4") == 1) and
(GetObjectOwner("mine5") == 1) and
(GetObjectOwner("mine6") == 1) then
UnreserveHero('Aberrar')
else
DeployReserveHero('Aberrar', 46, 140, GROUND)
end
end

end

Trigger(COMBAT_RESULTS_TRIGGER, 'fightResult')

I checked it, and I have a couple of questions right away. How do I make the mines initially belong to a specific player?
And secondly: the script is malfunctioning; the console says: Aberrar does not belong to any player. Although in the player properties, he is waiting in the reserve heroes. WTF?
User Avatar
8 years ago
Auto-translated
In the editor, you can set the owner. At what point does it say that it doesn't belong to anyone? Right when the map starts, or after a battle?
In reply to Gerter
User Avatar
8 years ago
Auto-translated
Gerter
In the editor, you can set the owner. At what point does it say that it doesn't belong to anyone? Right when the map starts, or after a battle?

Maybe I'm blind, but where is it?



The error about the absence appears after the battle.
User Avatar
8 years ago
Auto-translated
yes, you can't use it in the editor for abandoned creatures, but you can for the others... then use SetObjectOwner() to assign ownership. As for the error after the battle, I don't know, I just checked it myself, and it worked fine...
In reply to Gerter
User Avatar
8 years ago
Auto-translated
Gerter
Yes, you can't do that for abandoned creatures in the editor, but you can for the others... then you can set it using SetObjectOwner(). As for the error after the battle, I don't know, I just checked it myself, and it worked fine...
Thank you, I figured out the mines. Here's the error, just in case. Maybe I translated something incorrectly. Although, does it even matter if you don't have it at all? I don't understand. Maybe there's a way to rewrite the script? Some kind of workaround?

Also, I have a rather strange question... why doesn't this work?
function HelpSin ()
MessageBox("/Maps/SingleMissions/rework (4)/sin.txt");
RemoveObject("sin");
Trigger(REGION_ENTER_AND_STOP_TRIGGER , "sinRegion", nil);
end;

Trigger(REGION_ENTER_AND_STOP_TRIGGER , "sinRegion", "HelpSin");

I have a lot of similar functions, but this one specifically doesn't work...

Added 8 minutes later
Oh, the second problem was solved simply by the fact that the region was surrounded around the unit on the map, and since this area is already considered as... an aggro zone for this unit, and the hero doesn't actually step into it... in general, I just stretched the region, and everything is okay.
User Avatar
8 years ago
Auto-translated
it’s hard to say for sure, of course, but if you looked at the entire map, maybe some other part of the code is affecting it…

as an alternative, you could try using PLAYER_REMOVE_HERO_TRIGGER:
function RemoveHero(looser, winner)
if(looser == 'Aberrar') then
--checks for mines, etc.
end
end

Trigger(PLAYER_REMOVE_HERO_TRIGGER, id of the desired player, 'RemoveHero')
In reply to Gerter
User Avatar
8 years ago
Auto-translated
Gerter
it's hard to say for sure, of course, if you look at the entire map, maybe some other part of the code is affecting it...

as an alternative, you can try using PLAYER_REMOVE_HERO_TRIGGER:
function RemoveHero(looser, winner)
if(looser == 'Aberrar') then
--checks for mines, etc.
end
end

Trigger(PLAYER_REMOVE_HERO_TRIGGER, id of the desired player, 'RemoveHero')

In this case, nothing happens at all after the hero is killed. There isn't even an error. And check your PMs.
8 years ago
Auto-translated
Try this instead:
function RemoveHero()
while 1 do
if not IsHeroAlive("Aberrar") then
if GetObjectOwner("mine1") == 1 and GetObjectOwner("mine2") == 1 and GetObjectOwner("mine3") == 1 and GetObjectOwner("mine4") == 1 and GetObjectOwner("mine5") == 1 and GetObjectOwner("mine6") == 1 then
UnreserveHero("Aberrar")
else DeployReserveHero("Aberra", coordinates)
end
end
end
end

startThread (RemoveHero)


Added 8 minutes later
Gerter


Attach OBJECT_CAPTURE_TRIGGER to a dwelling, and when it triggers, write the necessary actions:
function Capture(n1, n2, s1, s2)

if(n2 == 1) then
MessageBox(...)
SetPlayerResource(...)
RemoveObject(...) or RazeBuilding(...), if you need to destroy it
end

end

Trigger(OBJECT_CAPTURE_TRIGGER, 'object name', 'Capture')

Thank you, but there are two problems here: there are many dwellings, and the computer doesn't interact with them at all. I meant a function where I touch a dwelling, and I'm offered what to do with it. At the same time, it is not captured, but the computer can interact with it as usual.

Statistics

Welcome our newest member: recijeb