Results 1 to 7 of 7

Thread: Scripting Advice Needed

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Scripting Advice Needed

    Okay, I need some help with my mod in regards to scripting, I know very little on the subject, but at least I am trying.

    I want a character to be sent off map for a few turns, but only when the player accepts, much in the same way as one can find in the Kingdoms British Isles campaign.

    The faction is England, he has the correct trait, morkinquest and the correct label, morkin1. When I start the campaign no window pops up to request the character leave at all.


    Code:
    declare_counter morkin_quest_offered
    declare_counter morkin_questing
    
    monitor_event CharacterTurnStart Trait morkinquest = 1
            and I_CompareCounter morkin_quest_offered = 0
            set_counter send_morkin_accepted 0
            and I_TurnNumber = 0
            add_events
                event    counter    morkin_quest_invite_accepted
                event    counter    morkin_quest_invite_declined
                event    counter    morkin_questing
            end_add_events
            historic_event morkin_quest_invite true factions { england, }
            set_counter morkin_quest_offered 1
            if I_IsFactionAIControlled england
                set_event_counter morkin_quest_invite_accepted 1
            end_if    
        terminate_monitor
    end_monitor
    
    monitor_conditions I_EventCounter morkin_quest_invite_accepted = 1
            send_character_off_map morkin1
            set_counter morkin_questing 1
            historic_event morkin_leaves_for_quest
        terminate_monitor
    end_monitor
    
    monitor_conditions I_EventCounter morkin_questing = 1
            and I_TurnNumber = 4
                    spawn_army 
                        faction england
                        character    Morkin, named character, male, heir, age 19, x 33, y 40, label morkin1, portrait morkin
                        traits brave 5 , handsome 1
                        unit        Free Horse Bodyguard            exp 3 armour 1 weapon_lvl 0
                    end
        terminate_monitor
    end_monitor
    So what have I done wrong? I assume it is something silly that only a novice would do. I appreciate any help given.
    The Watchwords Of Midnight
    "The brave and the free fear no foe, go forth, mighty hosts of Midnight! Unto death or victory we go!"

    The Midnight Chronicles

  2. #2

    Default Re: Scripting Advice Needed

    There are a couple of things which may help you. I'll start at the top of your script and work down.

    the counter morkin_questing is somewhat not needed, because further down in the script you refer to it as an event_counter. Which does not need to be declared. There is a difference between event counters and regular counters.

    You also do not need the other counter which you declared, morkin_quest_offered, Because the only monitor it is used in is terminated once it fires. In effect, the counter is doing nothing.

    Moving onto the first monitor it starts off ok but then you add a command line in between 2 condition lines...

    and I_CompareCounter morkin_quest_offered = 0
    set_counter send_morkin_accepted 0
    and I_TurnNumber = 0

    The counter you set here has not been declared. You should scratch this line.

    In the events section you have declared the event twice (there are 2 different approaches to decalring and setting up events). I would just use the following line...

    historic_event morkin_quest_invite true factions { england, }

    The next line, set_counter morkin_quest_offered 1 is another counter that has not been declared. I don't see a need for it in this script unless you use it elsewhere in other scripts.

    The if statement should be fine. . I would add another if statement and change the script based on whether england is AI or human controlled. Using additional monitors is perfectly fine and wont cause any turn lag.

    You then use monitor_conditions, which, as a general rule its best to stay a way form them as they cause turn lag. The best approach is to do it all in a monitor_event. Also, this is the monitor which you use a regular counter but i think you intend it to act as an event counter. so...

    monitor_event EventCounter EventCounterType morkin_quest_invite_accepted
    if I_EventCounter morkin_quest_invite_accepted = 1
    send_character_off_map morkin1
    set_event_counter morkin_questing 1
    historic_event morkin_leaves_for_quest
    end_if
    terminate_monitor
    end_monitor

    The last moniotor_conditions can also be set up in a regular monitor_event.

    monitor_event EventCounter EventCounterType morkin_questing
    if I_EventCounter morkin_questing = 1
    and I_TurnNumber = 4
    spawn_army
    faction england
    character Morkin, named character, male, heir, age 19, x 33, y 40, label morkin1, portrait morkin
    traits brave 5 , handsome 1
    unit Free Horse Bodyguard exp 3 armour 1 weapon_lvl 0
    end
    end_if
    terminate_monitor
    end_monitor

    So putting it altogether, try this...

    Code:
     
    monitor_event CharacterTurnStart Trait morkinquest = 1
     and I_TurnNumber = 0
      if I_LocalFaction england
       historic_event morkin_quest_invite true
      end_if
      if not I_LocalFaction england
       set_event_counter morkin_quest_invite_accepted 1
      end_if    
        terminate_monitor
    end_monitor
     
    monitor_event EventCounter EventCounterType morkin_quest_invite_accepted
     if I_EventCounter morkin_quest_invite_accepted = 1
      send_character_off_map morkin1
      set_event_counter morkin_questing 1
             historic_event morkin_leaves_for_quest
    end_if
        terminate_monitor
    end_monitor
     
    monitor_event EventCounter EventCounterType morkin_questing 
     if I_EventCounter morkin_questing = 1
     and I_TurnNumber = 4
      spawn_army 
                        faction england
                        character    Morkin, named character, male, heir, age 19, x 33, y 40, label morkin1, portrait morkin
                        traits brave 5 , handsome 1
                        unit        Free Horse Bodyguard            exp 3 armour 1 weapon_lvl 0
                    end
    end_if
        terminate_monitor
    end_monitor
    I hope that helps. I'm more than happy to help further if you wish. Keep in mind that the lines i changed/deleted form your original script i am unsure if you use them elsewhere in other scripts. But they are easily put back in if that is the case. Also, ive never written a script to send a character off map, so i don't know if it is the correct command to do it or how it works, i assume yours is correct. This script should wok as long as i did not make any spelling errors and all the stuff in the spawn army part are correct in other files...

    Let me know how it works out...
    ...longbows, in skilled hands, could reach further than trebuchets...

  3. #3

    Default Re: Scripting Advice Needed

    send_character_off_map is the right thing, I am sure of it morkin1 is the label the character has, so it should work.

    But unfortunately I still do not get that far, the script does not start even with the modifications I made due to your advice, the choice event does not even appear. Not even when I just copy out your script.

    I think I understand all the bits where I went wrong from what you said in your post. I never knew monitor_conditions lagged the game. I was thinking of having the morkin_quest_offered do something, but as I could not get the script to work at all I tried to cut the entire thing down.

    I even read up what I could on this thread but I could not work out what is going wrong. My problem is that I do not have a very good understanding of it all. I will read everything over once more and try again, I am not one to give up easily. Thanks for the reply, I hope you can help work out what I am still doing wrong.


    Edit - Also I want an event for when Morkin returns, does this look right?

    Code:
    monitor_event EventCounter EventCounterType morkin_questing 
     if I_EventCounter morkin_questing = 1
     and I_TurnNumber = 4
             historic_event morkin_returns_from_quest
      spawn_army 
                        faction england
                        character    Morkin, named character, male, heir, age 19, x 33, y 40, label morkin1, portrait morkin
                        traits brave 5 , handsome 1
                        unit        Free Horse Bodyguard            exp 3 armour 1 weapon_lvl 0
                    end
    end_if
        terminate_monitor
    end_monitor
    Last edited by Aedelric; May 06, 2009 at 10:26 AM.
    The Watchwords Of Midnight
    "The brave and the free fear no foe, go forth, mighty hosts of Midnight! Unto death or victory we go!"

    The Midnight Chronicles

  4. #4

    Default Re: Scripting Advice Needed

    Two more things I would like to include when Morkin returns are;

    console_command remove_ancillary ice_crown
    console_command kill_character Gryfallon


    Are these correct? Also would the top one stop others acquiring the ice_crown ancillary? If not would it be possible to stop others gaining it?

    Edit - You posted that while I was typing this out, I will try the trace thing and let you know how it goes.
    The Watchwords Of Midnight
    "The brave and the free fear no foe, go forth, mighty hosts of Midnight! Unto death or victory we go!"

    The Midnight Chronicles

  5. #5

    Default Re: Scripting Advice Needed

    male seems to be one of the problems, another is the unit, I thought the inclusion of a bodyguard unit was important, perhaps it is not needed and just generates the general with the first bodyguard unit available. So I removed that unit.

    Edit - I am at a loss.
    Last edited by Aedelric; May 06, 2009 at 04:08 PM.
    The Watchwords Of Midnight
    "The brave and the free fear no foe, go forth, mighty hosts of Midnight! Unto death or victory we go!"

    The Midnight Chronicles

  6. #6

    Default Re: Scripting Advice Needed

    Try checking your log with trace turned on. Start up a new campaign and then exit. In the log search for campaign_script. Continue to search for it until you find explanations as to why the script is not firing. If you delete everything from the campaign script except for the script you are testing it may speed up the process of finding the issue. I always test my scripts starting with a blank campaign script. It could be somthing simple that is overlooked.

    Let us know how it works out.
    ...longbows, in skilled hands, could reach further than trebuchets...

  7. #7

    Default Re: Scripting Advice Needed

    console_command remove_ancillary ice_crown

    You need to add the characters name before the ancillary, such as 'console_command remove_ancillary characterName ice_crown'. This command will only remove the ancillary from that character. Traits and Ancillaries are determined in the dedicated file and they each have thier own conditions set in that file, which is where you would make it possible (or not) for other characters to obtain it, or under what conditions they can.

    When using the kill_character command just be sure you are naming the character properly. Correct spelling etc.

    For the spawn army command use this as a basis for your own army spawn. (this is straight from the docudemons).
    spawn_army
    faction romans_julii
    character Foedus Chaerea, general, command 0, influence 0, management 0, subterfuge 0, age 20, , x 54, y 124
    unit roman generals guard cavalry soldiers 20 exp 9 armour 1 weapon_lvl 0
    unit roman legionary first cohort ii soldiers 40 exp 0 armour 0 weapon_lvl 0
    unit roman legionary cohort ii soldiers 60 exp 0 armour 0 weapon_lvl 0
    unit roman praetorian cohort i soldiers 60 exp 0 armour 0 weapon_lvl 0
    end

    Also, for 'send_character_off_map' you can just use the characters name instead of a label.

    Do you have access to the docudemons?
    They are an invaluable source of aid for anyone planning on writing scripts. I would recommend GED's ultimate docudemons.

    Once again, try doing a search in the log (after setting it to trace and firing up a campaign). See what you find. If you like, upload your log here and ill take a look at it and see what i can do to help out. It can be frustrating when things seem unclear or your unsure if your on the right track or not, but once you get it working the feeling is well worth the trouble
    ...longbows, in skilled hands, could reach further than trebuchets...

Posting Permissions

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