Ideas for simple Random Events?

Users who are viewing this thread

Lyx

Sergeant
It's no secret that the roleplaying aspect of MnB is rather.... repetitive. Quite quickly, you've seen everything, are just running from one battle to the next, and do repetitive missions simply so that certain numbers change, not because its a task you like to do. One way to change that would be more variety in generic quests - but because of how the module system is organized and it's syntax, quests require a lot of effort to implement.

So, today i had a little idea - people who've played sandbox games like pirates, or certain 4x games, are probably aware of random events. You just from time to time get a random popup which informs you that something happened, some stats or stuff changes in the world, and thats it. It's like in one of those board games where you draw a random card from a deck, which tells you about some special event which happened, and which changes stuff.

Now, the nice thing about such random events is that they are trivial to implement, because they require no user interaction and no scene setups, no state-tracking of stuff, and all that crap. It's just a dialog which pops up, you get to click "continue..." , some consequences get applied, and done. Actually, they're so trivial to implement, that its more work to come up with ideas and write nice texts, than to implement them.

I've just spent the last 2 hours setting up a simple system for such random events. I can add events to the pool with just a few lines of code at one single central place (instead of stuff scathered around the module system, as its often the case). What i currently can do is:

1. have a pool of events from which one can be randomly choosen every 2 weeks.
2. When an event is triggered, check if certain conditions are met.
3. Display a notification dialog which shows some text.
4. Apply simple consequences.

Why would one want something like that? Well, you'd want it if you would like the life in the game to be made a bit more variable and colorful, by adding simple random stuff. Just some small things which break the routine.

So, here's your task: What kind of simple random events can you think of? Remember, we're NOT talking about missions, encounters and stuff.... we're just talking about "fire-and-forget" events which require no more presentation than some text. Also, we're not talking about very specific events which only apply in a small amount of situations or have huge and complex consequences - we're talking about small random generic stuff which can happen to (almost) everyone anytime.

Brainstorm ahead! :smile:

-----

Currently implemented simple random events:
- Fire in village/town
- Good harvest in village
- Good trading in city
- Lost piece of art found
- Disease in village/town contained/cured
- Player/Companion training accident

Current WIP source snapshot (you need the module system for this):

Put this somewhere (i prefer end) in simple triggers:
Code:
#---BEGIN LYX RANDOM EVENTS---
(1 * 6,[	# interval currently set to 6 hours for testing  - should be 14 * 24 for normal play

	# Init
	# ---------------------------------------------------------------------------
	(assign, ":total_events", 7),	# update this when adding/removing events!
	(val_add, ":total_events", 1),	# MnB has weird ideas of ranges
	(store_random_in_range, ":curr_event", 0, ":total_events"),
	(neq, ":curr_event", "$g_lyx_last_random_event"),	# ignore event if same as last
	(assign, "$g_lyx_last_random_event", ":curr_event"),
	(assign, ":pos", 0),
	(try_begin), (eq,1,2),	# dummy


	# Events
	# ---------------------------------------------------------------------------

	# --- FIRE IN CITY OR VILLAGE ---
	(else_try),	(val_add,":pos",1), (eq,":pos",":curr_event"),	# this first line is same for all events
		(call_script, "script_get_random_center_of_lord", "trp_player", 4),
		(assign, ":center_no", reg0),
		(neq,":center_no",-1),	# skip event if player has no matching center
		(call_script, "script_get_player_distance_to_center", ":center_no"), (ge,reg0,8),	# abort if player is close
		(str_store_party_name, s5, ":center_no"),
		(dialog_box, "@A messenger informs you that there was a fire in {s5}. It's under control now, but it may take a while until the damage is repaired.", "@Fire in one of your fiefs:"),
		(call_script, "script_change_center_prosperity", ":center_no", -25),

	# --- VILLAGE GOOD HARVEST ---
	(else_try),	(val_add,":pos",1), (eq,":pos",":curr_event"),	# this first line is same for all events
		(call_script, "script_get_random_center_of_lord", "trp_player", 1),
		(assign, ":center_no", reg0),
		(neq,":center_no",-1),	# skip event if player has no matching center
		(call_script, "script_get_center_prosperity", ":center_no"), (le,reg0,75),	# abort if center is already rich
		(str_store_party_name, s5, ":center_no"),
		(dialog_box, "@The village of {s5} had a great harvest recently and the locals managed to trade well. Their prosperity has improved!", "@Good Harvest:"),
		(call_script, "script_change_center_prosperity", ":center_no", 25),

	# --- CITY GOOD TRADE / LOST ART FOUND---
	(else_try),	(val_add,":pos",1), (eq,":pos",":curr_event"),	# this first line is same for all events
		(call_script, "script_get_random_center_of_lord", "trp_player", 2),
		(assign, ":center_no", reg0),
		(neq,":center_no",-1),	# skip event if player has no matching center
		(call_script, "script_get_center_prosperity", ":center_no"), (le,reg0,75),	# abort if center is already rich
		(str_store_party_name, s5, ":center_no"),
		(store_random_in_range, ":rand_num", 1, 2),
		(try_begin),
			(eq,":rand_num",1), (dialog_box, "@The merchant caravans of {s5} managed to do very profitable trading recently. {s5}'s wealth has benefited significantly from this!", "@Good Trading:"),
		(else_try),
			(eq,":rand_num",2), (dialog_box, "@A famous piece of art, which was long been thought lost, was found near {s5}! It is currently on display in {s5} and people are coming from all over Calradia to see it. The merchants are profiting greatly from this surge in visitors.", "@Lost art found:"),
		(try_end),
		(call_script, "script_change_center_prosperity", ":center_no", 25),

	# --- DISEASE ---
	(else_try),	(val_add,":pos",1), (eq,":pos",":curr_event"),	# this first line is same for all events
		(call_script, "script_get_random_center_of_lord", "trp_player", 4),
		(assign, ":center_no", reg0),
		(neq,":center_no",-1),	# skip event if player has no matching center
		(call_script, "script_get_player_distance_to_center", ":center_no"), (ge,reg0,8),	# abort if player is close
		(call_script, "script_get_player_relation_with_center", ":center_no"), (ge,reg0,-30),	# abort if center hates you already
		(str_store_party_name, s5, ":center_no"),
		(dialog_box, "@A messenger informs you that a painful disease has broken out in {s5}. A surgeon was sent, but was unable to find a cure. All he could do, was to contain the plague by seperating the healthy from the sick. The quarantine was succesful, but the trust of {s5}'s people in you, has suffered.", "@Disease contained:"),
		(call_script, "script_change_player_relation_with_center", ":center_no", -6),

	# --- DISEASE AVERTED ---
	(else_try),	(val_add,":pos",1), (eq,":pos",":curr_event"),	# this first line is same for all events
		(call_script, "script_get_random_center_of_lord", "trp_player", 4),
		(assign, ":center_no", reg0),
		(neq,":center_no",-1),	# skip event if player has no matching center
		(call_script, "script_get_player_distance_to_center", ":center_no"), (ge,reg0,8),	# abort if player is close
		(call_script, "script_get_player_relation_with_center", ":center_no"), (le,reg0,30),	# abort if center loves you already
		(str_store_party_name, s5, ":center_no"),
		(dialog_box, "@A messenger informs you that a painful disease had broken out in {s5}. However, a surgeon was sent and managed to find a cure for the plague. The people of {s5} are grateful for how this evil was handled, and their trust in you has improved!", "@Disease averted:"),
		(call_script, "script_change_player_relation_with_center", ":center_no", 6),

	# --- COMPANION INJURED ---
	(else_try),	(val_add,":pos",1), (eq,":pos",":curr_event"),	# this first line is same for all events
		(call_script, "script_get_random_hero_in_playerparty"),
		(assign, ":troop_no", reg0),
		(neq,":troop_no",-1),	# skip event if no companion in party
		(call_script, "script_get_troop_health",":troop_no"), (ge,reg0,60),	# abort if companion is already weak
		(str_store_troop_name, s5, ":troop_no"),
		(dialog_box, "@{s5} was accidently injured during today's training. The wounds aren't severe, but it may take some time for {s5} to be in top form again.", "@Training accident:"),
		(call_script, "script_change_troop_health", ":troop_no", -40),

	# --- PLAYER INJURED ---
	(else_try),	(val_add,":pos",1), (eq,":pos",":curr_event"),	# this first line is same for all events
		(call_script, "script_get_troop_health", "trp_player"), (ge,reg0,60),	# abort if player is already weak
		(dialog_box, "@During today's training, you were accidently injured. While the wounds aren't severe, it may take some time for them to heal.", "@Training accident:"),
		(call_script, "script_change_troop_health", "trp_player", -40),

	# Closing
	# --------------------------------------
	(try_end),
]),
#---END LYX RANDOM EVENTS---

And this somewhere (i.e. end) in scripts:
Code:
#---BEGIN LYX HELPER-SCRIPTS---

	#script to get a troop's health
	#INPUT: arg1 = troop_no
	#OUTPUT: reg0 - health percentage
	("get_troop_health",[
		(store_script_param, ":troop_no", 1),
		(store_troop_health, reg0, ":troop_no")
	]),

	#script to modify a troop's health
	#INPUT: arg1 = troop_no, arg2 = health percentage modifier
	#OUTPUT: none
	("change_troop_health",[
		(store_script_param, ":troop_no", 1),
		(store_script_param, ":modifier", 2),
		(store_troop_health, ":troop_hp",":troop_no"),
		(val_add, ":troop_hp", ":modifier"),
		(val_clamp, ":troop_hp", 1, 100),
		(troop_set_health, ":troop_no", ":troop_hp"),
	]),

	#script to get a prosperity of a center
	#INPUT: arg1 = troop_no
	#OUTPUT: reg0 - prosperity (0-100)
	("get_center_prosperity",[
		(store_script_param, ":troop_no", 1),
		(party_get_slot, reg0, ":troop_no", slot_town_prosperity),
	]),

	#script to get player relation with faction
	#INPUT: arg1 = faction_no
	#OUTPUT: reg0 - relation
	("get_player_relation_with_faction",[
		(store_script_param, ":faction_no", 1),
        (store_relation, reg0, ":faction_no", "fac_player_supporters_faction"),
	]),

	#script to get player relation with center
	#INPUT: arg1 = center_no
	#OUTPUT: reg0 - relation
	("get_player_relation_with_center",[
		(store_script_param, ":center_no", 1),
		(party_get_slot, reg0, ":center_no", slot_center_player_relation),
	]),

	#script to get player distance between player and a center
	#INPUT: arg1 = center_no
	#OUTPUT: reg0 - distance
	("get_player_distance_to_center",[
		(store_script_param, ":center_no", 1),
		(store_distance_to_party_from_party, reg0, "p_main_party", ":center_no"),
	]),


	#script to get a random hero in player's party
	#INPUT: none
	#OUTPUT: reg0 = troop_no
	("get_random_hero_in_playerparty",[
		# create list of all heroes in player party
		(assign, ":pos", 0),
		(try_for_range,":troop_no",companions_begin,heroes_end),
			(troop_slot_eq, ":troop_no", slot_troop_occupation, slto_player_companion),
			(troop_set_slot, "trp_temp_array_a", ":pos", ":troop_no"),
			(val_add, ":pos", 1),
		(try_end),
		# pick one randomly or output -1 if none found
		(try_begin),
			(eq,":pos",0), (assign,reg0,-1),
		(else_try),
			(val_add, ":pos", 1),
			(store_random_in_range, ":rand_pos", 0, ":pos"),
			(troop_get_slot, reg0, "trp_temp_array_a", ":rand_pos"),
		(try_end),
	]),


	#script to get a random center owned by a lord (may be "trp_player") (by ConstantA & Lyx)
	#INPUT: arg1 = troop_no, arg2 = mode (0=all, 1=village, 2=city, 3=castle. 4=city or village, 5=city or castle)
	#OUTPUT: reg0 - center_no or -1 if none available
	("get_random_center_of_lord",[
		(store_script_param, ":troop_no", 1),
		(store_script_param, ":mode", 2),
		(assign, ":pos", 0),

		# consider villages?
		(try_begin),
			(this_or_next|eq,":mode",0),
			(this_or_next|eq,":mode",1),
			(eq,":mode",4),
			(try_for_range, ":center_no", villages_begin, villages_end),
				(party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
				(troop_set_slot, "trp_temp_array_a", ":pos", ":center_no"),
				(val_add, ":pos", 1),
			(try_end),
		(try_end),
		

		# consider cities?
		(try_begin),
			(this_or_next|eq,":mode",0),
			(this_or_next|eq,":mode",2),
			(eq,":mode",5),
			(try_for_range, ":center_no", towns_begin, towns_end),
				(party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
				(troop_set_slot, "trp_temp_array_a", ":pos", ":center_no"),
				(val_add, ":pos", 1),
			(try_end),
		(try_end),

		# consider castles?
		(try_begin),
			(this_or_next|eq,":mode",0),
			(this_or_next|eq,":mode",3),
			(eq,":mode",5),
			(try_for_range, ":center_no", castles_begin, castles_end),
				(party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
				(troop_set_slot, "trp_temp_array_a", ":pos", ":center_no"),
				(val_add, ":pos", 1),
			(try_end),
		(try_end),

		# pick random from gathered list, or return -1 if none available (none owned by the troop)
		(try_begin),
			(eq,":pos",0), (assign,reg0,-1),
		(else_try),
			(val_add, ":pos", 1),
			(store_random_in_range, ":rand_pos", 0, ":pos"),
			(troop_get_slot, reg0, "trp_temp_array_a", ":rand_pos"),
		(try_end),
	]),
	
#---END LYX HELPER-SCRIPTS---

This SHOULD be savegame compatible, but i haven't tested that.
 
Just something that came to my mind:

-Wanted criminal found and hanged
-Failed murder attemp of a random lord
-Bad harvest in a village (consquense could be a less prosperity)
-Fire in a  town (consquense could be a less prosperity)
-Found of acient artefact/art
-Disease in a random settlement (consquense could be a less prosperity)
 
Cruger said:
-Wanted criminal found and hanged
Hmm, not sure this would be interesting without some kind of random pool of names (which is out of my scope). However, the idea may be interesting in combination with something else. Let's say YOUR men found a wanted criminal in YOUR city... then we may have some consequences, so that the anonymity of the criminal suddenly isn't such a big deal anymore :smile:

-Failed murder attemp of a random lord
Also interesting, but problem is that it would over the course of time seem weird that there are only failed assassination attempts, but no successful ones :smile: Then again, i may try to implement the "successfull murder" at a later time, by simply handling it as if the party of a lord got destroyed and the lord escaped.

-Bad harvest in a village (consquense could be a less prosperity)
-Fire in a  town (consquense could be a less prosperity)
-Disease in a random settlement (consquense could be a less prosperity)
Already on it, and will do it as soon as i find out how to select a random PLAYER town/village. There seem to be no existing scripts for this, and i don't know yet how to abuse the iterators to do something like that. Still, its just a matter of time, since i'll need random selection of player villages/towns anyways. I'll also implement the opposite version (more prosperity) so that its balanced.

-Found of acient artefact/art
Also interesting, if the text-description is atmospheric enough.

You know, compared with your ideas, i so far have come up with just boring stuff:
- one of your companions has a minor accident
- find some cargo which apparently was left behind by someone who needed to get away fast
- some of the arena heroes visit one of your towns and arrange a tournament
 
Lyx said:
Already on it, and will do it as soon as i find out how to select a random PLAYER town/village. There seem to be no existing scripts for this, and i don't know yet how to abuse the iterators to do something like that. Still, its just a matter of time, since i'll need random selection of player villages/towns anyways. I'll also implement the opposite version (more prosperity) so that its balanced.

Why does it only need to be player settlements that can have this? In my opinion having it for all settlements would be more interesting.

I can't really get my brain to do any coding right know, but I know you can randomly select one of the players settlements in some way.

Also a random pool of names should be easy enough if you just take a look at how they did it with making random names for the quest where you have to go and find a dude in a village and then kill him.
 
(thank you board, for putting my reply in the trashcan. Oh well, second try)

Cruger said:
Why does it only need to be player settlements that can have this? In my opinion having it for all settlements would be more interesting.
The main selling point of random events to me is, that they're easy to implement and require no complex code. Stuff really stays simple. If events can apply to AI lords as well, then a few problems arise:

- The event fired, and none will be triggered again for 14 days, unless exception code is added which handles AI events different -> more complexity.

- If the event involves choices, then it must be handled differently, because AI-lords dont choose the same way as a player does (no dialogs and stuff) -> more complexity.

I prefer to grab for the low hanging fruits here - try to get the most out of as little complexity and effort as possible.

I can't really get my brain to do any coding right know, but I know you can randomly select one of the players settlements in some way.
Well, i found a way to do it, but its dirty. Problem is: In other languages, what you would do is iterate over all centers, and store those belonging to the player in a NEW ARRAY. Then randomly pick from that new array. But i am not aware of a method to do this -locally- with the module system (so, without again setting up globals somewhere and spreading code across the module system).

The dirty method which i'm currently using involves a recursive scriptcall. Pick a random center, check if belongs to the player. If yes, break. If not, call the function again - until a center belonging to the player was picked. Thats really dirty and has an infinitely small potential of turning into an iloop. But well - to quote from my code comments "What else are you gonna do in a HL assembly language, which lacks the flexibility of assembly?" :wink:

Also a random pool of names should be easy enough if you just take a look at how they did it with making random names for the quest where you have to go and find a dude in a village and then kill him.
Oh, thanks for the info! With a bit of luck the generator code is in a seperate script, which i can just recycle. I'll look into this!
 
Lyx are you still working on this ?? http://forums.taleworlds.com/index.php/topic,83415.0.html

 
Lyx said:
Problem is: In other languages, what you would do is iterate over all centers, and store those belonging to the player in a NEW ARRAY. Then randomly pick from that new array. But i am not aware of a method to do this -locally- with the module system (so, without again setting up globals somewhere and spreading code across the module system).

Code:
#script_get_random_players_center
#INPUT: none
#OUTPUT: reg0 - center_no
("get_random_players_center",
[
(assign, ":pos", 0),
(try_for_range, ":center_no", centers_begin, centers_end),
(party_slot_eq, ":center_no", slot_town_lord, "trp_player"),
(troop_set_slot, "trp_temp_array_a", ":pos", ":center_no"),
(val_add, ":pos", 1),
(try_end),
(val_add, ":pos", 1),
(store_random_in_range, ":rand_pos", 0, ":pos"),
(troop_get_slot, reg0, "trp_temp_array_a", ":rand_pos"),
]),


 
@dzorro: Depending on what you mean with "this"...

Minimalistic Kingdom Management Kit:
1. Formal war declaration not yet implemented (secondary to me, because its purely aesthetic)
2. Recruiting lords if relation is high enough not yet implemented (still planning to do that)
3. Making companions vassals not yet implemented (still planning to do that)
4. Companion clashes disabled and companion wage x4. Done but not yet posted.
5. Upload source for diffing, instead of the currently posted manual instructions - not yet done.

I will probably do 4. and 5. during the next weeks. Doing 1-3. could take a while.

Own gameplay mod which sticks close to pre 1.0 native, based on above kingdom kit:
- this thread is part of that :smile:

-------

@ConstantA:
Doh, (ab-)using troops as temporary arrays. Thats about the last thing i would have thought of. Thank you!
 
Update: i am thinking about dropping the feature of letting the player choose between two options. There are two ways to handle anonymous text messages: present it as a dynamic game menu(send text via string registers), or use dialogboxes/questionboxes. In both cases, everything is handled in simple triggers in one single trigger. Problem is: menus do not seem to return to the calling simple trigger, after they are closed, so i cannot apply consequences afterwards (at least not in the caller). Same goes for questionboxes - if i understand this right, then the trigger script will not wait for the answer - instead, i'd need to handle the answer elsewhere. I do however not want to handle events and consequences in seperate places.

To give you an idea how simple and easy noninteractive random events are...

Init Section - this is only required once - the global is currently first initiated during game start.
Code:
(1 * 12,[	# currently set to 12 hours for testing

	# Init
	# ---------------------------------------------------------------------------
	(assign, ":total_events", 1),	# update this when adding/removing events!		
	(store_random_in_range, ":curr_event", 0, ":total_events"),
	# avoid repeating the same event in a row
	(try_begin),
		(eq, ":curr_event", "$g_lyx_last_random_event"),
		(val_add, ":curr_event", 1),
		(val_min, ":curr_event", ":total_events"),
	(try_end),
	# update last event tracker and setup cursor for walking through all events
	(assign, "$g_lyx_last_random_event", ":curr_event"),
	(assign, ":cursor", 0),	
	# No event if 0 was rolled:
	(try_begin), (eq, ":cursor", ":curr_event"),

This is how a single event looks like - the event list is just a series of such blocks:
Code:
	# Events
	# ---------------------------------------------------------------------------

	# Fire in village/town
	(else_try), (val_add, ":cursor", 1), (eq, ":cursor", ":curr_event"),	# this first line is same for all events
		(call_script, "script_check_player_has_center_reg0"),
		(eq,reg0,1),
		(call_script, "script_random_player_center_reg0"),
		(assign,":center",reg0),
		(call_script, "script_change_center_prosperity", ":center", -20),
		(str_store_party_name, s5, ":center"),
		(dialog_box, "@A messenger informs you that there has been a fire in {s5}. It is under control now, but it may take a while until the damage is repaired.", "@Fire in one of your fiefs"),

Closing of the trigger
Code:
	# Closing
	# --------------------------------------
	(try_end),
]),
 
I think a really good random event would be to have two lords have a falling out- you could force a conflict between them without making their factions go to war (i think). If this was a regular thing, then the player would stumble on it eventaully, and you could have a 'microwave quest' (this is what I call low-effort M&B repetitive quests) to solve the dispute one way or the other.

I know you want simplke stuff- but this is simple, it would just take time to write dialogue and adjust the codes. Still. Its an idea.
 
Okay, events working now:
- fire in village/town
- good village harvest
- good town trading
- disease in village/town contained (quarantine) (bad)
- disease in village/town averted (cure) (good)
 
Lyx,
menus didnt return to the simple triggers call them, so we must handle the consequences on another triggerps.
We can use global variables to accomodate. Let it $g_randomevent. Let initiate it to be 0, then in the event menus called by triggers, different answers set the variable to different values. We can use more global variable for complex events.
Last, we make  a simple trigger that checked everytime, and if the $g_randomevent greater than 0 (an event has accured), handle the consequences.
Code:
(0, [(gt, $g_randomevent, 0),
(try_begin),
   (eq, $g_randomevent, 1),
   ...
   (assign, $g_randomevent, 0),
(else_try),
   (eq, $g_randomevent, 2),
   ...
   (assign, $g_randomevent, 0),
(try_end),
]),
 
Well, i guess one could work around it and still keep the event definitions in one place, if one moves the event definitions into a script (instead of a simple trigger), and then gives the script different states, controlled by the global which you proposed (i had such a global already, but didn't know how to use if after the menu took over).

This would look someway like this:

1st global:
- last fired random event number

2nd global:
- state of the last fired random event (0=main, 1=user choosed option 1, 2=user choosed option 2)

1st simple trigger:
- activated every 2 weeks
- just randomly chooses an event and calls the randomevent script

2nd simple trigger:
- always checks if the 2nd global is in another state than 0. If yes, then triggers the randomevent script again.

Randomevent script:
- has all the event definitions, with each event having up to 3 sections (0=main, 1=option1 choosen, 2=option2 choosen)

menu:
- multipurpose menu which is fed via string registers
- if options are used, then on player click sets the 2nd global into state 1 or 2.

-----

I guess that would work - though i'm not exactly happy about the involved buerocracy. I mean, we're up from 1 global and 1 simple trigger with one level of state..., to 2 globals, 2 triggers, a script with two levels of state and a menu - just to handle if a player pressed button 1 or button 2. I'm feel kinda split about this... on the ond hand, interactivity would make random events more personal, on the other hand the required buerocracy isn't really what i'd consider "elegant" and "clean".

Hmm, could we someway cut out the ugly feeding of a menu via string registers, and instead use a choice dialog? Or would that make it even more complicated?
 
Ok, here it is my idea that may be can be added as a random event.
When player party is near a friendly town, an event may be triggered. Let say one of our troops have a conflict with civilians from the town. Well, let add the event possibility to be triggered if main party's morale is low.
Then player s given options. Apologize to the lord own the town-> lower morale and renown. Or, ignore the event-> relation with the town and the lord own the town lower.
 
First post updated.

I tried to implement a better idea of what i wrote in my prev post, but ran into new issues which would again require more complexity in the event definition. So, i decided to drop the feature of letting the player choose between multiple options - besides, its not like most simple events need such a feature.
 
i could need some help, because i dont get this bug.

Code:
	#script to get number of centers owned by a lord (may be "trp_player")
	#INPUT: arg1 = troop_no, arg2 = mode (0=all, 1=village, 2=city, 3=castle. 4=city or village, 5=city or castle)
	#OUTPUT: reg0 - num of centers
	("get_num_of_lord_centers",[
		(store_script_param, ":troop_no", 1),
		(store_script_param, ":mode", 2),
		(assign, ":count", 0),

		# consider villages?
		(try_begin),
			(this_or_next|eq,":mode",0),
			(this_or_next|eq,":mode",1),
			(eq,":mode",4),
			(try_for_range, ":center_no", villages_begin, villages_end),
				(party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
				(val_add, ":count", 1),
  	(display_message, "@village found"),
			(try_end),

		# consider cities?
		(else_try),
			(this_or_next|eq,":mode",0),
			(this_or_next|eq,":mode",2),
			(eq,":mode",5),
			(try_for_range, ":center_no", towns_begin, towns_end),
				(party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
				(val_add, ":count", 1),
  	(display_message, "@city found"),
			(try_end),

		# consider castles?
		(else_try),
			(this_or_next|eq,":mode",0),
			(this_or_next|eq,":mode",3),
			(eq,":mode",5),
			(try_for_range, ":center_no", castles_begin, castles_end),
				(party_slot_eq, ":center_no", slot_town_lord, ":troop_no"),
				(val_add, ":count", 1),
  	(display_message, "@castle found"),
			(try_end),

		(try_end),

		# return number
		(assign,reg0,":count"),
	]),
When i run this code in a dialog, and choose mode 5 (cities and castles), with me owning a city and castle, only the city is recognized as belonging to me. Do i need to check ownership of castles (or even villages belonging to castles?) differenty?
 
I think native module system has similar script already, "print_troop_owned_centers_in_numbers_to_s0".
Based on the script you can make new script with your desired output.
 
thanks for the hint, but i just noticed the error - its a really stupid one..... its the control structure. It stops considering center types as soon as one matches :smile: First post updated because a similiar bug was also present there.
 
This has just given me a weird idea- what if those annoying companion clashes could be resolved by a simple quest-esque task? Like making Borcha and Nizar do some constructive team excersise (like helping each other out in battle?)

Ahem, yes, anyway...

Random Events

Plague across an area of the map- if you cross it your troops catch it and start dying. (give more use to the first aid skill maybe)
One of your companions has an old enemy, whose party spawns and attacks yours- killing said old enemy boosts your companion's morale.
You find some happy, lost cattle- take them to a village for massive relation boost or feast on beef. (mmm, beef)
A shifty look type approaches you in a tavern, and promises to open the gates of castle x for cash y ( a much easier castle assualt ensues)
Kingdom X suffers a peasant uprising in village Y -(oppertunity to join village to your kingdom? Or money to be made crushing them?)
You gain a rival within whichever kingdom you're associated with, who sneakilly attacks you at every oppertunity (until you kill him- mwahahaha)

I could go on, but tired now.

 
Back
Top Bottom