OSP Code SP Color Coded Messages: Updated 6-DEC-08 [Modder Resource]

Users who are viewing this thread

HardCode

Master Knight
Updated 6-DEC-2008

This resource will color code important messages based on the event type and whether it is positive, negative, or neutral to the player. I've done some preliminary testing, but report any logical flaws or inconsistencies here.

To use this resource, first copy this script into module_scripts:

Code:
# HC - Script to figure out what color a display message should be
("get_message_color", [  
	(store_script_param, ":news_type", 1),	# See News Types in module_constants
	(store_script_param, ":entity", 2),		# The troop or town in question

	# Set a default color
	(assign, reg20, 0xFFFFFFFF),
	(assign, ":color", reg20),

	# Get the player's faction
	(store_troop_faction, ":player_faction", "trp_player"),

	(try_begin),
		# news_lord_defeated = 1
		# ":entity" is the troop id of the captured lord
		(eq, ":news_type", news_lord_defeated),
		(store_troop_faction, ":lord_faction", ":entity"),
		(try_begin),
			(eq, ":lord_faction", ":player_faction"),
			(assign, ":color", color_bad_news),
		(else_try),
			(store_relation, ":relation", ":lord_faction", ":player_faction"),
			(lt, ":relation", 0),
			(assign, ":color", color_good_news),
		(else_try),
			(assign, ":color", color_neutral_news),
		(try_end),

	(else_try),
		# news_lord_captured = 2
		# ":entity" is the troop id of the captured lord
		(eq, ":news_type", news_lord_captured),
		(store_troop_faction, ":lord_faction", ":entity"),
		(try_begin),
			(eq, ":lord_faction", ":player_faction"),
			(assign, ":color", color_terrible_news),
		(else_try),
			(store_relation, ":relation", ":lord_faction", ":player_faction"),
			(lt, ":relation", 0),
			(assign, ":color", color_great_news),
		(else_try),
			(assign, ":color", color_neutral_news),
		(try_end),

	(else_try),
		# news_lord_freed = 3
		(eq, ":news_type", news_lord_freed),
		(store_troop_faction, ":lord_faction", ":entity"),
		(try_begin),
			(eq, ":lord_faction", ":player_faction"),
			(assign, ":color", color_great_news),
		(else_try),
			(store_relation, ":relation", ":lord_faction", ":player_faction"),
			(lt, ":relation", 0),
			(assign, ":color", color_terrible_news),
		(else_try),
			(assign, ":color", color_neutral_news),
		(try_end),

	(else_try),
		# news_lord_escaped = 4
		(eq, ":news_type", news_lord_escaped),

	(else_try),
		# news_village_looted = 5
		# ":entity" is the village number
		(eq, ":news_type", news_village_looted),		
		(store_faction_of_party,":center_faction",":entity"),
		(try_begin),
			(eq, ":center_faction", ":player_faction"),
			(assign, ":color", color_bad_news),
		(else_try),
			(store_relation, ":relation", ":center_faction", ":player_faction"),
			(lt, ":relation", 0),
			(assign, ":color", color_good_news),
		(else_try),
			(assign, ":color", color_neutral_news),
		(try_end),

	(else_try),
		# news_center_captured = 6
		# ":entity" is ":root_defeated_party".
		(eq, ":news_type", news_center_captured),
		(store_faction_of_party,":defeated_center_faction",":entity"),
		(try_begin),
			(eq, ":defeated_center_faction", ":player_faction"),
			(assign, ":color", color_terrible_news),
		(else_try),
			(store_relation, ":relation", ":defeated_center_faction", ":player_faction"),
			(lt, ":relation", 0),
			(assign, ":color", color_great_news),
		(else_try),
			(assign, ":color", color_neutral_news),
		(try_end),

	(else_try),
		# news_center_under_siege = 7
		# ":entity" is the ai_object, which appears to be the center under siege
		(eq, ":news_type", news_center_under_siege),		
		(store_faction_of_party,":center_faction",":entity"),
		(try_begin),
			(eq, ":center_faction", ":player_faction"),
			(assign, ":color", color_bad_news),
		(else_try),
			(store_relation, ":relation", ":center_faction", ":player_faction"),
			(lt, ":relation", 0),
			(assign, ":color", color_good_news),
		(else_try),
			(assign, ":color", color_neutral_news),
		(try_end),

	(else_try),
		# news_center_siege_lifted = 8
		# ":entity" is the center number
		(eq, ":news_type", news_center_siege_lifted),		
		(store_faction_of_party,":center_faction",":entity"),
		(try_begin),
			(eq, ":center_faction", ":player_faction"),
			(assign, ":color", color_good_news),
		(else_try),
			(store_relation, ":relation", ":center_faction", ":player_faction"),
			(lt, ":relation", 0),
			(assign, ":color", color_bad_news),
		(else_try),
			(assign, ":color", color_neutral_news),
		(try_end),

	(else_try),
		# news_center_prosperity_changed = 9
		# ":entity" is the center number
		(eq, ":news_type", news_center_prosperity_changed),		
		(party_get_slot, ":center_lord", ":entity", slot_town_lord),
		(try_begin),
			(eq, ":center_lord", "trp_player"),
			(assign, ":color", color_good_news),
		(else_try),
			(assign, ":color", 0xFFFFFFFF),
		(try_end),

	(try_end),

	(assign, reg20, ":color"),
]),

Then, copy these constants into module_constants (You can change the hex color values as desired.):

Code:
########################################################
##  COLOR CODES             ############################
########################################################
# HC - Add in color codes
color_great_news = 0x00FF00
color_good_news = 0x50FF50
color_terrible_news = 0xFF2222
color_bad_news = 0xFF5050
color_neutral_news = 0xFFAA00
color_quest_and_faction_news = 0x66CCFF
color_hero_news = 0xFFFF00

########################################################
##  NEWS TYPES              ############################
########################################################
# HC - Just an enumeration of news types to be used as a script parameter
news_lord_defeated = 1
news_lord_captured = 2
news_lord_freed = 3
news_lord_escaped = 4
news_village_looted = 5
news_center_captured = 6
news_center_under_siege = 7
news_center_siege_lifted = 8
news_center_prosperity_changed = 9

Finally, do a search on "display_" in all module files that contain scripting code (ex. module_dialogs, module_scripts, module_game_menus), and call the script before displaying the message. Be sure to use the correct constant and entity as the script parameters. For example, in script "game_event_simulate_battle":

Code:
# HC - Select the message color based on the circumstances. reg20 holds the color.
(call_script, "script_get_message_color", news_lord_captured, ":cur_troop_id"),
(display_log_message, "str_hero_taken_prisoner", reg20),
#(display_log_message, "str_hero_taken_prisoner"),

Some messages are obviously bad news, such as prisoners escaping, so apply the color constants directly to those messages. There is also a quest and faction related constant for messages when the Marshall changes or cattle are delivered. You'll have to find them and apply the color constants.

Example 1 in module_simple_triggers:
Code:
(try_begin),
    (lt, "$g_player_follow_army_warnings", 8),
    (display_message, "@You must follow {s1}!", color_quest_and_faction_news),
(else_try),
    (display_message, "@You must follow {s1}! This is your last warning!", color_terrible_news),
(try_end),

Example 2 in module_simple_triggers:
Code:
    (display_message, "@{s1} is scouted.", color_quest_and_faction_news),
 

HardCode

Master Knight
Update: I had to make a "fix". I intended for the prosperity messages to stay white, like Native, but accidentally changed them to orange if the property isn't yours. I've updated the last "try" block, changing the color to 0xFFFFFFFF.
 

HardCode

Master Knight
It's so much easier focusing on the messages this way. You immediately know if there is good news, bad news, great news, or terrible news. And easy to catch messages for Renown and Morale gained (or lost!)
 

Garnier

Sergeant
I've been using it and I just got this:
67386439ob4.png
 

HardCode

Master Knight
Check what values you are passing to the script. Make sure that you are passing the correct troop ID/center ID/etc in the calls to the script. That's actually one of the hard parts, and one each modder must figure out because there are way too many calls to display_message and display_log_message for me to post in any way that would make sense.

Also, I don't recall if I copied the most recent version of the code, so I did so now. Also, I've tweaked the colors a little bit, so they show up better if you shrink your on-screen text size in font_data.xml.
 
Top Bottom