If italy joins CP, then Spain joins Entente.

A forum to discuss custom scenarios, campaigns and modding in general.

Moderators: Slitherine Core, The Lordz

Post Reply
Kossatx
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 132
Joined: Wed Nov 27, 2013 3:27 pm

If italy joins CP, then Spain joins Entente.

Post by Kossatx » Sun May 05, 2019 9:34 pm

Hi, I would like to script if Italy joins CP then Spain joins Entente. I think it would be something like this, but I'm not sure if it's wrong and even if only must be written in game_events.lua file. Any suggestion?

Code: Select all

if italy.alliance.id == 2 then 
ChangeFactionAlignment(game:GetFactionById(15), spain.alliance,  - math.random(35,45)
end

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1219
Joined: Tue Nov 23, 2010 3:35 pm

Re: If italy joins CP, then Spain joins Entente.

Post by Robotron » Sun May 05, 2019 9:50 pm

Just enter your code into

function TriggerTurnEvents()

in game_events.lua

at any line and make sure you define factions Italy and Spain beforehand using the usual method:

local italy = game:GetFactionById(8)
local spain = game:GetFactionById(15)

and remove the "-" (minus) so it reads

Code: Select all

local italy = game:GetFactionById(8)
local spain = game:GetFactionById(15)

if italy.alliance.id == 2 then 
	ChangeFactionAlignment(game:GetFactionById(15), spain.alliance,   math.random(35,45)
end
For factions to join Entente the modifier must be positive, for CP negative.

Your code would have let Spain join CP which, in my opinion, would be more realistic anyway. Spain was militarily backwards then and would rather (if at all) fight an Entente without Italy than CP reinforced by Italy.
Slitherine's Commander the Great War on steroids: POTZBLITZ mod!
http://www.slitherine.com/forum/viewtopic.php?f=218&t=77884&p=662610#p662610

Kossatx
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 132
Joined: Wed Nov 27, 2013 3:27 pm

Re: If italy joins CP, then Spain joins Entente.

Post by Kossatx » Mon May 06, 2019 9:13 am

Thanks a lot Robotron! Your point of view about spanish alliances is interesting, but I've read most generals and politicians were pro-ententente, including Alfonso XIII. The only plans I know about an hypothetical spanish participation in WWI were naval activities against Italian navy in the Mediterranian and a franco-spanish invasion of Sardinia. These plans were aproved by Alfonso XIII, but obviously never were implemented. Anyway, I like your suggestion so I'll include in the script a dice roll: if the roll is between 1 and 4 Spain will align towards Entente, if is between 5 or 6 it will align towards CP :D

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1219
Joined: Tue Nov 23, 2010 3:35 pm

Re: If italy joins CP, then Spain joins Entente.

Post by Robotron » Mon May 06, 2019 2:21 pm

Note that the alignment change by the script will take place at the beginning of each turn.

Because the modifier value is set to a range of between 35 to 45 Spain would join Entente 2 turns after Italy has joined CP.
Slitherine's Commander the Great War on steroids: POTZBLITZ mod!
http://www.slitherine.com/forum/viewtopic.php?f=218&t=77884&p=662610#p662610

Kossatx
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 132
Joined: Wed Nov 27, 2013 3:27 pm

Re: If italy joins CP, then Spain joins Entente.

Post by Kossatx » Mon May 06, 2019 2:26 pm

Robotron wrote:
Mon May 06, 2019 2:21 pm
Note that the alignment change by the script will take place at the beginning of each turn.

Because the modifier value is set to a range of between 35 to 45 Spain would join Entente 2 turns after Italy has joined CP.
Oh! If I want this script triggers only once, ¿is it possible?

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1219
Joined: Tue Nov 23, 2010 3:35 pm

Re: If italy joins CP, then Spain joins Entente.

Post by Robotron » Mon May 06, 2019 3:08 pm

Sure.

Code: Select all

local italy = game:GetFactionById(8)
local spain = game:GetFactionById(15)

if GetEvent("SpainJoinsCP") == 0 
	and italy.alliance.id == 2 then 
		ChangeFactionAlignment(game:GetFactionById(15), spain.alliance,   math.random(35,45))
		SetEvent("SpainJoinsCP", -1)
end
By doing this the script becomes a "pseudo"-event called "SpainJoinsCP", that is only triggered once and does not require a picture/headline and text.

Here's the same event with your D6-roll of 4 or lower to have Spain join Entente else join CP version:

Code: Select all

if GetEvent("SpainJoinsCP") == 0 
	and italy.alliance.id == 2 then 
	local luck = math.random(1,6)
	if luck <= 4 then	
		ChangeFactionAlignment(game:GetFactionById(15), spain.alliance,   math.random(35,45))
		SetEvent("SpainJoinsCP", -1)
	else
		ChangeFactionAlignment(game:GetFactionById(15), spain.alliance,  - math.random(35,45))
		SetEvent("SpainJoinsCP", -1)
	end	
end
Slitherine's Commander the Great War on steroids: POTZBLITZ mod!
http://www.slitherine.com/forum/viewtopic.php?f=218&t=77884&p=662610#p662610

Kossatx
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 132
Joined: Wed Nov 27, 2013 3:27 pm

Re: If italy joins CP, then Spain joins Entente.

Post by Kossatx » Mon May 06, 2019 3:32 pm

Thanks a lot again Robotron! :D

Kossatx
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 132
Joined: Wed Nov 27, 2013 3:27 pm

Re: If italy joins CP, then Spain joins Entente.

Post by Kossatx » Tue May 07, 2019 12:38 pm

The "pseudo-event" works fine :D

I'm sorry to be a bore Robotron, but If I'd like to make the "pseudo-event" become an event... what should I do? I think is necessary a picture with the event name, some text in language file... and something else?

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1219
Joined: Tue Nov 23, 2010 3:35 pm

Re: If italy joins CP, then Spain joins Entente.

Post by Robotron » Tue May 07, 2019 4:22 pm

You're not boring me at all.

Okay, so let's make an event called "BlahBlahBlah".

1. You'll need a PNG picture measured 414 x 348 (width x heigth) pixels. No other format than PNG will do!

2. Name this picture: event_BlahBlahBlah.png

3. Put the picture into folder: data/graphics/hud/events (where all the other event graphics are)

4. Open english.txt in folder: data/lang

5. In vanilla CTGW the event texts start at about line 800, you will have to define the event headline and the event text here.

6. every event needs a headline, the headline needs a certain syntax: event_???_title = ??? In our example the syntax would be: event_BLAHBLAHBLAH_title = THIS IS MY FIRST EVENT TITLE!

7. every event needs a text, the text needs a certain syntax: event_???_descr = ??? In our example the syntax can be: event_BLAHBLAHBLAH_descr = This is my first event text!

8. be VERY VERY cautious to get the syntax right or the game will not load anymore and crash without a proper error report!

9. especially if you insert a lot of new stuff into english.txt be sure to backup the file beforehand!

10. okay, now open game_events.lua and cut out the script part from where it is

11. instead insert a new event function call at the place where the script was before

The event function must have the same name like the event picture and the event reference in english.txt

In our case the function call would be titled: BlahBlahBlah()

12. Now scroll down to where all the other event function are and define the function using your script fragment

13. to define your function, type:

Code: Select all

function BlahBlahBlah()

local italy = game:GetFactionById(8)
local spain = game:GetFactionById(15)

	if GetEvent("BlahBlahBlah") == 0 
	and italy.alliance.id == 2 then 
			ChangeFactionAlignment(game:GetFactionById(15), spain.alliance,   math.random(35,45))
			SetEvent("BlahBlahBlah", game.turn)
	end
end

Notice that SetEvent now ends with game.turn and not with -1.
This means the game will now execute the display of the event picture and store the gameturn when the event happened.

Hope this helps.
Slitherine's Commander the Great War on steroids: POTZBLITZ mod!
http://www.slitherine.com/forum/viewtopic.php?f=218&t=77884&p=662610#p662610

Kossatx
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 132
Joined: Wed Nov 27, 2013 3:27 pm

Re: If italy joins CP, then Spain joins Entente.

Post by Kossatx » Tue May 07, 2019 4:54 pm

Great! That's all what I need :D

Post Reply

Return to “Commander the Great War : Mods & Scenario Design”