Skip to content

Posts from Scripts

4.8 (8 ratings)
User Avatar
12 years ago
Auto-translated
Were there any pop-up monster icons somewhere? On some object? Or am I imagining things...
User Avatar
12 years ago
Auto-translated
They existed (eternal slavery, dragon set), but they are not related to scripts in any way.
User Avatar
12 years ago
Auto-translated
Damn, the script isn't working.
function burn()
----
for i, hut in GetObjectNamesByType('PEASANT_HUT') do
Trigger(4, hut, 'hutF')
end
-----
startThread(burn2)
end

startThread(burn)

---

fires = 0

function burn2(hero, hut)
while 1 do
sleep(1)
if GetCurrentPlayer() == 1 and fires == 0 then
SetObjectEnabled(hut , nil)
fires = 1
elseif GetCurrentPlayer() == 2 or GetCurrentPlayer() == 3 or GetCurrentPlayer() == 4 then
SetObjectEnabled(hut , true)
fires = 0
end
end
end

----

hutt = 0

----

fire2 = 0

function hutF(hero, hut)
if GetCurrentPlayer() == 1 and fire2 == 0 then
sleep(1)
QuestionBox ( "/Maps/SingleMissions/NewRandomMap 43/burn1.txt" , 'burnok' , 'burnno');
sleep(1)
end
end

function burnok(hero, hut)
sleep(1)
BlockGame()
--burn hut effects
hutt = hutt + 1
Trigger(4, hut, nil)
UnblockGame()
end

function burnno(hero, hut)
sleep(1)
fire2 = 1
SetObjectEnabled(hut, true)
sleep(1)
MakeHeroInteractWithObject('Nymus' , hut)
sleep(1)
SetObjectEnabled(hut, nil)
fire2 = 0
end


Basically, what I'm most interested in is how to make the script read the name of the hut and use it in other functions. If I write it in parentheses after the function name, it somehow doesn't work.
You can ignore the variables; there aren't any functions that use them yet.
I tried using GameVar to output the hut, but it doesn't read it.
And when I put it in quotes, it stops recognizing the object altogether
User Avatar
12 years ago
Auto-translated
Save the hut in some global variable with a different name, for example, current_hut. In general, arguments are passed to functions as usual: function(list_of_arguments) or startThread(function, list_of_arguments) And, if you want to do MakeHeroInteractWithObject, you also need to disable the trigger. By the way, why so many hyphens between lines?
User Avatar
12 years ago
Auto-translated
SetGameVar ('hut2', hut)
---
hut3 = GetGameVar('hut2')
---
SetObjectEnabled('hut3', true)

Is this correct? (quotes and everything)

Added 55 seconds later
By the way, why so many hyphens between the lines?

It's necessary. I'm tired and starting to get confused, I can't tell one thing from another. That's why I put in line breaks and hyphens)))
User Avatar
12 years ago
Auto-translated
SetGameVar is a game-wide variable, not a global one. A global variable is one that is not local. In this script, the global variables will be burn, fires, burn2, hutt, fire2, hutF, burnok, burnno.
I need to. I'm tired and starting to get confused, I can't tell one from the other. That's why I'm putting in line breaks and minuses.
Try putting a tab at the beginning of each subsequent level (after the words function ..., do, then, and after a new line).
User Avatar
12 years ago
Auto-translated
How do I upgrade a hut to a global building?
User Avatar
12 years ago
Auto-translated
It is global by default.
User Avatar
12 years ago
Auto-translated
aaa.

Okay.

So, why isn't it working then?))
User Avatar
12 years ago
Auto-translated
Also, `startThread(burn2)` should be written inside the loop.
In reply to RedHeavenHero
User Avatar
12 years ago
Auto-translated
RedHeavenHero
Also: startThread(burn2) should be written inside the loop.

Yeah, I missed that. I'll fix it.

Added 6 minutes later
Still don't understand why it doesn't work. Since the function is global, does that mean quotes aren't needed? But even so, 'enabled' isn't being set.
User Avatar
12 years ago
Auto-translated
I'll take a look now, analyze it, and post my version of the script. Okay?
User Avatar
12 years ago
Auto-translated
I would be very grateful. If needed, I would like to create similar structures with archer towers, barracks, and a Haven outpost.
In reply to Heroist
User Avatar
12 years ago
Auto-translated
For now, this is how it is. If there are any errors, let me know, and we will fix them. ;) ``` HAVEN_DWLS = {} hutt = 0 function burn() for i, dw_type in {"PEASANT_HUT", "ARCHERS_HOUSE", "BARRACKS", "HEAVEN_MILITARY_POST"} do for j, dw in GetObjectNamesByType(dw_type) do HAVEN_DWLS[dw] = "откл" SetObjectEnabled(dw, nil) Trigger(4, dw, "BurnHavenDwelling") end end startThread(burn2) end startThread(burn) function burn2() while 1 do repeat sleep() until IsPlayerCurrent(1) for dwelling, state in HAVEN_DWLS do if state == "вкл" then HAVEN_DWLS[dwelling] = "откл" SetObjectEnabled(dwelling, nil) Trigger(4, dwelling, "BurnHavenDwelling") end end repeat sleep() until not IsPlayerCurrent(1) for dwelling, state in HAVEN_DWLS do if state == "откл" then HAVEN_DWLS[dwelling] = "вкл" SetObjectEnabled(dwelling, 1) Trigger(4, dwelling, nil) end end end end function BurnHavenDwelling(hero, hut) if GetCurrentPlayer() == 1 then QuestionBox ( "/Maps/SingleMissions/NewRandomMap 43/burn1.txt" , 'burnok("'..hut..'")' , 'burnno("'..hut..'")'); end end function burnok(hut) Trigger(4, hut, nil) hutt = hutt + 1 HAVEN_DWLS[hut] = nil end function burnno(hut) SetObjectEnabled(hut, 1) Trigger(4, hut, nil) sleep(1) MakeHeroInteractWithObject('Nymus' , hut) sleep(1) SetObjectEnabled(hut, nil) Trigger(4, hut, "BurnHavenDwelling") end
User Avatar
12 years ago
Auto-translated
and what should be displayed in place of "on" and "off"?

Statistics

Welcome our newest member: recijeb