Page 4 of 5 FirstFirst 12345 LastLast
Results 61 to 80 of 105

Thread: The S2 Script-o-Rama

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Thorn's Avatar Artifex
    Join Date
    Jan 2005
    Location
    Here
    Posts
    2,194

    Default Re: The S2 Script-o-Rama

    Uhm.. anyone knows how to access to Daimyo Honour?? I would like to add some events about it...

  2. #2

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    Uhm.. anyone knows how to access to Daimyo Honour?? I would like to add some events about it...
    If you can access it via an effect (see the effects tables) then you can play with it by adding character traits.
    My Tools, Tutorials and Resources

    Was running out of space, so see the full list here!

    Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings
    The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell

  3. #3
    Thorn's Avatar Artifex
    Join Date
    Jan 2005
    Location
    Here
    Posts
    2,194

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by T.C. View Post
    If you can access it via an effect (see the effects tables) then you can play with it by adding character traits.
    I was thinking about creating events based on Daimyo's Honour so being Honorable or not would have diferent effects.

    Thanks for the tip.

  4. #4
    Thorn's Avatar Artifex
    Join Date
    Jan 2005
    Location
    Here
    Posts
    2,194

    Default Re: The S2 Script-o-Rama

    Another thing It would be posible to use grant unit outside a dilemma??

    I have been trying something like grant_unit (#capital, "inf_yari_samurai_ronin") to add some units to the AI without success..

  5. #5
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

    Default Re: The S2 Script-o-Rama

    Use 'create_force'.

    I don't know the exact syntax right now, but thats the one to create any kind of army at any co-ords.

  6. #6
    Thorn's Avatar Artifex
    Join Date
    Jan 2005
    Location
    Here
    Posts
    2,194

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by .Mitch. View Post
    Use 'create_force'.

    I don't know the exact syntax right now, but thats the one to create any kind of army at any co-ords.
    Yep.. I was trying to avoid that function because I don't know which coordinates would be needed any time..
    allowing us to spawn units at capitols reomoves that restriction making things easier..

  7. #7

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    Yep.. I was trying to avoid that function because I don't know which coordinates would be needed any time..
    allowing us to spawn units at capitols reomoves that restriction making things easier..
    In the patch 5 pack (or data.pack)'s script you can find how the AI spawn units around campaigns, where the coordinate is given in the script as well. Each point is the size of a single "banner" on the map, so it shouldn't be too difficult for you to pop in a field army if you want to have one. Though I'm not sure what happens if you spawn a force right next to an opponent and whether or not that little yellow zone thing would apply.

  8. #8
    Thorn's Avatar Artifex
    Join Date
    Jan 2005
    Location
    Here
    Posts
    2,194

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Ying, Duke of Qin View Post
    In the patch 5 pack (or data.pack)'s script you can find how the AI spawn units around campaigns, where the coordinate is given in the script as well. Each point is the size of a single "banner" on the map, so it shouldn't be too difficult for you to pop in a field army if you want to have one. Though I'm not sure what happens if you spawn a force right next to an opponent and whether or not that little yellow zone thing would apply.
    There is a problem with fixed coordinates, You don't know which provinces will be hold by a clan at any time. Making a rule that spawn units at capitals (like grant unit for dilemma rules) will solve that problem or we will have to create, at least, 1 rule for each province and several army options to make it works with diferent clans..

    There must be an easier way than that to spawn an army inside a province....

  9. #9

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    Another thing It would be posible to use grant unit outside a dilemma??

    I have been trying something like grant_unit (#capital, "inf_yari_samurai_ronin") to add some units to the AI without success..
    Quote Originally Posted by Thorn View Post
    There is a problem with fixed coordinates, You don't know which provinces will be hold by a clan at any time. Making a rule that spawn units at capitals (like grant unit for dilemma rules) will solve that problem or we will have to create, at least, 1 rule for each province and several army options to make it works with diferent clans..

    There must be an easier way than that to spawn an army inside a province....
    There's two possible issues here. 1.) grant_unit doesn't work for the AI. 2.) You are possibly using it wrong. Could you post the useage code here so I can take a look? For reference, here is an example:

    Code:
    scripting.game_interface:grant_unit("settlement:ita_milano:milan", "Inf_Light_Lombardy-Cisalpine_Legion")
    My Tools, Tutorials and Resources

    Was running out of space, so see the full list here!

    Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings
    The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell

  10. #10
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

    Default Re: The S2 Script-o-Rama

    I think the problem might be that he wasn't using the "scripting.game_interface" prefix, as in the missions scripts there is only "grant_unit..." ?

  11. #11

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by .Mitch. View Post
    I think the problem might be that he wasn't using the "scripting.game_interface" prefix, as in the missions scripts there is only "grant_unit..." ?
    Possibly. If that happened the error would probably be more noticeable on the campaign map that if the arguments were wrong.
    My Tools, Tutorials and Resources

    Was running out of space, so see the full list here!

    Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings
    The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell

  12. #12
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

    Default Re: The S2 Script-o-Rama

    I always come to this point when scripting eventualy, where something you want to do becomes more work than its worth. =P

    Is there a way to possibly create a mission, and have it autocomplete right away to just get the grantunit function to fire? Just throwing ideas out here..

  13. #13

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by .Mitch. View Post
    Is there a way to possibly create a mission, and have it autocomplete right away to just get the grantunit function to fire? Just throwing ideas out here..
    Yes, but...

    Quote Originally Posted by .Mitch. View Post
    more work than its worth


    The other way I mentioned is really not that hard to do. You could do it in less that 50 lines of code, at a guess. I'll give it a shot this evening / tomorrow and see how it looks.
    Last edited by T.C.; June 18, 2011 at 11:19 AM.
    My Tools, Tutorials and Resources

    Was running out of space, so see the full list here!

    Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings
    The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell

  14. #14
    Thorn's Avatar Artifex
    Join Date
    Jan 2005
    Location
    Here
    Posts
    2,194

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by .Mitch. View Post
    I always come to this point when scripting eventualy, where something you want to do becomes more work than its worth. =P

    Is there a way to possibly create a mission, and have it autocomplete right away to just get the grantunit function to fire? Just throwing ideas out here..
    Well it isn't too hard, just time-consuming and frustrating knowing that if we had access to those functions definitions we could make it easier..

    I had the same idea, but I will try to avoid it as long as I can find a more elegant way..

    Quote Originally Posted by T.C. View Post

    The other way I mentioned is really not that hard to do. You could do it in less that 50 lines of code, at a guess. I'll give it a shot this evening / tomorrow and see how it looks.
    Great!, It could be nice to have some guidance, I'm still in bad shape about scripting.., last time I did it was with Med2..

    I would like to ask two things

    How RecruitUnit works?, force you to train a unit? or spawn it?

    and I have created a rule to make all players at peace, but I can't remove alliances and protectorates or find a function about that..

    Is there something like force_break_alliance/protectorate out there??

    I have found force_make_protectorate/peace/trade and force_declare_war, but noting else..
    Last edited by Thorn; June 18, 2011 at 01:08 PM.

  15. #15
    Thorn's Avatar Artifex
    Join Date
    Jan 2005
    Location
    Here
    Posts
    2,194

    Default Re: The S2 Script-o-Rama

    Hello again guys,

    At last I have understood how events and dilemmas works without using scripts, but now I'm a bit stuck with this..

    events.FactionTurnStart[#events.FactionTurnStart+1] = function(context)

    local Region = CampaignUI.RegionsOwnedByFaction(context)

    for i = 1, #Region do
    effect.adjust_treasury(10000, context)
    end
    end

    I cant find why it isn't working, any clue?

  16. #16

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    Hello again guys,

    At last I have understood how events and dilemmas works without using scripts, but now I'm a bit stuck with this..

    events.FactionTurnStart[#events.FactionTurnStart+1] = function(context)

    local Region = CampaignUI.RegionsOwnedByFaction(context)

    for i = 1, #Region do
    effect.adjust_treasury(10000, context)
    end
    end

    I cant find why it isn't working, any clue?
    It's been a while since I was here - later tonight I'll post what I said I'd post a month ago and the long answer to your question. The short answer is that table uses strings as keys, not numbers. So a numeric loop won't work it, you need a "for k, v in pairs(table)".
    My Tools, Tutorials and Resources

    Was running out of space, so see the full list here!

    Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings
    The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell

  17. #17
    Thorn's Avatar Artifex
    Join Date
    Jan 2005
    Location
    Here
    Posts
    2,194

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by T.C. View Post
    It's been a while since I was here - later tonight I'll post what I said I'd post a month ago and the long answer to your question. The short answer is that table uses strings as keys, not numbers. So a numeric loop won't work it, you need a "for k, v in pairs(table)".
    Sorry, but It isnt working either...

    as soon as I include local Region = CampaignUI.RegionsOwnedByFaction (context) into my function it stops working..

  18. #18

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    How RecruitUnit works?, force you to train a unit? or spawn it?
    Where have you seen this function?

    Quote Originally Posted by Thorn View Post
    Is there something like force_break_alliance/protectorate out there??
    Not that I'm aware of.

    Quote Originally Posted by Thorn View Post
    Hello again guys,

    At last I have understood how events and dilemmas works without using scripts, but now I'm a bit stuck with this..

    events.FactionTurnStart[#events.FactionTurnStart+1] = function(context)

    local Region = CampaignUI.RegionsOwnedByFaction(context)

    for i = 1, #Region do
    effect.adjust_treasury(10000, context)
    end
    end

    I cant find why it isn't working, any clue?

    Ok, we'll start off with this. First, look here (and wait till the page fully loads so it jumps to the anchor tag) to see the sort of output that that function gives. As you can see, when it was originally logged it was logged as key, value, \n, key, value type, value. (so ignore the string:, function: and so on bits). I've been misreading what you wanted out of this, so you can disregard my eralier comment about string keys, rather than numerical keys (I thought you wanted region names) So a modified version of your script goes as follows:

    Code:
    events.FactionTurnStart[#events.FactionTurnStart+1] = function(context)
    	--This might work, not sure tbh
    	-------------------------------------
    	local FactionString = context.string
    	-------------------------------------
    	--if that doesn't work then
    	for i = 1, # FactionsTable do
    	if conditions.FactionName(FactionsTable[i], context) then
    		local Region = CampaignUI.RegionsOwnedByFactionOrByProtectorates(FactionsTable[i])
    			for i = 1, #Region do
    				scripting.game_interface:treasury_mod(FactionsTable[i], 10000)
    			end	
    	end
    end
    Notes:
    • Getting the faction name from context should work - I'd run logging tests on it first to find out (it could be context.String or context.FactionName)
    • If that works replace the table entires with the variable FactionString
    • If the above doesn't work you'll need to make a table with the factions you want to effect, I've named it FactionsTable in the example there - in NTW there's a handy function to generate a table of that sort, IDT it exists in S2.
    • I've added a better treasury adjustment function there, however it doesn't accept negative figures. But it is more reliable apart from that.


    And here's something I said I'd do quite a while ago. This code is used to get a region's key:

    Code:
    	local RegionKey = nil
    	local RegionAddress = nil
    	local PlayersFaction = CampaignUI.PlayersFactionKey()
    	local RegionList = CampaignUI.RetrieveFactionRegionList(PlayersFaction)
    	for k, v in ipairs(RegionList) do
    		--Get the regions address from the settlements address
    		RegionAddress = CampaignUI.SettlementsRegion(v.SettlementAddress)
    		--And from the settlements address the region's key
    		RegionKey = CampaignUI.RegionKeyFromAddress(RegionAddress)
    		--from here do something with RegionKey, as it will be overwritten each time the loop iterates.
    	end
    Once you have the region's key you can compare it to a table with the type of settlement names used for grant_unit() (eg "settlement:ita_milano:milan") and from there use grant_unit. If you want me to write the full code for something like this I will.
    My Tools, Tutorials and Resources

    Was running out of space, so see the full list here!

    Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings
    The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell

  19. #19
    Thorn's Avatar Artifex
    Join Date
    Jan 2005
    Location
    Here
    Posts
    2,194

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by T.C. View Post
    Where have you seen this function?
    I can't remember right now, I think from ETW/NTW Script-o-Rama


    Quote Originally Posted by T.C. View Post

    Spoiler Alert, click show to read: 


    Ok, we'll start off with this. First, look here (and wait till the page fully loads so it jumps to the anchor tag) to see the sort of output that that function gives. As you can see, when it was originally logged it was logged as key, value, \n, key, value type, value. (so ignore the string:, function: and so on bits). I've been misreading what you wanted out of this, so you can disregard my eralier comment about string keys, rather than numerical keys (I thought you wanted region names) So a modified version of your script goes as follows:

    Code:
    events.FactionTurnStart[#events.FactionTurnStart+1] = function(context)
    	--This might work, not sure tbh
    	-------------------------------------
    	local FactionString = context.string
    	-------------------------------------
    	--if that doesn't work then
    	for i = 1, # FactionsTable do
    	if conditions.FactionName(FactionsTable[i], context) then
    		local Region = CampaignUI.RegionsOwnedByFactionOrByProtectorates(FactionsTable[i])
    			for i = 1, #Region do
    				scripting.game_interface:treasury_mod(FactionsTable[i], 10000)
    			end	
    	end
    end
    Notes:
    • Getting the faction name from context should work - I'd run logging tests on it first to find out (it could be context.String or context.FactionName)
    • If that works replace the table entires with the variable FactionString
    • If the above doesn't work you'll need to make a table with the factions you want to effect, I've named it FactionsTable in the example there - in NTW there's a handy function to generate a table of that sort, IDT it exists in S2.
    • I've added a better treasury adjustment function there, however it doesn't accept negative figures. But it is more reliable apart from that.


    And here's something I said I'd do quite a while ago. This code is used to get a region's key:

    Code:
    	local RegionKey = nil
    	local RegionAddress = nil
    	local PlayersFaction = CampaignUI.PlayersFactionKey()
    	local RegionList = CampaignUI.RetrieveFactionRegionList(PlayersFaction)
    	for k, v in ipairs(RegionList) do
    		--Get the regions address from the settlements address
    		RegionAddress = CampaignUI.SettlementsRegion(v.SettlementAddress)
    		--And from the settlements address the region's key
    		RegionKey = CampaignUI.RegionKeyFromAddress(RegionAddress)
    		--from here do something with RegionKey, as it will be overwritten each time the loop iterates.
    	end
    Once you have the region's key you can compare it to a table with the type of settlement names used for grant_unit() (eg "settlement:ita_milano:milan") and from there use grant_unit. If you want me to write the full code for something like this I will.


    Well I tried this way and it works

    Code:
    events.FactionTurnStart[#events.FactionTurnStart+1] = function(context)
    
    	local Region = CampaignUI.RegionsOwnedByFactionOrByProtectorates(context.string)
    	local provincias = 0
    	local turno = CampaignUI.CurrentTurn(context)
    	local factor = math.floor((turno*5)/math.log(turno+1))
    
    	if not conditions.FactionIsHuman(context) then
    		for k,v in pairs(Region) do
    			provincias = provincias +1			
    		end		
    		effect.adjust_treasury(provincias*factor, context)
    	end
    	if turno < 6 then
    		effect.adjust_treasury(125, context)
    	elseif turno < 12 then
    		effect.adjust_treasury(125, context)
    	elseif turno < 24 then
    		effect.adjust_treasury(125, context)
    	end
    end
    I'm looking for a better function to gradually increase income from provinces to lessen the AI inability for developing a strong economy, but this get +1800 per province at the end of the game time, maybe it could seems a bit much, however by this time the Human player will have a very strong position

  20. #20

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    I can't remember right now, I think from ETW/NTW Script-o-Rama
    This is exactly the same as the NTW script o rama. Anyway, the function is used by the UI. But it needs arguments that are very specific to the UI environment, we wouldn't be able to generate them from a campaign scripting point of view.

    Quote Originally Posted by Thorn View Post

    Well I tried this way and it works

    Code:
    events.FactionTurnStart[#events.FactionTurnStart+1] = function(context)
    
    	local Region = CampaignUI.RegionsOwnedByFactionOrByProtectorates(context.string)
    	local provincias = 0
    	local turno = CampaignUI.CurrentTurn(context)
    	local factor = math.floor((turno*5)/math.log(turno+1))
    
    	if not conditions.FactionIsHuman(context) then
    		for k,v in pairs(Region) do
    			provincias = provincias +1			
    		end		
    		effect.adjust_treasury(provincias*factor, context)
    	end
    	if turno < 6 then
    		effect.adjust_treasury(125, context)
    	elseif turno < 12 then
    		effect.adjust_treasury(125, context)
    	elseif turno < 24 then
    		effect.adjust_treasury(125, context)
    	end
    end
    I'm looking for a better function to gradually increase income from provinces to lessen the AI inability for developing a strong economy, but this get +1800 per province at the end of the game time, maybe it could seems a bit much, however by this time the Human player will have a very strong position
    CampaignUI.CurrentTurn() doesn't need a context argument. Luckily Lua discards superflous arguments, saving a lot of errors

    The function itself is good, you just need to play about with your mathematical formula's to get better results.
    My Tools, Tutorials and Resources

    Was running out of space, so see the full list here!

    Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings
    The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell

Page 4 of 5 FirstFirst 12345 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •