This is a customizable kit you can use to add a colored team chat to your mod. It currently uses 5 colors, but they can be expanded easily. Feel free to use it or modify it however you please without permission (Some credit would be nice, but it's not necessary ).
About the fix, if my theory was correct, the reason the faction chat was bugging out in PW Mod was due to a high number of mission_template triggers and scripts running simultaneously as well as Low Framerate client-side. Hopefully this update will fix all that, or at least make the message repeat once or twice instead of not showing up at all.
Also, the look of the chat box has been fixed to look almost exactly as the native chats (off by a few pixels). Plus, I've changed it so the text above the box is the same color as your color (thanks to Lazslo et al for the inspiration). Finally, expect to no longer need to click on the chat box after the 1.128 patch (thanks to Vorne for the inside info).
Well, lets get on to the good stuff
header_common
Put these anywhere in header_common.
Add these to the list of multiplayer events (note: if you have defined other events, make sure you adjust the numbers accordingly).
module_presentations
Add this presentation anywhere. If you add more colors, make sure you tweak this script accordingly (there is a comment to tell you where you'll need to update).
module_mission_templates
Add these triggers in whatever gamemodes you need faction chat in.
(Note: you can change the key used to access the chat in this trigger)
module_mission_scripts
Add this script to the bottom of the scripts (before the bracket). This is the script where you'll want to add in the conditions that determine to which faction a player belongs (eg. PW Mod uses armors or hats). You can also add more colors here.
Next look for the script, game_receive_network_message and add these to their respective spots.
Add this to the server events
Add these two to the client events.
If you add more colors, make sure you tweak this script accordingly (there is a comment to tell you where you'll need to update).
Confused? Don't worry, this is what the entire game_receive_network_message script should look like.
http://gk-server.us/game_receive_network_message.txt
Okay, that's all folks! If there are any problems or questions (or praise) let me know
About the fix, if my theory was correct, the reason the faction chat was bugging out in PW Mod was due to a high number of mission_template triggers and scripts running simultaneously as well as Low Framerate client-side. Hopefully this update will fix all that, or at least make the message repeat once or twice instead of not showing up at all.
Also, the look of the chat box has been fixed to look almost exactly as the native chats (off by a few pixels). Plus, I've changed it so the text above the box is the same color as your color (thanks to Lazslo et al for the inspiration). Finally, expect to no longer need to click on the chat box after the 1.128 patch (thanks to Vorne for the inside info).
Well, lets get on to the good stuff
header_common
Put these anywhere in header_common.
Code:
fac_red = 0
fac_white = 1
fac_blue = 2
fac_green = 3
fac_gold = 4
fac_max_fac = 5
Code:
#server
multiplayer_event_new_fac_chat = 113
#client
multiplayer_event_display_fac_chat = 114
multiplayer_event_fac_chat_successful = 115
module_presentations
Add this presentation anywhere. If you add more colors, make sure you tweak this script accordingly (there is a comment to tell you where you'll need to update).
Code:
("send_faction_message",prsntf_manual_end_only, 0,[
(ti_on_presentation_load,
[
(set_fixed_point_multiplier, 1000),
(init_position, pos1),
(str_store_string, s1, "@Send message to current faction:"),
(create_text_overlay, reg1, s1,tf_with_outline),
(overlay_set_color, reg1, 0xFFFFFFFF), #DEFAULT OVERLAY COLORY
#Color factions are related to the hex code for overlay color. IF YOU ADD MORE COLORS UPDATE THIS!
(multiplayer_get_my_player, ":player_no"),
(call_script,"script_get_player_color_faction", ":player_no"),
(try_begin),
(eq,reg0, fac_red),
(overlay_set_color, reg1, 0xFF0000),
(else_try),
(eq,reg0, fac_white),
(overlay_set_color, reg1, 0x000000),
(else_try),
(eq,reg0, fac_blue),
(overlay_set_color, reg1, 0x0000FF),
(else_try),
(eq,reg0, fac_green),
(overlay_set_color, reg1, 0x00FF00),
(else_try),
(eq,reg0, fac_gold),
(overlay_set_color, reg1, 0xFFF500),
(try_end),
(position_set_x, pos1, 200),
(position_set_y, pos1, 530),
(overlay_set_position, reg1, pos1),
(overlay_set_text, reg1, s1),
(position_set_x, pos1, 1000),
(position_set_y, pos1, 1000),
(overlay_set_size, reg1, pos1),
(create_simple_text_box_overlay, "$g_presentation_obj_fac_message", tf_center_justify),
(position_set_x, pos1, 200),
(position_set_y, pos1, 500),
(overlay_set_position, "$g_presentation_obj_fac_message", pos1),
(position_set_x, pos1, 600),
(position_set_y, pos1, 1000),
(overlay_set_size, "$g_presentation_obj_fac_message", pos1),
(overlay_obtain_focus, "$g_presentation_obj_fac_message"),
(assign, "$g_waiting_to_send_fac_chat", 1),
(str_clear, s0),
(overlay_set_text, "$g_presentation_obj_fac_message", s0),
(assign,"$g_waiting_for_confirmation_to_terminate", 1),
(presentation_set_duration, 999999),
]),
(ti_on_presentation_event_state_change,
[(store_trigger_param_1, ":object"),
(try_begin),
(eq,":object", "$g_presentation_obj_fac_message"),
(try_end),
(try_begin),
(neq,"$g_waiting_to_send_fac_chat",1),
(assign, "$RepeatChatUntilSucess", 1),
(str_store_string_reg, s67, s0),
(multiplayer_send_string_to_server, multiplayer_event_new_fac_chat, s0),
(assign, "$g_waiting_for_confirmation_to_terminate", 0),
(presentation_set_duration, 0),
(try_end),
]),
(ti_on_presentation_run,
[(store_trigger_param_1, ":cur_time"),
(try_begin),
(key_clicked, key_escape),
(assign, "$g_waiting_for_confirmation_to_terminate", 0),
(presentation_set_duration, 0),
(assign, "$g_waiting_to_send_fac_chat", 0),
(else_try),
(key_clicked, key_enter),
(assign, "$g_waiting_to_send_fac_chat", 0),
(try_end),
]),
]),
module_mission_templates
Add these triggers in whatever gamemodes you need faction chat in.
Code:
(0.5, 0, 0, [],
[
(try_begin),
(eq, "$RepeatChatUntilSucess", 1),
(multiplayer_send_string_to_server, multiplayer_event_new_fac_chat, s67),
(try_end),
]),
Code:
(0, 0.05, 0, [
(eq, "$g_waiting_for_confirmation_to_terminate", 0),
(multiplayer_get_my_player, ":player_no"),
(player_is_active, ":player_no"),
(key_clicked, key_u),
],
[
(start_presentation, "prsnt_send_faction_message"),
]),
module_mission_scripts
Add this script to the bottom of the scripts (before the bracket). This is the script where you'll want to add in the conditions that determine to which faction a player belongs (eg. PW Mod uses armors or hats). You can also add more colors here.
Code:
#####################################
#get_player_faction
#input: arg1=player id
#output: reg0=player's color faction, returns -1 if no faction.
#####################################
("get_player_color_faction",
[
(store_script_param_1, ":player_no"),
(player_get_agent_id, ":agent_no", ":player_no"),
(assign, reg0, -1),
(try_begin), #RED
#INSERT CONDITIONS HERE
(assign, reg0, fac_red),
(else_try), #WHITE
#INSERT CONDITIONS HERE
(assign, reg0, fac_white),
(else_try), #BLUE
#INSERT CONDITIONS HERE
(assign, reg0, fac_blue),
(else_try), #GREEN
#INSERT CONDITIONS HERE
(assign, reg0, fac_green),
(else_try), #GOLD
#INSERT CONDITIONS HERE
(assign, reg0, fac_gold),
(try_end),
]),
Next look for the script, game_receive_network_message and add these to their respective spots.
Add this to the server events
Code:
(else_try),
(eq, ":event_type", multiplayer_event_new_fac_chat),
(try_begin), ###Get sender players color
(str_store_player_username, s1,":player_no"),
(str_store_string, s4, "@[{s1}] {s0}"),
(server_add_message_to_log, s4),
(call_script, "script_get_player_color_faction", ":player_no"),
(assign, ":player_fac", reg0),
(get_max_players, ":players"), #Get destination players' color based on color faction
(try_for_range, ":dest_player_no", 1, ":players"),
(try_begin),
(player_is_active, ":dest_player_no"),
(call_script, "script_get_player_color_faction", ":dest_player_no"),
(eq, reg0, ":player_fac"),
(multiplayer_send_string_to_player, ":dest_player_no", multiplayer_event_display_fac_chat, s4),
(try_end),
(try_end),
(multiplayer_send_message_to_player, ":player_no", multiplayer_event_fac_chat_successful),
(try_end),
Add these two to the client events.
If you add more colors, make sure you tweak this script accordingly (there is a comment to tell you where you'll need to update).
Code:
(else_try),
(eq, ":event_type", multiplayer_event_display_fac_chat),
(multiplayer_get_my_player, ":player_no"),
(assign, reg0, fac_gold), ###DEFAULT COLOR
(call_script, "script_get_player_color_faction", ":player_no"),
#Color factions are related to the hex code for color displayed. IF YOU ADD MORE COLORS, UPDATE THIS!!!
(try_begin),
(eq,reg0, fac_red),
(display_message, s0, 0xFF0000),
(else_try),
(eq,reg0, fac_white),
(display_message, s0, 0x000000),
(else_try),
(eq,reg0, fac_blue),
(display_message, s0, 0x0000FF),
(else_try),
(eq,reg0, fac_green),
(display_message, s0, 0x00FF00),
(else_try),
(eq,reg0, fac_gold),
(display_message, s0, 0xFFF500),
(try_end),
Code:
(else_try),
(eq, ":event_type", multiplayer_event_fac_chat_successful),
(assign, "$RepeatChatUntilSucess", 0),
Confused? Don't worry, this is what the entire game_receive_network_message script should look like.
http://gk-server.us/game_receive_network_message.txt
Okay, that's all folks! If there are any problems or questions (or praise) let me know