Events question...

CurtSibling

ENEMY ACE™
Joined
Aug 31, 2001
Messages
29,447
Location
Innsmouth
I want an event that rewards Soviet control of Maykop, and gives an extra 500 Gold per turn.
Just wondering if this would work, or if "continuous" is only relevant with flag events?

If there is a simple Lua method to the same thing, I am up for that also.

Code:
@IF
citytaken
continuous
city=Maykop
attacker=Soviet Union
defender=Anybody
@THEN
CHANGEMONEY
receiver=Soviet Union
amount=500
@ENDIF
 
Basically in lua what I'd do is set it up so that there was a flag for Soviet's controlling Maykop, and every turn (or increment, or whatever) that they had it, I'd give them 500.

I like to define my flags in the object file to try and keep things tidy (I'm already defining most everything else there) so I'd have:

flag.define("Maykop owned by Soviets", true)

I'd also make the $500 a parameter so that you don't have to go hunting through stuff later if you want to change this. This is an extremely big time-savings when it comes to tweaking scenarios in playtesting so I'd urge you or any other designer to use it. If you have some set of values that is going to be pretty consistent, or can be (for example, maybe you have "small, medium, large reinforcements") if you define it in one place, you can change 1000s of events to the new number by changing the parameters file instead of going through everything in the scenario. For example in Cold War, I use this concept for all my rebellions. As there are literally thousands of lines of code dealing with rebellions and insurrections, you can imagine the time savings if someone says "yeah these are too weak."

param.maykopBonus = 500

Then in the main events (probably onTurn but maybe afterProduction depending on if you want to shield the 500 from the Germans on city capture) I'd do something like this:

Code:
if turn >= 1 and flag.value("Maykop owned by Soviets") == true then
object.tSoviets.money = object.tSoviets.money + param.maykopBonus
end

turn >= 1 will have it happen every turn that this flag remains true.

Note that this assumes you're using the suggested naming conventions of the template with tSoviets but it could be tUSSR or whatever you chose.

Edit - just remember that you'll also need an event to set the flag as false if it is taken from the Soviets.

You could also have this bonus go to whomever happens to own maykop but I wouldn't use a flag there and I'd just check who owns the city each turn and give them 500.
 
I appreciate the post, dude - But can you outline clearly what files in the Lua template I'd be using?

With macro events (I'm using both Macro and Lua in this scenario) I just need merely write one event...
Lua is great, I'm convinced - :)
But in the choice between one simple event and an unclear system stretched over multiple files, I will choose the steamlined path.
 
I appreciate the post, dude - But can you outline clearly what files in the Lua template I'd be using?

With macro events (I'm using both Macro and Lua in this scenario) I just need merely write one event...
Lua is great, I'm convinced - :)
But in the choice between one simple event and an unclear system stretched over multiple files, I will choose the steamlined path.

You don't need to use flags for this event.

Choose either onTurn or afterProduction (or, I guess beforeProduction if you're using the latest template), and introduce the following code:

If using onTurn:
Code:
if object.cMaykop.owner == object.pSoviets then
        object.pSoviets.money = object.pSoviets.money + param.maykopMoneyBonus
end
if using afterProduction (or beforeProduction)
Code:
if object.cMaykop.owner == object.pSoviets and tribe == object.pSoviets then
        object.pSoviets.money = object.pSoviets.money + param.maykopMoneyBonus
end

There is no need to check the turn, unless you don't want the bonus to start until a specific turn (or, end on a specific turn).

Notes:
I used object.pSoviets instead of object.tSoviets, since my latest object builder changed the prefix from t (tribe) to p (player) to free up t for terrain. This is just cosmetic, so use whatever your object file is set to.

If it is possible for Maykop to be razed to the ground, make the following check with the location of Maykop instead:
Code:
if (object.lMaykopLoc.city and object.lMaykopLoc.city.owner == object.pSoviets) and tribe == object.pSoviets then
 
Thanks, guys.
If the macro events are a bust, I will definitely use these.
Either Lua option seems workable...OnTurn might be the way I go.

So when you mention "param.maykopMoneyBonus",
does that line go into the Parameter.Lua, in the Parameter folder? If not, can you indicate where?
 
So when you mention "param.maykopMoneyBonus",
does that line go into the Parameter.Lua, in the Parameter folder? If not, can you indicate where?

Yes, it would go in the parameters.lua file. Make sure that your onTurn or afterProduction file has the line
Code:
local param = require("parameters")

In the macro system, continuous only has meaning if there are 2 conditions, that is
Code:
@IF
A Event
@AND
B Event
@THEN
STUFF
If A event happens, then a the "A event Happened flag" is set to true. If B Event happens, and the "A event happened flag" is already true, then the STUFF happens. Similarly, when B Event happens, a "B event happened flag" is set to true, and is checked whenever A event happens. At the end of the turn (actually, I think after the flag event of the next turn), these flags are set to false. Continuous means that the corresponding event happened flag is not set to false at the beginning of the next turn.

I think to achieve what you want in the macro system, you would have to give 500 gold to the soviets each turn, and then use something like
Code:
@IF 
Germans capture Maykop
continuous
@AND
turn interval every turn
@THEN
take 500 gold from soviets
to take it away after the Germans capture Maykop.

In order to restore the bonus when the city is recaptured, you'd have to have the above event for the soviets and give them 500, I think.

I don't know the ins and outs of exactly what can be achieved with the macro system. I knew a bit more a couple years ago when I wrote the legacy event engine, but I wasn't focusing on weird combinations.

FYI, there is functionality:
Code:
turnsSinceCapture (get/set)
city.turnsSinceCapture -> integer

Returns the number of turns since the city was last captured.
in case you want to make it so that it takes a couple turns after city re-capture for the oil bonus to start flowing again.
 
Curt I'd just abandon macro... you're deep enough into this and are coming along nicely. Cut the cord :)
 
@JPetroski

I'd love to switch over to Lua totally, but sometimes the system is too arcane and complex even when doing simple things.
When trying to create a simple spawning of units based on a tech dsicovery, I couldn't get a solid answer on what to do.

As I said before, I'm an artist, not a code guy.

I'll try and implement as much events to Lua as I can (that is the point of this exercise) but with a lack of up to date tuturorials, and
most experts already busy with their own projects, I must use what methods work to get the scenario complete.
 
Curt I'd just abandon macro... you're deep enough into this and are coming along nicely. Cut the cord :)
Really? I guess I don't quite agree. Actually I think that the legacy events engine might be the coolest thing that @Prof. Garfield has done -- meaning no disrespect to his other work of course! Having a "bridge" that allows long-time designers to expand upon what they know, without starting over, is really valuable. I think @CurtSibling is the classic example of someone who should leverage that as much as possible. Since he knows the macro language very well, and Lua hardly at all, use macro as much as possible! Go right ahead -- what is the downside of that, exactly? Seems to me that will make his scenario development proceed at a much better pace. Then use Lua to add in events that macro cannot support. But he can dip his toe in those waters little by little and gradually get more comfortable with it, instead of facing down the daunting task of writing an entire scenario's events in a language that (probably) feels pretty foreign.

At some point, though, I do agree with you. Once someone is comfortable with Lua (as you are, John) then splitting events between two systems starts to be more confusing and could actually slow that person down. And it's also true that any designer will start to dream up better events once they really get the feel for what Lua can do -- so getting nudged in that direction has long-term benefits. But I think we'll get more Lua adopters if we can show them a gradual path instead of "all or nothing".

@techumseh Yes it's one or the other in the literal sense -- as far as TOT is concerned. But what Prof. Garfield has written is a parser that can read in a macro events file, and then run it using Lua. So TOT thinks it's running pure Lua events, but macro events (that are written correctly) will still work, without being rewritten from scratch.
 
Last edited:
Wait. I thought you couldn't combine the two. Isn't it one or the other?

Hi, dude. Thanks to ProfG, Lua and Macro seem to work quite fine alongside each other.

The Imperialism update scenario used Lua/Marco events. Macro for text events and barb spawns/attacks, and Lua
for cool stuff like workers being handed to the attacker instead of killed, and dangerous terrain that hurts normal units.

I can only imagine what a master scenario maker like yourself could do with Lua...
 
Last edited:
Really? I guess I don't quite agree. Actually I think that the legacy events engine might be the coolest thing that @Prof. Garfield has done -- meaning no disrespect to his other work of course! Having a "bridge" that allows long-time designers to expand upon what they know, without starting over, is really valuable. I think @CurtSibling is the classic example of someone who should leverage that as much as possible. Since he knows the macro language very well, and Lua hardly at all, use macro as much as possible! Go right ahead -- what is the downside of that, exactly? Seems to me that will make his scenario development proceed at a much better pace. Then use Lua to add in events that macro cannot support. But he can dip his toe in those waters little by little and gradually get more comfortable with it, instead of facing down the daunting task of writing an entire event's scenarios in a language that (probably) feels pretty foreign.

At some point, though, I do agree with you. Once someone is comfortable with Lua (as you are, John) then splitting events between two systems starts to be more confusing and could actually slow that person down. And it's also true that any designer will start to dream up better events once they really get the feel for what Lua can do -- so getting nudged in that direction has long-term benefits. But I think we'll get more Lua adopters if we can show them a gradual path instead of "all or nothing".

100%, good sir, 100%.

I firmly believe Lua is one of the best things to happen in CIV2. And it brought my love for modding back to life. I am even remaking my biggest scenario from the ground up,
just to take advantage of the features in Lua, that cannot be done with Macro. The legacy hybrid from ProfG is indeed a breakthrough. I will become more ambitious with Lua,
once my confidence increases. It saves so much time with unwieldly events like "gold for unitkilled", while specific text-heavy events I feel are suitable for Macro.

I am just grateful to be able to use both systems in the one scenario...We designers are spoiled for amazing tools!
 
I can only write for myself but I'm not in the mood writing Macro events anymore since I realized, what's possible with LUA. AWI is a kind of hybrid scenario, where I used both languages, but 1517 will be a 100% LUA scenario as it is a scenario from scratch. For AWI I had a lot events written in Macro before.

But honestly, without the patience and help of our LUA experts here onboard I would never use LUA. I was a complete noob before and had no experience in programming, so I'm very thankfull for your support. I agree, at the beginning LUA is much more difficult than Macro but if you understand the basics more and more it works little by little better and easier. At least I'm able to write events for basics like text events, city conquering, technology discovering. For me that's very much.

I understand if designers will use both languages, regardless of how much experiences they have in LUA. Especially in an existing scenario it makes more sense using both languages than writing everything in LUA again. With the legacy events engine everything works fine and you can combine both languages.

But if you designing a complete new scenario from scratch I would go to 100% LUA.
 
@civ2units That's fair. I think once designers see what Lua can do, and start to get comfortable with it, that goal of doing a new project 100% in Lua is going to be pretty typical. I'm all in favor of that! I just don't want someone who wants to use a hybrid system to feel that it's not going to be successful. Upgrading an older scenario that already has working macro events is certainly the best example. I'm just trying to make Lua seem more appealing, and less intimidating, by highlighting the fact that someone who's familiar with macro can adopt Lua gradually or jump in all at once -- they have the option of picking what they'd prefer.
 
Really? I guess I don't quite agree.

I mean I wasn't really looking for a debate so much as just pointing out that Curt seems to be grasping this quickly enough that I don't think he needs the macro events and might as well jump in. He can do whatever he's comfy with though. It doesn't matter to me.

I will say however that as a former smoker, I'm going to make a comparison some of you aren't going to like (especially if you're current smokers).

When people say they "quit smoking" but are still chewing gum or on a patch, they really haven't quit anything. It's the nicotine they're addicted to. There is only one way to quit; it is cold turkey. Until the moment passes that they are no longer putting nicotine in their body, they are still addicted to it. Chewing gum or patches just prolongs the time it takes them to quit and master their demon. Macro vs. lua (or anything new vs. old) isn't that different, IMO.

I don't really care what anyone does or doesn't do (it makes no difference to me), but the template is a great short cut for converting works that are already built or halfway built. It prevents you from having to do however much work over. Some of these old scenarios or half-built scenarios are giants. Why recreate the wheel, I get it. But, if you're starting from scratch, you aren't doing yourself any favors by using the converter for a new project.

You all do whatever you want to do but "them's the chips" on this matter, I'm afraid :) every line you write in macro is one less you're learning in lua and people are here to help you with the latter now. You can't count on that always being the case. Better for us all to learn as fast as we can, IMO.

Or don't. It's up to each of you!
 
It's less like giving up smoking - And more like learning mechanics with the choice of either an automobile, or the engine of a F-35 fighter jet.
Aspects that are elementary to pro-level Lua users seem like pure wizardry to apprentice users like me. I am still unsure how to make simple Lua events work.

This might be a good time to raise the point that some new Lua tutorials that cover some events basics would be of massive use to newbs.
I know there are the excellent series of tutorials on the forum, but much of it needs to be brought up to 2021 standards.

If we had some Lua lessons to study: Like how to create a city capture event with text,
or a unit spawn event with text, it would enable me (and others) to push forward.

We want to learn, but we need guidance. Enshrine your wisdom, Lua masters!
 
If we had some Lua lessons to study: Like how to create a city capture event with text,
or a unit spawn event with text, it would enable me (and others) to push forward.

Have you looked at Boudicca yet? It was built specifically to give an example that could be copied, pasted, and modified? I will say a big part of the problem with learning this is that there is so much out there that is different. Just look at how Garfield and I completely differently answered your question. Both answers work. His is probably the better way to do it. There's a number of different ways to achieve any desired result with this stuff that makes it overwhelming, especially when you consider that:

1. Caesar
2. Napoleon
3. Over the Reich
4. Cold War
5. American War for Independence
6. Medieval Millennium

ALL use different methods. Hence the template was constructed to try and end this.

I'm really at the point where I think maybe I should make Hinge of Fate a public build as opposed to quiet side job just so folks can see a giant scenario built within the confines of the template. Would that be helpful?
 
I think the 'addiction' comparison is quite insulting, frankly. At this stage of my life, I'm very torn about trying to learn what's essentially a new language. I love what Lua can do, but I'm not sure I really want to invest the time and energy to learn it. So that really means giving up scenario making, since I'm not willing to be a relic of an obsolete system, as were a couple of designers that insisted on hanging on to MGE. Maybe it's time to find another hobby. The thing about people who quit smoking, is that they can be a little sanctimonious.
 
I mean I wasn't really looking for a debate so much as just pointing out that Curt seems to be grasping this quickly enough that I don't think he needs the macro events and might as well jump in.
@JPetroski I certainly didn't mean to be argumentative -- no hard feelings I trust. Your original post was clearly intended to be complimentary and encouraging to Curt, I didn't mean to overlook that.

Also, I certainly don't want to be cast in the role of defending the macro language! That would be pretty funny considering that I've never even written a single working event in it. I will agree, without reservation, that Lua is ultimately superior as an events language, and I hope all designers adopt it eventually. But some people -- apparently Techumseh is an example -- may not be aware that they have options for how (and how quickly) they get there.

Things like nicotine gum and the patch exist because, at least for some people, quitting cold turkey Just. Doesn't. Work. For anyone who wants to make a change in their behavior (and that's important: the person has to want to make a change), I will stand by the perspective that "take it at your own pace" is superior to "get intimidated/discouraged and give up." For some people, jumping in with both feet is the pace that works. For others, if they think that's their only option, they'll never do it at all.

Have you looked at Boudicca yet? It was built specifically to give an example that could be copied, pasted, and modified? I will say a big part of the problem with learning this is that there is so much out there that is different. Just look at how Garfield and I completely differently answered your question. Both answers work. His is probably the better way to do it. There's a number of different ways to achieve any desired result with this stuff that makes it overwhelming, especially when you consider that:

1. Caesar
2. Napoleon
3. Over the Reich
4. Cold War
5. American War for Independence
6. Medieval Millennium

ALL use different methods. Hence the template was constructed to try and end this.
Just to speak to the two projects there with which I had significant involvement: Napoleon's events were written in Lua really without much of a framework at all, as I was learning the language. If I was going to do that scenario again now, I would write it differently, with a more modular approach instead of putting all the code in a single file. But for a first project, I'm satisfied with how successful it turned out to be. Tootall_2012 (as the overall project designer) was able to grasp the structure well enough to make many additions and enhancements on his own in the later point releases.

Medieval Millennium has its own framework that was basically developed concurrently with Prof. Garfield's work on the Lua Scenario Template. However, I wrote its framework with the goal of making my own Lua event-writing as efficient as possible. So in that sense it's a framework for people who are pretty comfortable with Lua, and it probably isn't going to be very successful as an introduction to events in that language.

It certainly feels to me like the most overwhelming aspect of the Lua Scenario Template is the sheer number of files, and figuring out the right (or best?) place to put code. If that template is intended to be the starting point for designers who are new to Lua -- and that certainly seems like a praiseworthy goal -- anything that can be done to simplify it and lower the "barrier to entry" would be extremely useful. Perhaps Boudicca needs a higher profile and more promotion as the template to copy. Perhaps a single overview Readme.txt explaining how each of the files in the template is intended to be used (with examples) would be helpful. But please understand I'm not throwing stones. What's there is great, and I'm only offering encouragement and suggestions that might help it reach a broader audience.

@techumseh It would certainly be a shame if you gave up on scenario-making. I really don't think TheNamelessOne intended to create a divide in the community by adding support for Lua, where only a privileged few move on to the new Elysian Fields. If you don't want to learn Lua, that's your right, and it doesn't mean that scenarios without Lua are "relics". But if you are at least a little bit interested, my point is that you can dip your toe in the waters only as much as you want, without starting over. And as John and Curt and others have pointed out, there are multiple people around in the forums right now who are glad to help you, so now is a great time to give it a try.
 
Last edited:
Top Bottom