Page 2 of 6 FirstFirst 123456 LastLast
Results 21 to 40 of 105

Thread: The S2 Script-o-Rama

  1. #21

    Default Re: The S2 Script-o-Rama

    Well, another question for y'all...

    There are events like UnitCreated() etc. in the events list.

    Now, the UnitCreated() event returns with an object, most likely, and most likely with an object of Unit class. Though, I have no clue what that class is, what parameters it has and such.

    Is there a way to make the program print those information out? Some way to pry into the abyss of the code?

  2. #22

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Seikales View Post
    Now, the UnitCreated() event returns with an object, most likely, and most likely with an object of Unit class.
    Chances are it won't - most events are simply hooks for triggering stuff, you have to specify yourself. As for print outs, read my section on logging (Section II.3)
    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. #23

    Default Re: The S2 Script-o-Rama

    Ok, so I have changed the scripting.lua as follows:

    Spoiler Alert, click show to read: 

    ...

    EpisodicScripting = scripting
    scripting.SetCampaign("jap_shogun")
    out.ting("Shogun Japan campaign script!")

    function TCS_Create_Log()
    local DateAndTime = os.date()
    local TCSLog = io.open("data/Logs/log.txt","w")
    TCSLog:write("[Log Created] "..DateAndTime.."\n\n")
    TCSLog:close()
    end

    local function OnNewCampaignStarted(context)
    new_game = true
    becoming_shogun_advice = true
    TCS_Create_Log ()
    scripting.game_interface:add_restricted_building_level_record("SHO_Port_3_Nanban_Trade_Port")
    scripting.game_interface:add_restricted_unit_record("Cav_Spear_Great_Guard_Takeda")
    scripting.game_interface:add_restricted_unit_record("Heavy_Ship_Nihon_Maru_Mori")
    end

    ...



    I tried three different methods.

    1) I saved this file in data/campaigns/jap_shogun folder.
    2) I added this file to my mod and kept the file in the folder.
    3) I added this file to my mod and deleted the file in the folder.

    however, nothing happened. I did not see any file getting created etc.

    In another attempt I added this in export_triggers_lua as

    Spoiler Alert, click show to read: 

    ...
    events.NewCampaignStarted[#events.NewCampaignStarted+1] =
    function(context)
    local DateAndTime = os.date()
    local TCSLog = io.open("data/Logs/log.txt","w")
    TCSLog:write("[Log Created] "..DateAndTime.."\n\n")
    TCSLog:close()
    return false
    end
    ...


    This method I tried by saving the file in the folder and adding it to my mod. As I suspected, it overwrote functions of some other parts of the script and I no longer had any initial
    missions, or spawning armies. Although it is not the way it should be done, I tried whether it would work
    but no. There was no file again.

    At no point the program gave any errors. It started smoothly.

    Any ideas? Thanks in advance

    Edit: If I change the path to data/log.txt instead of data/Logs/log.txt, it works. It will NOT create a folder for you apparently, but it will write in a folder if you create it. You have to create the folder, if you wish it at a nice neat location
    Last edited by Seikales; May 29, 2011 at 11:03 PM.

  4. #24

    Default Re: The S2 Script-o-Rama

    Question: Is there a way to retrieve the name of the faction when the FactionTurnEnd event fires?

  5. #25

    Default Re: The S2 Script-o-Rama

    Question: Have you EVER tried to run these on the scripting.lua? I keep getting errors.

    Edit: I forgot that the event listener for FactionTurnEnd was already defined on AddEventCallBack definitions. Although very small, there exists an OnFactionTurnEnd function defined for this. Editing that function will do whatever is required.

    The upper question still remains though
    Last edited by Seikales; May 30, 2011 at 10:04 AM.

  6. #26

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Seikales View Post
    It will NOT create a folder for you apparently, but it will write in a folder if you create it.
    Sorry, I should have made this a little clearer, Buy you are right in where it went wrong

    Quote Originally Posted by Seikales View Post
    Question: Is there a way to retrieve the name of the faction when the FactionTurnEnd event fires?
    Just use the FactionName condition (ie use it's output as a variable)
    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

  7. #27

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Seikales View Post
    Have you EVER tried to run these on the scripting.lua? I keep getting errors.
    Yes, I run everything out of scripting.lua.
    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. #28

    Default Re: The S2 Script-o-Rama

    If my scripts are correct, the total population of a clan doesn't change with recruitment, for example. That's a bugger! Total shame.

    And, as an example. the population of the Mori capital Aki is 100,000.

    Quote Originally Posted by T.C. View Post
    Just use the FactionName condition (ie use it's output as a variable)
    Could you please kindly elaborate on this? A detailed example will be of great help mate. I am new to this Lua stuff and mostly new to event/callback etc. things.
    Last edited by Seikales; May 30, 2011 at 10:51 AM.

  9. #29
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Seikales View Post
    If my scripts are correct, the total population of a clan doesn't change with recruitment, for example. That's a bugger! Total shame.

    And, as an example. the population of the Mori capital Aki is 100,000.



    Could you please kindly elaborate on this? A detailed example will be of great help mate. I am new to this Lua stuff and mostly new to event/callback etc. things.
    Code:
    local function OnFactionTurnStart(context)
        
    if conditions.TurnNumber(context) == 2 then -- Here you can test what turn it is if you want
    
    if conditions.FactionName("hojo", context) then -- Here you can check what factions turn it is
    if conditions.FactionIsHuman("hojo", context) -- Here you can check if this faction is the player
    end
    end
    end

  10. #30

    Default Re: The S2 Script-o-Rama

    I meant a direct retrieval of the clan name. Otherwise, controlling against every clan name is required and it is a bit of a hassle. This is more of a general questions actually. I mean, when an event is called (say, in events/triggers), the information is transferred within the 'context' variable. It surely includes information that can be used. As an example, there is a CharacterTurnEnd event, which you can check against the CharacterType etc. You know, these kind of things usually have some sort of data structure, which can be perhaps accessed. Again to speak with an example (gedanken),

    A has two parameters, Length and Width

    You may access A.Length and A.Width, either directly or by using A.Length() if it has been defined (these I say from my general object oriented programming knowledge).

    So, I am wondering if I can access the structure of the context when I call it AND reach its parameters like this. For example, context.FactionName() would give me anything?

    Hope I make some sense Cheers and thanks for the replies!

  11. #31

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Seikales View Post
    I meant a direct retrieval of the clan name. Otherwise, controlling against every clan name is required and it is a bit of a hassle. This is more of a general questions actually.
    Just set up a table and loop through it, it will do it in a few lines of code. If you don't know how to use this I can write an example.

    I mean, when an event is called (say, in events/triggers), the information is transferred within the 'context' variable. It surely includes information that can be used. As an example, there is a CharacterTurnEnd event, which you can check against the CharacterType etc. You know, these kind of things usually have some sort of data structure, which can be perhaps accessed.
    The type of context is userdata, which means it is mostly information from the C side of the exe. Very little of it is useable from a Lua point of view, except perhaps context.string. I'll look up an example of this being used later, I don't use it myself and as such can't write something off the top of my head.
    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. #32

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by T.C. View Post
    Just set up a table and loop through it, it will do it in a few lines of code. If you don't know how to use this I can write an example.
    I would very much appreciate an example, even for the sake of comparison. Thanks in advance.

  13. #33
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

    Default Re: The S2 Script-o-Rama

    Create the table to house all of the factions in Shogun. Like so:

    Code:
    local factions_table = {"faction1", "faction2", "faction3", "faction4"}
    Create a loop and simple If statement to check what factions turn it is. You sound like you want to be able to do stuff depending on whatever faction it is, so your gona need an If statement for however many factions there are, there is no escaping this as you can't dynamicaly link a variable with the content of a variable without an If, which kinda makes this whole loop and table thing pointless as its still hugee code. Even CA don't use Loops, they just use a large amount of If statements, its easier.

    Here is a basic concept of looping through a table, not exact for what you want, because I don't know what you want:
    Code:
    for x = 1, #factions_table do -- Loop through the factions table
    if factions_table[x] = "shimazu" then
    --DO WHAT YOU WANT WITH SHIMAZU HERE
    elseif factions_table[x] = "hojo" then
    --DO WHAT YOU WANT WITH HOJO HERE
    end
    end -- Ending the Loop
    As you can see, it would be just as fast to do it the way I showed you earlier, with a set amount of If statements.

    Unless you want to learn dynamic tables of which you set the space in the table based on the number of the current loop, which is honestly not worth it imo, then your best off just getting down and doing the large number of If's.

  14. #34

    Default Re: The S2 Script-o-Rama

    Hmm, yes. That's a good way. Splendid. Thanks Mitch.

    Edit: I tried the following, which won't go through (error)

    for x = 1, #major_factions_table do -- Loop through the factions table

    klan = major_factions_table[x]


    if conditions.FactionName(klan, context) and not conditions.FactionIsHUman(klan, context)
    TCS_Log_Update(klan)
    end
    end

    Unfortunately, the program won't accept the klan variable in the function. This is so annoying. They almost don't want us to do any scripting.
    Last edited by Seikales; June 04, 2011 at 01:37 PM.

  15. #35

    Default Re: The S2 Script-o-Rama

    I tried the following, which won't go through (error)

    for x = 1, #major_factions_table do -- Loop through the factions table

    klan = major_factions_table[x]


    if conditions.FactionName(klan, context) and not conditions.FactionIsHUman(klan, context)
    TCS_Log_Update(klan)
    end
    end

    Unfortunately, the program won't accept the klan variable in the function. This is so annoying. They almost don't want us to do any scripting.

    Edit: I also tried
    klan = "\""..major_factions_table[x].."\""

    in hopes that this will be OK since generally input is like "mori" and the programmers can be some anal retentive sadists but, alas, that didn't work neither.
    Last edited by Seikales; June 04, 2011 at 02:14 PM.

  16. #36

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Seikales View Post
    I tried the following, which won't go through (error)

    for x = 1, #major_factions_table do -- Loop through the factions table

    klan = major_factions_table[x]


    if conditions.FactionName(klan, context) and not conditions.FactionIsHUman(klan, context)
    TCS_Log_Update(klan)
    end
    end

    Unfortunately, the program won't accept the klan variable in the function. This is so annoying. They almost don't want us to do any scripting.
    Lua is case-sensitive, check your FactionIsHuman.
    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. #37

    Default Re: The S2 Script-o-Rama

    FactionName(klan, context) won't work. I also checked for FactionIsHuman and everything else.

    But,

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

    works.

    Although if checks for boolean, somehow when comparing against the condition, you have to use the == true statement.

    This is rather strange. Please try it yourself and tell me if I am mistaken.
    Last edited by Seikales; June 05, 2011 at 01:55 AM.

  18. #38

    Default Re: The S2 Script-o-Rama

    Now, I am trying to get some nice random numbers. The os.time and os.clock are not very useful, they don't generate much randomness when used in

    math.randomseed(os.time())

    Any alternatives for a really good random number generator?

  19. #39

    Default Re: The S2 Script-o-Rama

    Quote Originally Posted by Seikales View Post
    FactionName(klan, context) won't work. I also checked for FactionIsHuman and everything else.

    But,

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

    works.

    Although if checks for boolean, somehow when comparing against the condition, you have to use the == true statement.

    This is rather strange. Please try it yourself and tell me if I am mistaken.
    You shouldn't have to, there must be a mistake elsewhere in your code. Probably because you said:
    Code:
    if conditions.FactionName(klan, context) and not conditions.FactionIsHUman(klan, context)
    Which is like saying "If it is 3 O'clock and it is not 3 O'clock then..."

    Quote Originally Posted by Seikales View Post
    Now, I am trying to get some nice random numbers. The os.time and os.clock are not very useful, they don't generate much randomness when used in

    math.randomseed(os.time())

    Any alternatives for a really good random number generator?
    math.random is a really bad tool to use for random number generation. Here's one I wrote myself:

    Quote Originally Posted by T.C. View Post
    As for randomisation, here's a much better, slightly different version I made. See what you can understand of it yet, it'll always be here for future reference

    It randomises by first creating a table with 100 "random" numbers in it (using the math.random() function which isn't good at all), then getting the millisecond value of the current time and using it to select one of the 100 random numbers. It would have been easier to use seconds, but if you want to use this repeatedly it is better to use milliseconds as computers can do more than one thing in a second

    +Rep to anyone who can point out the flaw in that combination of numbers + milliseconds (Yes, I am aware it is there )


    Code:
             --os.clock() returns the time in seconds that Lua has been running for. It is the only Lua 
    	--clock function that returns a time value in seconds and milliseconds, making it very useful.
    	--math.modf() returns the whole and fractional values of the number handed to it - using this
    	--we can separate the seconds from the milliseconds
    function TCS_Rand_Num ()
    	--Assign the os.clock output to a var
    	local DateAndTimeRandNum = os.clock()
    	--Assign the separated value to a var. (NOTE: This will only return the first of two values,
    	--so the whole number part, not the fractional.
    	local Num_1 = math.modf(DateAndTimeRandNum)
    	--declare a table
    	local Rand_Num_table = {}
    	--for 1 -> 100 assign the ith value to be a pseudo-random number, using math.random
    	for i = 1, 100 do
    		Rand_Num_table[i] = math.random(1, 100)
    	end
    	--take the clock value (seconds and milliseconds) away from the separated value(seconds) to
    	--leave you with only a milliseconds value. then multiply it by 100 and round up to the nearest integer (math.ceil)
    	--to give a whole number based on the millisecond the function was called.
    	local Num_2 = (math.ceil((DateAndTimeRandNum - Num_1) * 100))
    	--then using the number select one of the pseudo-random numbers from the table "Rand_Num_table"
    	--and return it
    	return Rand_Num_table[Num_2]
    end
    So you can use this as follows:
    Code:
    local NumberVar = TCS_Rand_Num ()
    if NumberVar > 3 then
    	...
    end
    Last edited by T.C.; June 05, 2011 at 05:47 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

  20. #40

    Default Re: The S2 Script-o-Rama

    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?

Page 2 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
  •