Page 3 of 6 FirstFirst 123456 LastLast
Results 41 to 60 of 105

Thread: The S2 Script-o-Rama

  1. #41

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Seikales View Post
    Just check

    if conditions.Factionname(klan, context) then

    without any other condition and klan is a variable name. Tell me what you get. I tried it stand alone that way and it didn't work until I wrote

    if conditions.FactionName(klan, context) == true then

    I know it is strange but I don't see any mistake in the code. Anyhow, try it if you wish.

    About random numbers: I read on the web that the os.time function won't return millisecond information unless you use extra libraries. Is that a mistaken information then?
    I can't try right now, I don't have access to S2 atm.
    I used os.clock, not os.time
    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

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

    Default Re: The S2 Script-o-Rama

    I'm trying to change some diplomatic agreement effects, but I cant find their effects..

    I'm looking mainly for make protectorade/ally events, where could I find them?

  3. #43

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    I'm trying to change some diplomatic agreement effects, but I cant find their effects..

    I'm looking mainly for make protectorade/ally events, where could I find them?
    Most diplomatic stuff is hardcoded. Any diplomacy editing via scripts would involve setting up a listener (for when certain factions attain the wanted diplomatic stance towards each other) and when the conditions are met, apply some sort of effect. Though apply db based effects from scripting isn't straightforward.
    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

  4. #44
    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
    Most diplomatic stuff is hardcoded. Any diplomacy editing via scripts would involve setting up a listener (for when certain factions attain the wanted diplomatic stance towards each other) and when the conditions are met, apply some sort of effect. Though apply db based effects from scripting isn't straightforward.
    Well that could work, I just want to give military access to allies and protectorates, making it that way I could even make it happens only between AI factions to avoid posible human exploits..

    When you said a listener you mean a background process like a trigger that is waiting for some conditions to be executed?

  5. #45

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    Well that could work, I just want to give military access to allies and protectorates, making it that way I could even make it happens only between AI factions to avoid posible human exploits..

    When you said a listener you mean a background process like a trigger that is waiting for some conditions to be executed?

    Well that's actually easy enough to do. Have you any experience scripting? if so, I can point you in the right direction. If not I could write it up quick enough.
    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

  6. #46
    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
    Well that's actually easy enough to do. Have you any experience scripting? if so, I can point you in the right direction. If not I could write it up quick enough.
    Thanks, I have some experience, I'm just a bit lost after a few years without doing it (since M2TW) so any help would be appreciate.

    I have been trying to find a function to know when an alliance/protectorate/vassalage is done to give military access to factions involved.

  7. #47

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    Thanks, I have some experience, I'm just a bit lost after a few years without doing it (since M2TW) so any help would be appreciate.

    I have been trying to find a function to know when an alliance/protectorate/vassalage is done to give military access to factions involved.
    I'm not 100% sure if this is what you want, let me know.

    I've added comments just to make things that bit easier You'll have to fill the factions table in manually; I have conflicting information as to whether or not a function to return living factions exists in S2 or not (and right now I can't check it). The table has some NTW factions in it, just so you know how to fill it out.

    Code:
    	local factions = {"prussia", "britain", "austria", "russia"}
    	local TCS_Diplomacy_Variable_Check = nil
    	--We need to loop through the factions twice so we can get two different names
    	--during any one iteration of the loop
    	for i = 1, #factions do 
    		for e = 1, #factions do
    			--Shut down all military access between the given factions
    			scripting.game_interface:force_diplomacy(factions[i], factions[e], "military access", false, false)
    			--Check the factions diplomacy stance, assign it to a variable
    			TCS_Diplomacy_Variable_Check = CampaignUI.RetrieveDiplomaticStanceString(factions[i], factions[e])
    			--If they are allied then....
    			if TCS_Diplomacy_Variable_Check == "Allied" then
    				--Allow military access
    				scripting.game_interface:force_diplomacy(factions[i], factions[e], "military access", true, false)
    			end
    		end
    	end
    Notes:
    • It's much more difficult to check if they have a protectorate agreement in place as it uses a different function with output that is far harder to check against (the other faction outputs a big block of strings rather than just one, and isn't even in a table format). Anyway, being allied covers most of the situations.
    • An "end" gets cut off on my browser by the bottom of the code box, watch out for it


    What were your ideas in regards to the player? I haven't factored that in yet.
    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

  8. #48
    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
    I'm not 100% sure if this is what you want, let me know.
    Spoiler Alert, click show to read: 

    I've added comments just to make things that bit easier You'll have to fill the factions table in manually; I have conflicting information as to whether or not a function to return living factions exists in S2 or not (and right now I can't check it). The table has some NTW factions in it, just so you know how to fill it out.

    Code:
    	local factions = {"prussia", "britain", "austria", "russia"}
    	local TCS_Diplomacy_Variable_Check = nil
    	--We need to loop through the factions twice so we can get two different names
    	--during any one iteration of the loop
    	for i = 1, #factions do 
    		for e = 1, #factions do
    			--Shut down all military access between the given factions
    			scripting.game_interface:force_diplomacy(factions[i], factions[e], "military access", false, false)
    			--Check the factions diplomacy stance, assign it to a variable
    			TCS_Diplomacy_Variable_Check = CampaignUI.RetrieveDiplomaticStanceString(factions[i], factions[e])
    			--If they are allied then....
    			if TCS_Diplomacy_Variable_Check == "Allied" then
    				--Allow military access
    				scripting.game_interface:force_diplomacy(factions[i], factions[e], "military access", true, false)
    			end
    		end
    	end
    Notes:
    • It's much more difficult to check if they have a protectorate agreement in place as it uses a different function with output that is far harder to check against (the other faction outputs a big block of strings rather than just one, and isn't even in a table format). Anyway, being allied covers most of the situations.
    • An "end" gets cut off on my browser by the bottom of the code box, watch out for it


    What were your ideas in regards to the player? I haven't factored that in yet.
    Thanks a lot!

    It seems we can't use the diplomatic agrement trigger like in M2TW so we have to check all factions every turn even those destroyed..

    About "shutting" down previous status, that would make non allied factions loose their agreements.. or you can only ask for military access when allied?

    To make it works with protectorates we should add if TCS_Diplomacy_Variable_Check == "Allied" or TCS_Diplomacy_Variable_Check == "Protector" or TCS_Diplomacy_Variable_Check == "Patron" , isn't it?

    About the player I was thinking to make it works only 1 way.. AI factions get military access, but Human player should have to ask for it, but if the penalties for breaking an alliance works I shouldn't be worry about human exploiting it happily
    Last edited by Thorn; June 05, 2011 at 02:34 PM.

  9. #49

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    Thanks a lot!

    It seems we can't use the diplomatic agrement trigger like in M2TW so we have to check all factions every turn even those destroyed..

    About the player I was thinking to make it works only 1 way.. AI factions get military access, but Human player should have to ask for it, but if the penalties for breaking an alliance works I shouldn't be worry about human exploiting it happily
    There's only a handful of stuff you can force:
    • force_declare_war
    • force_make_peace
    • force_make_protectorate
    • force_make_trade_agreement


    After that it's all allow/deny the option (and most can be circumvented by an AI army invading one of it's neighbours).
    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. #50
    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
    There's only a handful of stuff you can force:
    • force_declare_war
    • force_make_peace
    • force_make_protectorate
    • force_make_trade_agreement


    After that it's all allow/deny the option (and most can be circumvented by an AI army invading one of it's neighbours).
    Ouch, I was editing my post when you answered, I was adding this:

    About "shutting" down previous status, that would make non allied factions loose their agreements.. or you can only ask for military access when allied?

    To make it works with protectorates we should add if TCS_Diplomacy_Variable_Check == "Allied" or TCS_Diplomacy_Variable_Check == "Protector" or TCS_Diplomacy_Variable_Check == "Patron" , isn't it?

  11. #51

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Thorn View Post
    Ouch, I was editing my post when you answered, I was adding this:

    About "shutting" down previous status, that would make non allied factions loose their agreements.. or you can only ask for military access when allied?

    To make it works with protectorates we should add if TCS_Diplomacy_Variable_Check == "Allied" or TCS_Diplomacy_Variable_Check == "Protector" or TCS_Diplomacy_Variable_Check == "Patron" , isn't it?
    It doesn't cause already existing statuses to be lost, it simply blocks the diplomatic offering.

    As I said above, the Protectorate information comes from a different function that outputs a large string such as this:

    Code:
    Protectorate
    
    Trade agreement
    
    Grants military access (indefinite)
    
    Has military access to your lands (indefinite)
    As that's all the one string, it's very hard to pick out the relevant information.

    Remember, I'm speaking from a NTW standpoint here. Things may be different in S2, but you'll have to log the functions yourself. There's a section in the OP about that if you are interested
    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. #52
    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 doesn't cause already existing statuses to be lost, it simply blocks the diplomatic offering.

    As I said above, the Protectorate information comes from a different function that outputs a large string such as this:

    Code:
    Protectorate
    
    Trade agreement
    
    Grants military access (indefinite)
    
    Has military access to your lands (indefinite)
    As that's all the one string, it's very hard to pick out the relevant information.

    Remember, I'm speaking from a NTW standpoint here. Things may be different in S2, but you'll have to log the functions yourself. There's a section in the OP about that if you are interested
    Oh.. I see.., but then protectorate grants military access by default... I should take a look on that, because then the problem is the dumb AI not helping its allies...

    I can see a full Imagawa stack waiting at Tokugawas frontier while Oda armies are invading it, so I thought they had no military access, but maybe I'm wrong.

    Thanks for the info

  13. #53

    Default Re: The S2 Script-o-Rama

    I am using the following random number generation method, which seems to work very good. It is partially your method, so thanks T.C.
    '
    Code:
    local num1,num2,num3,num4
    num1 = os.clock()
    num2 = math.modf(num1)
    num3 = math.ceil((num1-num2)*10000)
    math.randomseed(num3)
    num4 = math.random(a,b)

  14. #54

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Seikales View Post
    I am using the following random number generation method, which seems to work very good. It is partially your method, so thanks T.C.
    '
    Code:
    local num1,num2,num3,num4
    num1 = os.clock()
    num2 = math.modf(num1)
    num3 = math.ceil((num1-num2)*10000)
    math.randomseed(num3)
    num4 = math.random(a,b)

    Just so you know, you don't need to explicitly declare the variables as you have in the first line when there is no danger of them being referenced before being assigned
    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

  15. #55

    Default Re: The S2 Script-o-Rama

    Three questions (Ugh. Shameful display - sorry for the bother. I knew I should have taken more compsci when I had the chance...)

    - If I want to get into the details of the event.lua script, how do I go about doing that? In particular, I'd like to see how a few of the events are designed.

    - If I wish to code in my own custom event (mostly just displaying text for narrative purposes), is there an approximately hard-coded event that I can clone and modify?

    - How do I code dilemmas? Is it basically just a mission with yes/no and different parameters assigned to each, or is a dilemma a different thing altogether?

  16. #56

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Ying, Duke of Qin View Post
    Three questions (Ugh. Shameful display - sorry for the bother. I knew I should have taken more compsci when I had the chance...)

    - If I want to get into the details of the event.lua script, how do I go about doing that? In particular, I'd like to see how a few of the events are designed.

    - If I wish to code in my own custom event (mostly just displaying text for narrative purposes), is there an approximately hard-coded event that I can clone and modify?

    - How do I code dilemmas? Is it basically just a mission with yes/no and different parameters assigned to each, or is a dilemma a different thing altogether?

    You need to start with some basic stuff until you get familiar with Lua; what you are asking is very complex and would take me a while to write. If you have no experience with Lua I doubt it would make any sense at all to you.
    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. #57

    Default Re: The S2 Script-o-Rama

    Mm, as always, I tend to be a bit overly ambitious when coming to these things. Blame it on the fangirling. But pretty please? I promise I'm teachable .

    You need to start with some basic stuff until you get familiar with Lua; what you are asking is very complex and would take me a while to write. If you have no experience with Lua I doubt it would make any sense at all to you.
    I've tried your tutorials, and downloaded/wrote a number of scripts to play with. I can do a lot of the simple things (giving units, adding money, even custom battles with a bit of help from .Mitch.). What else should I be trying out?

    I think I've actually made some headway. All of the event text and things are located conveniently in the local_INSERTLANGUAGEHERE. There is one for the titles (event_log_descriptions, message_event_log_descriptions) and another event for the text itself. Given what I'm trying to do is mostly narrative-based, I'd really like to know how an event is actually put together.

    Thanks again!

  18. #58

    Default Re: The S2 Script-o-Rama

    I misread what you were trying to do, it's fairly simple after all

    Well if I was building an event for Napoleon I'd add an entry in the events table in the db. Then you'd have to add an entry in data/events.lua. That's for a historic event.

    You can't build a custom event such as OnFactionTurnStart, but you can use these events to be very specific, mainly by using stuff like context.string as an argument. But you'd have to log context.string first to see what it's output is.

    You'll need to be a bit clearer about this, I'm not sure what you're getting at:

    - If I want to get into the details of the event.lua script, how do I go about doing that? In particular, I'd like to see how a few of the events are designed.
    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. #59

    Default Re: The S2 Script-o-Rama

    Thanks for the help, T.C! I'll be fiddling around when I get home tonight.

    You can't build a custom event such as OnFactionTurnStart, but you can use these events to be very specific, mainly by using stuff like context.string as an argument. But you'd have to log context.string first to see what it's output is.
    Ah. Alright. Man, this isn't making our lives easier at all...

    You'll need to be a bit clearer about this, I'm not sure what you're getting at:
    Oh. What I mean is that I'd like to see for myself regarding the functionality of a few of events cited there - DummyEvent, DuelDemanded/DuelFought, the differences between HistoricalEvents, Historical_Events and HistoricalCharacters. That sort of thing. I went into the scripting.lua file but couldn't find any details as to where they were, nor can I find examples (sometimes you can find a lot of things in the tutorial's scripting. )

  20. #60

    Default Re: The S2 Script-o-Rama

    I think for any serious scripting effort, we need a list of functions we can call (including effects etc.) from a script. I believe for coding ease, a lot of functions were allowed for script calls. We just have to find them out

    But I have no clue how. What are the chances that CA releases this information to us?

Page 3 of 6 FirstFirst 123456 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
  •