Mount & Blade: Warband (Module system code for lords to age and die)

Users who are viewing this thread


I had Chat AI write a code for the warband so that the lords would age and die, and be replaced by a son from a family member after he dies. Do you think this code module can be integrated into the system and will it work in the game?

Chat Aİ:

In order to write the necessary codes for the aging and death of lords, we must add a class to the module system that will store the age of the lords and update it when any event occurs. The structure of this class could be:

class Lord:
def __init__(self, name, age): = name
self.age = age

def get_age(self):
return self.age

def set_age(self, age):
self.age = age

def increase_age(self):
self.age += 1

Features of this class include keeping lords' names and ages. The increase_age() method is used to update the ages of the lords.

Now we can write the codes for the death of the old lords and the replacement of their sons. For this, you can add a death_chance() method to the Lord class and have this method called as it ages. As a result of this method working, lords who have reached a certain age can be made to die with a random probability. We can also add a special code for the replacement of deceased lords by their sons. In this code, the deceased lord can be replaced by his son of the same name.

import random

class Lord:
def __init__(self, name, age): = name
self.age = age
self.sons = []

def get_age(self):
return self.age

def set_age(self, age):
self.age = age

def increase_age(self):
self.age += 1

def death_chance(self):
if self.age >= 60: #10% chance of death for 60 year old lords
chance = random.randint(1, 10)
if chance == 1:
print(f'{} has died of natural causes.')

def replace_with_son(self):
if self.sons:
# random.randint() makes a random choice between sons.
#so that a certain son of the lord will pass.
son = random.randint(0, len(self.sons)-1)
new_lord = self.sons[son]
print(f'{} has taken over the throne!')

In these code examples, we added a sons property to the Lord class. This attribute is used to hold sons of lords. If there is no lord son, nothing is done because no one can replace him.

For example, at the end of each term, as we increase the age of each lord, we can see that the dead lords are replaced by their sons.
No, that's not working at all, it's not even MaBL-syntax.
In keeping with the MaBL syntax, I wanted lords to age by adding 1 to their age each year, and write code that would cause lords over 60 to die with a random probability, and then any son from a family member would replace the dead lord. I came across such a pile of code. Do you think this works?

from header_common import *

from module_constants import *

from module_scripts import *

# Codes required for lords to age and die

def mod_age_lords():

# Increase the age of lords by 1 year


for i in range(lord_start, lord_end):

lord = troop

if lord is not None:

lord[trp_age] += 1

# If the lord is over 60, she dies with a random probability.

if lord[trp_age] > 60 and not troop_is_hero(lord):

if game_random_get_int(100) < 10:

troop_set_slot(lord, slot_troop_wounded, 1)

troop_set_slot(lord, slot_troop_wounded_time, game_get_hours_per_week() * 4)

troop_set_slot(lord, slot_troop_wounded_by_player, 0)

troop_set_slot(lord, slot_troop_wounded_by_player_time, -1)

# The Lord is succeeded by any son from a family member.

if len(lord[trp_faction][fac_kingdom_ladies]) > 0:

new_lord = game_random_get_item_from_list(lord[trp_faction][fac_kingdom_ladies])

new_lord[trp_age] = 18

new_lord[trp_home] = lord[trp_home]

new_lord[trp_cur_center] = lord[trp_cur_center]

new_lord[trp_banner_scene_prop] = lord[trp_banner_scene_prop]

new_lord[trp_banner_mesh] = lord[trp_banner_mesh]

new_lord[trp_banner_mesh_2] = lord[trp_banner_mesh_2]

new_lord[trp_banner_key] = lord[trp_banner_key]

new_lord[trp_occupation] = slto_kingdom_hero

new_lord[trp_personalityclash_object] = -1

new_lord[trp_personalityclash_state] = -1

new_lord[trp_personalityclash2_object] = -1

new_lord[trp_personalityclash2_state] = -1

new_lord[trp_personalitymatch_object] = -1

new_lord[trp_personalitymatch_state] = -1

except Exception as e:

print("Error in mod_age_lords: " + str(e))
No, the stuff you've posted is all complete nonsense.
Yes, you are right. I didn't tell it to obey the MaBL syntax when printing the code to ai. I wrote the code to match the MaBL syntax, I sent it to the answers section, can you take a look at it? Maybe this is extensible code.
Complete plug n play code with AI in my experience is just not possible, the rest still need human brain. It can give you useful clue though, if you understand what it meant and it somewhat makes sense. It could be a useful learning tool for codes as well before you ask a person what it meant.

For instance I used ChatGPT when trying to make shaders for waving banner from horizontal to vertical (I do not understand HLSL at all), I copied the whole code so the AI understand it first, and it gave me a clue on what exactly to change lol
Top Bottom