Skip to content

Posts from Scripts for beginners.

4.5 (2 ratings)
User Avatar
2 years ago
Auto-translated
AngryTapok1337, I fixed the code there, try it. What is the console complaining about? Maybe the error appears in a different line. Or are you not getting an error, but the function simply isn't working?

Added 25 minutes ago
I tested it, and it works. However, there is one error: the destination point for delivery to the city should not be the point where the city is located, but the entrance point to the city, i.e., where the heroes stand when they visit the city. Although, even without this fix, the caravan spawned and was filled with creatures. It just didn't move and stood at the spawn point, daily producing the standard error of caravans being unable to move as if it were blocked by something or the city garrison doesn't have any slots. Thus, my initial script version (without the addition with the check for a completed quest) works.
In reply to Азгалор
2 years ago
Auto-translated

Azgalor
AngryTapok1337, I've fixed the code there, try it out. What error does the console report? Maybe the error appears in a different line. Or does it not display an error, but the function simply doesn't work?

Added 25 minutes later
I've tested it, and it works. However, there is one error: the destination point for delivering goods to the city should not be the location of the city itself, but the entrance point to the city, i.e., where heroes stand when they visit the city. Even without this fix, the caravan spawns and is filled with creatures. It just doesn't move and stays at the spawn point, daily displaying the standard error about the inability of caravans to move, as if it is blocked by something or the city garrison does not have available slots. Therefore, my initial script version (without the addition that checks for a completed quest) works.

 

It doesn't work at all, no matter how I insert it. At the same time, it doesn't display an error in the line where the caravan should spawn. It's as if there's nothing about the caravan in the code at all. Perhaps the problem lies in the rest of the code or in the map itself?

Attachments 1
1 file attached • Total size: 250.4 KB
In reply to AngryTapok1337
User Avatar
2 years ago
Auto-translated
AngryTapok1337
It doesn't work at all, no matter how I try to implement it. At the same time, the script doesn't display any errors when the caravan is supposed to spawn. It's as if there's nothing about the caravan in the code at all. Perhaps the problem lies in the rest of the code or even in the map itself?
As soon as I launched the map, I was immediately greeted with an error about the missing region RegionFight7, which your function RegionFight2F references in two lines. I commented them out, restarted the map, and the caravan error appears when I try to turn it. The `sleep(4)` is in the wrong place; it should be before `SetObjectRotation` (as in the code I originally sent). You posted it in your previous message with the note "This is what I got." Because of this, the game doesn't have time to load the caravan, and then it immediately tries to turn it, breaking the script because it's trying to affect an object that technically doesn't exist on the map yet (it works like with `DeployReserveHero`). Also, set the rotation angle to -90, as it rotates to face the corner of the map
In reply to Азгалор
2 years ago
Auto-translated

Azgalor
As soon as I launched the map, I was immediately greeted with an error about the missing region RegionFight7, which is referenced in 2 lines in the RegionFight2F function. I commented them out, restarted the map, and now I get an error with the caravan when I try to turn it. The sleep(4) is in the wrong place; it should be before SetObjectRotation (as in the code I originally sent). You posted it in the previous message with the note "This is what I got." Because of this, the game doesn't have time to load the caravan, and then it immediately tries to turn it, breaking the script because it's trying to affect an object that technically isn't on the map yet (it works like DeployReserveHero). Also, set the rotation angle to -90, because it turns to face the corner of the map

I saw the region error when I sent it and fixed it, but I guess I forgot to save it 😁

 

Thanks for the help - I'll try moving the sleep function when I get home.

User Avatar
2 years ago
Auto-translated
AngryTapok1337, it's a minor thing, but just in case, to avoid unnecessary spam in the console, use `nil` instead of `false` in `SetObjectEnabled` when disabling objects. The script won't break, it just clutters the console with extra text.
In reply to Азгалор
2 years ago
Auto-translated

Azgalor
As soon as I launched the map, I was immediately greeted with an error about a missing region, RegionFight7, which is referenced in 2 lines within the RegionFight2F function. I commented them out, restarted the map, and now I get an error with the caravan when I try to turn it. The sleep(4) is in the wrong place; it should be before SetObjectRotation (like in the code I originally sent). You posted it in the previous message with the note "This is what I got." Because of this, the game doesn't have time to load the caravan, and then it immediately tries to turn it, breaking the script because it's trying to affect an object that technically doesn't exist on the map yet (it works like with DeployReserveHero). Also, set the rotation angle to -90, because it turns to face the corner of the map

Everything works now, thank you very much!smile

 

I'll leave the code here, just in case someone needs it.

 

CARAVAN = "caravan"

function respawn_caravan()
    if (GetDate( DAY_OF_WEEK ) == 5) and ( GetObjectiveState("NaydiSuhestv1") == OBJECTIVE_COMPLETED ) then
        car = CARAVAN..GetDate(DAY)
        CreateCaravan(car, PLAYER_1, GROUND, 173, 68, GROUND, 156, 159 )
        sleep(4)
        SetObjectRotation(car, 240)
        AddObjectCreatures(car, CREATURE_CHAMPION, 5)
        AddObjectCreatures(car, CREATURE_LONGBOWMAN, 75)
        AddObjectCreatures(car, CREATURE_VINDICATOR, 50)
        AddObjectCreatures(car, CREATURE_ZEALOT, 15)
        sleep(4)
        MessageBox ("/Maps/SingleMissions/ZimaMap1v2NoScriptsNoQuests/Rally.txt")
    end
end

2 years ago
Auto-translated

I wanted to ask for help with a script again, but somehow I managed to get it working. smile

 

The script passes the city and hero to the player when they complete a quest (in my case, the quest is initially hidden, so I couldn't just use OBJECTIVE_STATE_CHANGE_TRIGGER). It's likely that this could have been written more simply, and if so, I'll be corrected. But anyway, I'll leave it here, just in case it's useful to someone.

 

function InfernoF()
 if ( GetObjectiveState("KillDruid") == OBJECTIVE_COMPLETED ) then
         MessageBox ("/Maps/SingleMissions/ZimaMap1v2NoScriptsNoQuests/Succubus2.txt")
         sleep(1)
         SetObjectOwner( "InfTown", 1 )
         DeployReserveHero( "Biara", 28, 21, UNDERGROUND )
         end
end

Trigger(OBJECTIVE_STATE_CHANGE_TRIGGER, "KillDruid", "InfernoF")

 



Added 4 minutes ago

And again, I'm asking for help.

The problem is this: I had working scripts that triggered a battle when a hero entered a region. Everything worked perfectly. But suddenly, I had a brain fart and wanted to give the player two heroes at the start (partly because the map is large, and exploring it with one hero could take until the second coming, but that's not the main point). So, I added a second hero to the player, and immediately everything went wrong - the script works as it should, and the battle starts, but... only the first hero fights (let's call him Hero1). That is, when Hero2 enters the scripted region, Hero1 still fights, regardless of where he is currently located.

The question is: how can I modify the script so that the battle is fought not by a specific hero, but by the one who enters the region?

The script is attached.

function Region1F ()
         MessageBox ("/Maps/SingleMissions/ZimaMap1v2NoScriptsNoQuests/Spasenie1.txt")
         StartCombat("RedHeavenHero04", nil, 4, 93, 100, 93, 100, 95, 75, 101, 15, nil)
         RemoveObject('g1')
         RemoveObject('g2')
         RemoveObject('g3')
         RemoveObject('g4')
         RemoveObject('g5')
         RemoveObject('g6')
         sleep(1)
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"Region1",nil)
end
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"Region1","Region1F")

 

Thank you in advance!

In reply to AngryTapok1337
User Avatar
2 years ago
Auto-translated
AngryTapok1337

I wanted to ask for help with a script again, but somehow I managed to get it working. smile

 

The script gives the player a town and a hero when they complete a quest (in my case, the quest is initially hidden, so I couldn't just use OBJECTIVE_STATE_CHANGE_TRIGGER). It's probably possible to write it more simply, and if so, I'll be corrected. But anyway, I'll leave it here, just in case it's useful to someone.

 

function InfernoF()
 if ( GetObjectiveState("KillDruid") == OBJECTIVE_COMPLETED ) then
         MessageBox ("/Maps/SingleMissions/ZimaMap1v2NoScriptsNoQuests/Succubus2.txt")
         sleep(1)
         SetObjectOwner( "InfTown", 1 )
         DeployReserveHero( "Biara", 28, 21, UNDERGROUND )
         end
end

Trigger(OBJECTIVE_STATE_CHANGE_TRIGGER, "KillDruid", "InfernoF")

 



Added 4 minutes ago

And again, I'm asking for help.

The problem is this: I had working scripts for a hero to enter a region and a battle to begin. Everything worked perfectly. But suddenly, something went wrong, and I wanted to give the player two heroes at the start (partly because the map is large, and it would take until the second coming to clear it with one hero, but that's not the point). So I added a second hero to the player, and immediately everything went wrong - the script works as it should, and the battle begins, but... only the first hero fights (let's call him hero1). That is, when hero2 enters the scripted region, the battle is still fought by hero1, regardless of where he is now.

The question is: how can I change the script so that the battle is fought not by a specific hero, but by the one who enters the region?

The script is attached.

function Region1F ()
         MessageBox ("/Maps/SingleMissions/ZimaMap1v2NoScriptsNoQuests/Spasenie1.txt")
         StartCombat("RedHeavenHero04", nil, 4, 93, 100, 93, 100, 95, 75, 101, 15, nil)
         RemoveObject('g1')
         RemoveObject('g2')
         RemoveObject('g3')
         RemoveObject('g4')
         RemoveObject('g5')
         RemoveObject('g6')
         sleep(1)
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"Region1",nil)
end
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"Region1","Region1F")

 

Thank you in advance!

I'll just write the script, because I'm too lazy to explain.
function Region1F (hero)
MessageBox ("/Maps/SingleMissions/ZimaMap1v2NoScriptsNoQuests/Spasenie1.txt")
StartCombat(hero, nil, 4, 93, 100, 93, 100, 95, 75, 101, 15, nil)
RemoveObject('g1')
RemoveObject('g2')
RemoveObject('g3')
RemoveObject('g4')
RemoveObject('g5')
RemoveObject('g6')
sleep(1)
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"Region1",nil)
end
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"Region1","Region1F")
In reply to AngryTapok1337
User Avatar
2 years ago
Auto-translated

AngryTapok1337
I need help again. The problem is this: I had working scripts that triggered a battle when a hero entered a region. Everything worked perfectly. But suddenly, I had an idea and wanted to give the player two heroes at the start (partly because the map is large, and it would take until the second coming to explore it with just one hero, but that's not the main point). So, I added a second hero for the player, and immediately everything went wrong – the script works as it should, and the battle starts, but... only the first hero fights (let's call him Hero1). That is, when Hero2 enters the scripted region, Hero1 still fights the battle, regardless of where he is currently located. The question is: how can I modify the script so that the battle is fought not by a specific hero, but by the one who enters the region? The script is attached. Thank you in advance!
Here's the script, but let's add that it should only work for our heroes; otherwise, an enemy bot might (just in case?) run in and activate the script, which is not what we want (or is it?).
function Region1F( heroName )
      if ( heroName == "scripted name of the first main hero" ) or ( heroName == "scripted name of the second main hero" ) then --if more main heroes are planned, you can add more checks in the same way as for the second hero
            MessageBox ("/Maps/SingleMissions/ZimaMap1v2NoScriptsNoQuests/Spasenie1.txt")
            StartCombat( heroName, nil, 4, 93, 100, 93, 100, 95, 75, 101, 15, nil)
            RemoveObject('g1')
            RemoveObject('g2')
            RemoveObject('g3')
            RemoveObject('g4')
            RemoveObject('g5')
            RemoveObject('g6')
            sleep(1)
            Trigger(REGION_ENTER_AND_STOP_TRIGGER,"Region1",nil)
      end
end
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"Region1","Region1F")
In reply to Азгалор
User Avatar
2 years ago
Auto-translated
Azgalor

That's it, but let's add that the script should only work for our heroes; otherwise, an enemy bot might come (just in case?) and activate the script, which is not what we want (or is it?).

function Region1F( heroName )
if ( heroName == "scripted name of the first main hero" ) or ( heroName == "scripted name of the second main hero" ) then --if more main heroes are planned, you can add them in the same way as the check for the second hero
MessageBox ("/Maps/SingleMissions/ZimaMap1v2NoScriptsNoQuests/Spasenie1.txt")
StartCombat( heroName, nil, 4, 93, 100, 93, 100, 95, 75, 101, 15, nil)
RemoveObject('g1')
RemoveObject('g2')
RemoveObject('g3')
RemoveObject('g4')
RemoveObject('g5')
RemoveObject('g6')
sleep(1)
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"Region1",nil)
end
end
Trigger(REGION_ENTER_AND_STOP_TRIGGER,"Region1","Region1F")
Wow, your script version is much better than mine. (WHERE ARE YOUR SCENARIOS, HUH? WITH YOUR INTELLIGENCE, YOU COULD MAKE THEM AMAZING! No sarcasm.)
In general, I recommend AngryTapok1337 to download maps from the forum and explore them, or explore the campaign maps. This way, you can learn a lot and discover many interesting possibilities.
2 years ago
Auto-translated

Thanks to BlueHeavenHero and Azgalor for their help!

And thank you for the advice on downloading maps. I had completely forgotten that it could be done that way. redface

In reply to AngryTapok1337
2 years ago
Auto-translated
Hello! Here's the situation: I'd like to create a cool, simple mod for Heroes 3 in VCMI for my friend's birthday. I just want to add a couple of artifacts with my own design, at least. But I'm not very good at programming... I managed to create a JSON code for the artifact itself, but, as I understand it, the problem is attaching the animation file in .def format for display on the map. I've been looking for information on how to create these .def files, but I haven't found anything. I just want the image to be visible during the game and to be able to pick it up. Is it possible to convert a PDF to a .def file or write a JSON code for a sequence of images (I think that's also possible)? I really want everything to work. Thank you in advance!
User Avatar
2 years ago
Auto-translated
Enthusiasm is good, but this isn't the right place for that. You should go to this section.
In reply to Ment
2 years ago
Auto-translated
Hello, dear modders! Could you please tell me how I can add the hero Nicholas, a vampire, in the multiplayer map editor? I didn't find him in the "Heroes (Scenario)" list, and I don't know how to add him using a script.
User Avatar
2 years ago
Auto-translated
Killer5029, for convenience, you can assign any Necromancer hero, and then select him and, on the left, in the object's properties, go to his Shared settings, and in the list of Necropolis heroes, select the hero Nikolay, click OK, and the hero will change to Nicholas the vampire.

Statistics

Welcome our newest member: recijeb

Users Online 3 users 1341 guests