Quick Modding Questions Thread

Awesome. Probably just what I need 🙂
Thanks!
One question about it: Does it mute other sounds or will the game keep playing the alerts normally (unit trained, building constructed, hostile units marching nearby, etc)?

Is there a similar thing to play a video perhaps?
 
Last edited:
Awesome. Probably just what I need 🙂
Thanks!
One question about it: Does it mute other sounds or will the game keep playing the alerts normally (unit trained, building constructed, hostile units marching nearby, etc)?
Other sounds should continue to play normally. It behaves in the same way the normal background music does - all the function does is override the automatic track selection.
Is there a similar thing to play a video perhaps?
I half remember that there is a way to do this by launching a popup with a specific keyword in the message body. I don't have the code on hand to look it up right now though.
 
I hope to fulfill a longtime dream with that function: custom playlist for different Civs in different eras in different situations.

Is there a function to check if a certain folder or file exists inside my mod?
The idea is to have a 0th checking whether my MoreMusic add-on is installed to the mod or not.


Than I will also need to know what are the functions to check if human player's...
1. Civ is X
2. Era is Y
3. Civ is in a Golden Age OR
4. Civ is in Anarchy OR
5. Civ is at war (with anyone) OR
6. Civ is at war with no one (but it's probably enough to use a final ELSE here)
 
I hope to fulfill a longtime dream with that function: custom playlist for different Civs in different eras in different situations.

Is there a function to check if a certain folder or file exists inside my mod?
The idea is to have a 0th checking whether my MoreMusic add-on is installed to the mod or not.
This is probably possible, but I would recommend:
1. In GlobalDefines.xml add a new value and set it to 0
2. In your module, set the same value to 1
3. Use CyGlobalContext().getDefineINT(<define tag>) to check if the module exists
Than I will also need to know what are the functions to check if human player's...
1. Civ is X
2. Era is Y
3. Civ is in a Golden Age OR
4. Civ is in Anarchy OR
5. Civ is at war (with anyone) OR
6. Civ is at war with no one (but it's probably enough to use a final ELSE here)
Code:
gc = CyGlobalContext()
iHumanPlayer = gc.getGame().getActivePlayer()

gc.getPlayer(iHumanPlayer).getCivilizationType()  # human civ
gc.getPlayer(iHumanPlayer).getCurrentEra()  # human era
gc.getPlayer(iHumanPlayer).isGoldenAge()  # player golden age
gc.getPlayer(iHumanPlayer).isAnarchy()  # player anarchy

gc.getTeam(gc.getPlayer(iHumanPlayer).getTeam()).isAtWar(<other team>)  # loop through for war/peace

I don't know if DLL changes are an option for you, but if so, also check out this method in my mod (and further look where it's used). Since playlists are tied to eras by the game, the idea is to determine the "soundtrack era" of a civilization that is completely independent of its actual era and is only used to determine its current playlist. I have added a few dummy eras that you cannot enter normally to store specific playlists. In my mod I am using this to play religion specific playlists, but it could easily be expanded for what you have in mind.

That would save you the trouble of micromanaging the currently playing track in Python - one challenge with your idea that I see is that afaict there is no way to queue up music and you have no way of knowing when a piece ends and a new one needs to be triggered. The built in playlist would manage this for you.


Regarding what I said above regarding playing movies - unfortunately it was not about playing an arbitrary movie. You can only force the game to play the wonder movie associated with a wonder this way.
 
one challenge with your idea that I see is that afaict there is no way to queue up music and you have no way of knowing when a piece ends and a new one needs to be triggered. The built in playlist would manage this for you.
Oh... Are you sure we cannot put CyInterface.DoSoundtrack one after another thus making a list? :confused:

Regarding what I said above regarding playing movies - unfortunately it was not about playing an arbitrary movie. You can only force the game to play the wonder movie associated with a wonder this way.
Oh, what a pity 😒
But great thanks for checking it, anyway :thumbsup:
 
Oh... Are you sure we cannot put CyInterface.DoSoundtrack one after another thus making a list? :confused:
Unfortunately not, if you call the method twice it will stop the first track and immediately play the second track. It's very much a "I want this to happen now" kind of interaction.
 
Unfortunately not, if you call the method twice it will stop the first track and immediately play the second track. It's very much a "I want this to happen now" kind of interaction.
I was afraid of that 😒

What about delaying the second track? There has to a function that says "wait X seconds", right? I understand that it would be a tedious work to manually set up each and every track's entry but i would be okay with that as long as I can achieve my goal.
 
I asked ChatGPT to write me a code:
Write a code with 4 elements:

Execute CyInterface().DoSoundtrack("AS2D_VICTORY1") than wait 36 seconds.
Execute CyInterface().DoSoundtrack("AS2D_VICTORY2) than wait 28 seconds.
Execute CyInterface().DoSoundtrack("AS2D_VICTORY3") than wait 93 seconds.
Execute CyInterface().DoSoundtrack("AS2D_VICTORY4") than wait 45 seconds.
Execute the above 4 elements in random order

Code:
import random
import time

# Function definitions
def play_and_wait(soundtrack, wait_time):
    print(f"Executing CyInterface().DoSoundtrack('{soundtrack}')...")
    # Replace the following line with actual code to execute CyInterface().DoSoundtrack()
    print(f"Playing {soundtrack}...")
    time.sleep(wait_time)
    print(f"Waited for {wait_time} seconds.")

# List of tasks
tasks = [
    ("AS2D_VICTORY1", 36),
    ("AS2D_VICTORY2", 28),
    ("AS2D_VICTORY3", 93),
    ("AS2D_VICTORY4", 45)
]

# Shuffle the tasks
random.shuffle(tasks)

# Execute the tasks in random order
for task in tasks:
    play_and_wait(task[0], task[1])

Is that doable? Is that a good start?
 
As a professional software developer this sentence hurt my soul.
I imagine how painters feel...
:rolleyes::lol:

I know it cannot write everything for me but I hope it can help in learning a few things. And at least I don't have to you guys about EVERYTHING.
 
Is that doable? Is that a good start?
If your goal is learning, I would not recommend this approach.

I would recommend starting with the most simple version of what you are aiming for, and then implementing it yourself. You will learn more by going step by step and seeing what works and what does not.

A readymade boilerplate from generative AI does not help you with that at all.
 
Yes, I understand that in order to learn I need to go step by step, though I'm not sure if I will have the patience/time/capacity for that.
But I'm curious: is the code that the AI can provide usable or is it gibberish? I mean the general Python/C++ codes, cause I know that it has no access to modding specific stuff - maybe unless that stuff is published and well discussed on the net already.
 
I mean the general Python/C++ codes, cause I know that it has no access to modding specific stuff - maybe unless that stuff is published and well discussed on the net already
I tried Github Copilot and the results are mixed.

Sometimes it produces good usable code and sometimes it's completely off. Error checking is mandatory with these tools.

Some mods are hosted on github which makes it likely that Civ4 related code was included in the training process for the models.
 
Yes, I understand that in order to learn I need to go step by step, though I'm not sure if I will have the patience/time/capacity for that.
But I'm curious: is the code that the AI can provide usable or is it gibberish? I mean the general Python/C++ codes, cause I know that it has no access to modding specific stuff - maybe unless that stuff is published and well discussed on the net already.
It's impossible to know without plugging it into the rest of the DLL and testing it. But I would advise you to consider the fact you have to ask that question.
 
The thing is; you cannot at all trust these generative models, and they will never admit or recognise that they are wrong. Even if you literally tell them 'hey, X is outdated syntax, use Y instead', it's still 50/50 whether they'll continue using X (or, initially switch to Y and then use X three prompts later).

You need to know how to refine your prompts, how to grab the usable parts and tweak the rest to something that actually works, and even be very alert for code that does fully work because who knows what kind of issues (ranging from inelegant implementations to memory leaks) you'll run into later on.

In other words; you need to be an experienced coder if you want to use these models.
 
Yeah, my plan was all along:
1. Ask AI to write to write me the code because I know very little about Python/C++ and the AI is available 24/7.
2. Come here to ask for "proof reading" :mischief:
So my question was meant to be: is ChatGPT somewhat good or not good at all :lol:
Thanks for all your answers 🙂
 
Yes, I understand that in order to learn I need to go step by step, though I'm not sure if I will have the patience/time/capacity for that.
It is kind of disrespectful to expect others to invest their time and patience to help you out with your questions for things you don't feel the need to put your own effort into yourself. If you don't care enough about your own work, why should we?

This is a repeated pattern you see again and again with this new generative AI culture where someone wants to be the "author" of generated AI output but the real work is foisted off on the people who actually understand the subject matter, who nevertheless get demoted to mere "proofreaders" anyway.

It's pretty low to even openly admit to it, but thanks for the honesty I guess.
 
It is kind of disrespectful to expect others to invest their time and patience to help you out with your questions for things you don't feel the need to put your own effort into yourself. If you don't care enough about your own work, why should we?
Sorry, I never meant to be disrespectful :(
I meant that I don't have the time, energy and patience to become skilled programmer as you guys.
Why I want to use AI generated stuff is that I don't want to ask "Hey, guys, can someone write me a code that..."
I know that I'll never become a real programmer but stay a merger. I like to look up codes already written and try to figure out how modify it to my needs; first on my own, than by asking for help from the community.
I don't want to discredit those who can do the real thing. Quite the other hand: I don't expect others to do things for me for free. That's why I was hoping that AI generated code may be a help for me, so I can try something, and when it doesn't work the experts can point out what's wrong or at least where to start.

And let me underline again: I am very thankful for all the help received here.
 
I tried Github Copilot and the results are mixed.
As far as I understand, Copilot is quite old - of course, by the standards of generative AI

<Nexus> The trick is that there are literally dozens of generative AI, so the experience gained with one neural network, to put it mildly, is not exhaustive. At the same time, the same Copilot is able to diagnose bugs, and the trial period there is kind of free.

And you will hear enough of the indignant screams of the coders.
 
I don't know if DLL changes are an option for you, but if so, also check out this method in my mod (and further look where it's used). Since playlists are tied to eras by the game, the idea is to determine the "soundtrack era" of a civilization that is completely independent of its actual era and is only used to determine its current playlist. I have added a few dummy eras that you cannot enter normally to store specific playlists. In my mod I am using this to play religion specific playlists, but it could easily be expanded for what you have in mind.
Is there a limit on how many eras can be there?

I already have 8 eras. If I want to have War and Peace versions it will go up to 15 (I wont split Ancient era).
And I'd like to have cultural groups too... So I would quickly end up having 150 to 210 era definitions :lol:

I'm still thinking and planning.
 
Back
Top Bottom