On disabling research, buildings and units in a script

Modding, Map Editor, IES Scripting and Other Questions
Sat42
Posts: 130
Joined: 03 Dec 2018, 18:01
Has thanked: 6 times
Been thanked: 1 time

On disabling research, buildings and units in a script

Post by Sat42 »

Dear all,

- CONTEXT -

Today is a great day (or was it yesterday when I ran a half marathon in 1h39min?) - I have managed to create my first test scenario with a working script providing special victory (and defeat) conditions and other special stuff :mrgreen:

But there remains a lot to do before I have a script containing all that I want for the REAL scenario I am working on. FYI, the test scenario takes place during Epoch II (Copper Age).

- OBJECTIVE -

To disable selected research, buildings and units at the initialization stage of the script.

- EXAMPLE -

Working example: SetTechEnabled(HUMAN_PLAYER, "Fortress", false);

- ISSUES -

-> Disabling buildings: I need to disable wonders, but SetTechEnabled(HUMAN_PLAYER, "Wonder", false); doesn't work

-> Disabling units: I need to disable units like the spearman BUT not the maceman, but SetTechEnabled(HUMAN_PLAYER, "Spearman", false); doesn't work
Note: SetTechEnabled(HUMAN_PLAYER, "Scout", false); does work

In general, where does one find the ID name of a generic unit / building for script work?

-> Disabling research of technologies: I found in a tutorial on scripting the following (slightly adapted for Epoch II)

Code: Select all

SetTechEnabled(HUMAN_PLAYER, "Military2_1", false);
SetTechEnabled(HUMAN_PLAYER, "Military2_2", false);
SetTechEnabled(HUMAN_PLAYER, "Military2_3", false);
SetTechEnabled(HUMAN_PLAYER, "Military2_4", false);
BUT it doesn't work! When I test my scenario I see I can still research those technologies. It does work, the corresponding icons remain greyed out (see post #5).
Note: SetTechEnabled(HUMAN_PLAYER, "Main3", false); does work (for preventing progress to next epoch).


As always, any help is much appreciated! :D
Last edited by Sat42 on 16 Nov 2020, 17:08, edited 1 time in total.

User avatar
Dr.MonaLisa
High Representative
Posts: 8707
Joined: 17 Jun 2010, 11:21
Location: Poland
Has thanked: 49 times
Been thanked: 108 times

Re: On disabling research, buildings and units in a script

Post by Dr.MonaLisa »

1. Was "HUMAN_PLAYER" defined? I don't remember but the first player is most likely 0 or 1. You could replace it to:

Code: Select all

SetTechEnabled(1, "Military2_1", false);
2. Those unit types technologies are most likely in: "zips\db_155.zip\db\TechTree\upgrade_unittype5.csv"
Maybe even "dbtechtreenod5.csv" in the same folder, for example I found:

Code: Select all

WonderWestern_01,text_wonder_WE_01_name,1,0,,,1,3,0,Citizen,WonderWestern_01,,900,500,500,500,0,0,0,0,0,0,0,Western,[],(None)
WonderWestern_06,text_wonder_WE_06_name,6,0,,,1,3,1,Citizen,WonderWestern_06,,900,500,500,500,0,0,0,0,0,0,0,Western,[],(None)
WonderWestern_11,text_wonder_WE_11_name,11,0,,,1,3,2,Citizen,WonderWestern_11,,900,500,500,500,0,0,0,0,0,0,0,Western,[],(None)
WonderMiddleEast_01,text_wonder_ME_01_name,1,0,,,1,3,0,Citizen,WonderMiddleEast_01,,900,500,500,500,0,0,0,0,0,0,0,MiddleEast,[],(None)
WonderMiddleEast_06,text_wonder_ME_06_name,6,0,,,1,3,1,Citizen,WonderMiddleEast_06,,900,500,500,500,0,0,0,0,0,0,0,MiddleEast,[],(None)
WonderMiddleEast_11,text_wonder_ME_11_name,11,0,,,1,3,2,Citizen,WonderMiddleEast_11,,900,500,500,500,0,0,0,0,0,0,0,MiddleEast,[],(None)
WonderFarEast_01,text_wonder_FE_01_name,1,0,,,1,3,0,Citizen,WonderFarEast_01,,900,500,500,500,0,0,0,0,0,0,0,FarEast,[],(None)
WonderFarEast_06,text_wonder_FE_06_name,6,0,,,1,3,1,Citizen,WonderFarEast_06,,900,500,500,500,0,0,0,0,0,0,0,FarEast,[],(None)
WonderFarEast_11,text_wonder_FE_11_name,11,0,,,1,3,2,Citizen,WonderFarEast_11,,900,500,500,500,0,0,0,0,0,0,0,FarEast,[],(None)
WonderMesoAmerican_01,text_wonder_AM_01_name,1,0,,,1,3,0,Citizen,WonderMesoAmerican_01,,900,500,500,500,0,0,0,0,0,0,0,MesoAmer,[],(None)
WonderMesoAmerican_06,text_wonder_AM_06_name,6,0,,,1,3,1,Citizen,WonderMesoAmerican_06,,900,500,500,500,0,0,0,0,0,0,0,MesoAmer,[],(None)
WonderMesoAmerican_11,text_wonder_AM_11_name,11,0,,,1,3,2,Citizen,WonderMesoAmerican_11,,900,500,500,500,0,0,0,0,0,0,0,MesoAmer,[],(None)
Best regards,
Dr.MonaLisa
Ministry of Game Affairs
Department of Control and Complains
Sat42
Posts: 130
Joined: 03 Dec 2018, 18:01
Has thanked: 6 times
Been thanked: 1 time

Re: On disabling research, buildings and units in a script

Post by Sat42 »

Thank you for the reply, Mona!

Following your help, here's an update to my situation:

- I have successfully disabled wonders! I can basically deal with any building now
- I have successfully disabled the training of spearmen! I can basically deal with any unit now

DISABLING TECH RESEARCH STILL DOES NOT WORK! dbtechtreenode.csv does say that technologies are named (e.g. for Epoch2) Economic2_1, Economic2_2, Economic2_3 etc. so the naming convention isn't the problem (and yes the script and testing in-game doesn't throw up any warnings), and yes since

Code: Select all

INITIALIZATION

HUMAN_PLAYER = 1;
I tried

Code: Select all

SetTechEnabled(1, "Military2_1", false);
and it doesn't work. Which didn't surprise me, since for example with buildings and units:

Code: Select all

SetTechEnabled(HUMAN_PLAYER, "Fortress", false);
SetTechEnabled(HUMAN_PLAYER, "Scout", false);
works so it should still be "HUMAN_PLAYER" and not just "1" when dealing with technologies.
Replacing "Economic2_1" with "EconomicEpoch2Slot1" leads to an error so that is not the solution.

I am testing all this with 1.5 Developers Version in case that changes anything (but I don't think it does). I think there's something obvious I am missing, but in any case it is less straightforward to disable tech research than it is to disable buildings or units that is for sure!
User avatar
Dr.MonaLisa
High Representative
Posts: 8707
Joined: 17 Jun 2010, 11:21
Location: Poland
Has thanked: 49 times
Been thanked: 108 times

Re: On disabling research, buildings and units in a script

Post by Dr.MonaLisa »

works so it should still be "HUMAN_PLAYER" and not just "1" when dealing with technologies.
HUMAN_PLAYER was defined earlier in the script code. It's basically 1.

In my World Simulator 2013 scenario: viewtopic.php?p=23816#p23816
I remember using a function that removed technologies points every X seconds... It could mean that I was unable to block technologies other way.
I wonder if disabling "Main2" would disable epoch-up? I also remember using "AwardTech" for auto-research at the fixed time.
Best regards,
Dr.MonaLisa
Ministry of Game Affairs
Department of Control and Complains
Sat42
Posts: 130
Joined: 03 Dec 2018, 18:01
Has thanked: 6 times
Been thanked: 1 time

Re: On disabling research, buildings and units in a script

Post by Sat42 »

Dr.MonaLisa wrote: 16 Nov 2020, 14:54
works so it should still be "HUMAN_PLAYER" and not just "1" when dealing with technologies.
HUMAN_PLAYER was defined earlier in the script code. It's basically 1.

In my World Simulator 2013 scenario: viewtopic.php?p=23816#p23816
I remember using a function that removed technologies points every X seconds... It could mean that I was unable to block technologies other way.
I wonder if disabling "Main2" would disable epoch-up? I also remember using "AwardTech" for auto-research at the fixed time.

Good point, maybe I should test replacing HUMAN_PLAYER with "1" in the cases where disabling works just to be sure it's all the same (just for future reference).

Thank you for your map example, at first it seemed to confirm what I suspected (direct disabling of tech is broken for some reason).

Just tested disabling "Main2"... while still having the player begin in Epoch II of course... and it didn't disable tech upgrades in Epoch II :P besides that...


Now it is time to admit my guilt and a REVELATION: you see, the disabled technologies are still visible in the Tech Tree when playing, BUT until just now I hadn't tested to see if I could actually research those technologies if I have the required tech points (and buildings): well I tested by giving the player tons of tech points to start with AND I cannot perform the disabled research!! The button for a disabled tech sorta works (it can still be clicked with the little sound confirming the click) but the research doesn't start, and the tech points are not spent - however the player has no way of knowing WHY it doesn't work and could interpret this as a bug.

So disabling tech research as shown above does work, but it's still not cool that a tech disabled in script looks like it should work in-game (icon still there) when in fact it doesn't (you can click as much as you like, the research won't start).

Maybe there's a way to disable the slot icons?

Added after 27 minutes 34 seconds:
A recapitulation on the technologies being disabled, since I am aware it is confusing:-

the following works:

Code: Select all

SetTechEnabled(HUMAN_PLAYER, "Military2_1", false);
but the corresponding tech button and icon remains, just greyed out even if you meet all the requirements (both in tech points and structures)

Also, preventing the player's progression to the next epoch with the following code does work, even if the player has 6 technologies researched in current epoch:

Code: Select all

SetTechEnabled(HUMAN_PLAYER, "Main3", false);
Hence, the only remaining issue is how to disable not just the researching of the technologies, but also their icons/buttons in the tech tree? This would help convey to the player exactly which technologies can actually be researched, instead of wondering why some tech remains greyed out even when meeting all the formal "default" requirements.

Worst case, I will just have to put a word in the briefing.

Added after 2 hours 4 minutes 6 seconds:
Another thing is - should one decide to have no research in the tech tree available - could it be possible to hide the Tech Tree button in the UI via scripting?
User avatar
Dr.MonaLisa
High Representative
Posts: 8707
Joined: 17 Jun 2010, 11:21
Location: Poland
Has thanked: 49 times
Been thanked: 108 times

Re: On disabling research, buildings and units in a script

Post by Dr.MonaLisa »

In my planes scenario, I've used the following "workaround" to disable Guarding button:

Code: Select all

AddWidgetListenForSelection("unit_action_guard", true);
RULE AntiGuard
if (bGuardlingLockaed && bAntiGuard && GetElapsedGameTime() > 3 && HasWidgetBeenSelected("unit_action_guard"))
  then AntiGuardAction
END_RULE
ACTION AntiGuardAction
SCRIPT WORLD
bAntiGuard = false;
STEP
CallNamedEventHandler("UIUnitCommand_Attack","");
RemoveWidgetListenForSelection("unit_action_guard");
PrintMessage("SYSTEM: Sorry, due to scenario OOS problems, guarding units has been disabled :(");
AddWidgetListenForSelection("unit_action_guard", true);
bAntiGuard = true;
END_SCRIPT
END_ACTION
Maybe it could be changed to react on the technology research click and print a message about it on chat?
In UP1.5, can get widgets names by using CTRL+O -> Input (Mouse) -> Click somewhere.
Best regards,
Dr.MonaLisa
Ministry of Game Affairs
Department of Control and Complains
Sat42
Posts: 130
Joined: 03 Dec 2018, 18:01
Has thanked: 6 times
Been thanked: 1 time

Re: On disabling research, buildings and units in a script

Post by Sat42 »

Dr.MonaLisa wrote: 16 Nov 2020, 18:20 In my planes scenario, I've used the following "workaround" to disable Guarding button:

Code: Select all

AddWidgetListenForSelection("unit_action_guard", true);
RULE AntiGuard
if (bGuardlingLockaed && bAntiGuard && GetElapsedGameTime() > 3 && HasWidgetBeenSelected("unit_action_guard"))
  then AntiGuardAction
END_RULE
ACTION AntiGuardAction
SCRIPT WORLD
bAntiGuard = false;
STEP
CallNamedEventHandler("UIUnitCommand_Attack","");
RemoveWidgetListenForSelection("unit_action_guard");
PrintMessage("SYSTEM: Sorry, due to scenario OOS problems, guarding units has been disabled :(");
AddWidgetListenForSelection("unit_action_guard", true);
bAntiGuard = true;
END_SCRIPT
END_ACTION
Maybe it could be changed to react on the technology research click and print a message about it on chat?
In UP1.5, can get widgets names by using CTRL+O -> Input (Mouse) -> Click somewhere.
That is interesting, a potential idea yes - thank you!
Sat42
Posts: 130
Joined: 03 Dec 2018, 18:01
Has thanked: 6 times
Been thanked: 1 time

Re: On disabling research, buildings and units in a script

Post by Sat42 »

Dr.MonaLisa wrote: 16 Nov 2020, 14:54
works so it should still be "HUMAN_PLAYER" and not just "1" when dealing with technologies.
HUMAN_PLAYER was defined earlier in the script code. It's basically 1.

In my World Simulator 2013 scenario: viewtopic.php?p=23816#p23816
(...) I also remember using "AwardTech" for auto-research at the fixed time.
Hey Mona, I had a quick look at this script, and yes at the initialization phase you would disable a whole bunch of tech like for example "SetTechEnabled(2, "Military13_1", false);" and then you would have a oneshot rule and action that after some time (10 * 60; I guess that is 10 minutes playtime?) results in "SetTechEnabled(2, "Military13_1", true);" followed by "AwardTech(2, "Military13_1");" so as to gift a technology to a player.

I suppose that means I can use "AwardTech" at the initialization phase to "get the player ahead" in his/her current epoch? So the tech is already researched at start of game?
User avatar
Dr.MonaLisa
High Representative
Posts: 8707
Joined: 17 Jun 2010, 11:21
Location: Poland
Has thanked: 49 times
Been thanked: 108 times

Re: On disabling research, buildings and units in a script

Post by Dr.MonaLisa »

Do you mean awarding techs from further epochs? I'm not sure what would be the result. It needs to be tested, for example using a spy in epoch 1, awarding the "Sabotage" ability technology from further epochs and seeing if it becomes available for the spy in epoch 1.

The auto technologies exploring functions are available in my world simulator scenario, you can search for:

Code: Select all

PrintMessageFromPlayer( "Scientists have explored a new technology:", 8 );
To copy over.
Best regards,
Dr.MonaLisa
Ministry of Game Affairs
Department of Control and Complains
Sat42
Posts: 130
Joined: 03 Dec 2018, 18:01
Has thanked: 6 times
Been thanked: 1 time

Re: On disabling research, buildings and units in a script

Post by Sat42 »

Hey thanks as usual for taking the time to help :)

So actually no I wasn't thinking of awarding tech from further epochs but I will make sure to test that at some point! It could come in useful for another scenario...

Meanwhile thanks to your script I did successfully test an awarding of tech, both in-game and at the initialization stage.

Here is my aim now: player 1 starts in Epoch X, and needs to get to Epoch X+1 because reasons - however, though player 1 starts in Epoch X, player 1 starts the game with most technologies from Epoch X already researched (using AwardTech at the initialization stage).

Here is my problem: because most technologies from Epoch X are awarded from start of game, player 1 gets a crown or two! But I don't want the player to receive a crown from the start of the game...

Is it possible to prevent the game from auto awarding a crown just because I am auto awarding all the tech from a research category at the initialization stage?

P.S. I already have the following:

Code: Select all

SetAllowLeaderForCrown(1, kCrownType_Military, false);
SetAllowLeaderForCrown(1, kCrownType_Imperial, false);
SetAllowLeaderForCrown(1, kCrownType_Economic, false);
and I can confirm it works! Mind you I don't mind having the crowns system (so long as it doesn't give leaders) in general, I just don't want it to kick in when auto awarding tech at the start of the game.

Added after 3 hours 5 minutes 8 seconds:
OK so while I await a (better, hopefully working) answer, meanwhile I thought this might help:

Code: Select all

void AdjustPlayerCrownScore(1, kCrownType_Economic, -100)
// subtract a number to the player's score for a particular crown.
I could do that after each "AwardTech" in the initialization section (sequentially), so that player 1 can never reach enough Crown points to get the crown even though player 1 gets awarded all the related technologies at start of game.

Doesn't seem elegant though.
Post Reply

Return to “Questions”