OSP Code QoL Traits

Users who are viewing this thread

Chaalaaka

Ever since I've played any Total War games, I've always wanted to have Traits or Ancillaries. So I decided to create a very simple & basic trait system. You can also create an ancillary system using the same technique.

I won't be developing this further.
You guys should use this code and.. well.. make it better!  :razz:
 
The following goes to the very bottom.
#############
## Traits  ##
#############

ta_begin = 201
ta_end = 205

false_no_trait = 0
false_had_trait = 1
false_had_trait_bonus = 2
true_has_trait = 3
true_has_trait_bonus = 4


The following goes at the bottom of troop slots and before player slots.
#############
## Traits  ##
#############

ta_disgraced = 201
ta_goodcommander = 202
ta_intelligent = 203
ta_strong = 204
#############
## Traits  ##
#############



    #script_ta_init
#Initializes all T&A stuff.

("ta_init",
[
    #Each trait/ancillary has four options.
#0 (false_no_trait):        false/doesn't have the trait.
#1 (false_had_trait):        false/once had the trait but no longer does.
#2 (false_had_trait_bonus):  false/once had the trait but no longer does AND bonus taken.
#3 (true_has_trait):        true/has the trait.
#4 (true_has_trait_bonus):  true/has the trait AND trait bonus has been given.


#Handle kings.
    (try_for_range, ":king", kings_begin, kings_end),
   
#Set all traits to false.
    (try_for_range, ":ta", ta_begin, ta_end),
    (troop_set_slot, ":king", ":ta", false_no_trait),
(try_end),

#Add 3-7 random traits.
(store_random_in_range, ":rand", 4, :cool:,
(try_for_range, reg1, 3, ":rand"),
    (store_random_in_range, ":rand", ta_begin, ta_end),
(call_script, "script_ta_enable_trait_no", ":king", ":rand"),
(try_end),
(try_end),

#Handle lords.
(try_for_range, ":lord", lords_begin, lords_end),
   
#Set all traits to false.
(try_for_range, ":ta", ta_begin, ta_end),
    (troop_set_slot, ":lord", ":ta", false_no_trait),
(try_end),

#Add 1-3 random traits.
(store_random_in_range, ":rand", 2, 4),
(try_for_range, reg1, 1, ":rand"),
    (store_random_in_range, ":rand", ta_begin, ta_end),
(call_script, "script_ta_enable_trait_no", ":lord", ":rand"),
(try_end),
(try_end),
]),


#script_ta_enable_trait_no
#Input: troop, trait no.
#Gives the given trait to the given troop.

("ta_enable_trait_no",
[
    (store_script_param, ":troop", 1),
(store_script_param, ":trait_no", 2),
(try_begin),
    (ge, ":trait_no", ta_begin),
(lt, ":trait_no", ta_end),
    (troop_get_slot, ":trait", ":troop", ":trait_no"),
    (try_begin),
    (neq, ":trait", false_had_trait),
(neq, ":trait", false_had_trait_bonus),
(neq, ":trait", true_has_trait),
(neq, ":trait", true_has_trait_bonus),
    (troop_set_slot, ":troop", ":trait_no", true_has_trait),
    (try_end),
(try_end),
]),

#script_ta_disable_trait_no
#Input: troop, trait no.
#Disables the given trait of the given troop.

("ta_disable_trait_no",
[
    (store_script_param, ":troop", 1),
(store_script_param, ":trait_no", 2),
(try_begin),
    (ge, ":trait_no", ta_begin),
(lt, ":trait_no", ta_end),
    (troop_get_slot, ":trait", ":troop", ":trait_no"),
    (try_begin),
    (neq, ":trait", false_no_trait),
(neq, ":trait", false_had_trait),
(neq, ":trait", false_had_trait_bonus),
(try_begin),
    (eq, ":trait", true_has_trait),
    (troop_set_slot, ":troop", ":trait_no", false_had_trait),
(else_try),
    (eq, ":trait", true_has_trait_bonus),
(troop_set_slot, ":troop", ":trait_no", false_had_trait_bonus),
(try_end),
(troop_set_slot, ":troop", 201, 2), #ta_disgraced
(try_end),
(try_end),
]),


#script_ta_get_trait_text
#Input: trait no.
#Output: s0 as trait text.
#Gets the text of a certain trait.

    ("ta_get_trait_text",
[
    (store_script_param, ":trait_no", 1),
    (str_store_string, s0, "@"),
(try_begin),
    (eq, ":trait_no", 201), #ta_disgraced
(str_store_string, s0, "@Disgraced.^What this man once knew,^he can no longer recollect."),
(else_try),
    (eq, ":trait_no", 202), #ta_goodcommander
(str_store_string, s0, "@Good commander.^Great at military tactics.^(+3 tactics)"),
(else_try),
    (eq, ":trait_no", 203), #ta_intelligent
(str_store_string, s0, "@Intelligent.^Born with a good wit.^(+4 intelligence)"),
(else_try),
    (eq, ":trait_no", 204), #ta_strong
(str_store_string, s0, "@Strong.^Has grown muscles large enough.^(+2 ironflesh, +1 strength)"),
(try_end),
]),
#############
## Traits  ##
#############

   
#For optimization, add 2 hours to check interval each 3 traits.

#ta_goodcommander
#This is just an example trigger. You'll have to implement the rest yourself.
#To "activate" this trigger, you need to give a king/lord the ta_goodcommander trait using
#script_ta_enable_trait_no.

(18, 0, 0, [],
[
    #Update kings.
(try_for_range, ":king", kings_begin, kings_end),
    (troop_get_slot, ":ta", ":king", ta_goodcommander),
(neq, ":ta", false_no_trait),
(try_begin),
    (eq, ":ta", true_has_trait),
(troop_raise_skill, ":king", "skl_tactics", 3),
(troop_set_slot, ":king", ta_goodcommander, true_has_trait_bonus),
(else_try),
    (eq, ":ta", false_had_trait_bonus),
(troop_raise_skill, ":king", "skl_tactics", -3),
(troop_set_slot, ":king", ta_goodcommander, false_had_trait),
(try_end),
(try_end),

#Update lords.
(try_for_range, ":lord", kings_begin, kings_end),
    (troop_get_slot, ":ta", ":lord", ta_goodcommander),
(neq, ":ta", false_no_trait),
(try_begin),
    (eq, ":ta", true_has_trait),
(troop_raise_skill, ":lord", "skl_tactics", 3),
(troop_set_slot, ":lord", ta_goodcommander, true_has_trait_bonus),
(else_try),
    (eq, ":ta", false_had_trait_bonus),
(troop_raise_skill, ":lord", "skl_tactics", -3),
(troop_set_slot, ":lord", ta_goodcommander, false_had_trait),
(try_end),
(try_end),
]),
 
apsod said:
Ok great :grin:
What is a trait :roll:
http://dictionary.reference.com/browse/trait

For example, a king may have the "ta_goodcommander" trait which basically gives him +3 to the tactics skill. Each lord and king have different traits.
 
Back
Top Bottom