/
module_scripts.py
13086 lines (12550 loc) · 661 KB
/
module_scripts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from header_common import *
from header_operations import *
from module_constants import *
from header_parties import *
from header_skills import *
from header_mission_templates import *
from header_items import *
from header_triggers import *
from header_terrain_types import *
from header_music import *
from header_map_icons import *
from header_sounds import *
import header_debug as dbg
import header_lazy_evaluation as lazy
import math
####################################################################################################################
# scripts is a list of script records.
# Each script record contns the following two fields:
# 1) Script id: The prefix "script_" will be inserted when referencing scripts.
# 2) Operation block: This must be a valid operation block. See header_operations.py for reference.
####################################################################################################################
scripts = []
scripts.extend([
("game_start", []), # single player only, not used
("game_get_use_string", # clients: called by the game when the local player is aiming at a usable scene prop
[(store_script_param, ":instance_id", 1),
(try_begin),
(multiplayer_is_server),
(get_player_agent_no, ":my_agent_id"),
(assign, ":stock_count_update_time", 0),
(else_try), # if the targeted prop has a stock count and enough time has passed since the last update, request the current count from the server
(multiplayer_get_my_player, ":my_player_id"),
(player_is_active, ":my_player_id"),
(player_get_agent_id, ":my_agent_id", ":my_player_id"),
(scene_prop_get_slot, ":stock_count_update_time", ":instance_id", slot_scene_prop_stock_count_update_time),
(neq, "$g_game_type", "mt_quick_battle"),
(neq, ":stock_count_update_time", 0),
(store_mission_timer_a, ":current_time"),
(gt, ":current_time", ":stock_count_update_time"),
(val_add, ":current_time", stock_count_check_interval),
(scene_prop_set_slot, ":instance_id", slot_scene_prop_stock_count_update_time, ":current_time"),
(multiplayer_send_int_to_server, client_event_request_stock_count, ":instance_id"),
(try_end),
(scene_prop_get_slot, ":item_id", ":instance_id", slot_scene_prop_item_id),
(scene_prop_get_slot, ":use_string", ":instance_id", slot_scene_prop_use_string),
(try_begin), # if the targeted prop is an item stockpile
(is_between, ":item_id", all_items_begin, all_items_end),
(call_script, "script_scene_prop_get_gold_value", ":instance_id", ":item_id", 0),
(assign, ":gold_value", reg0),
(assign, ":gold_multiplier", reg1),
(try_begin),
(gt, ":use_string", 0),
(try_begin), # for banners, get the associated faction name
(eq, ":use_string", "str_buy_banner_faction"),
(call_script, "script_scene_prop_get_owning_faction", ":instance_id"),
(str_store_faction_name, s1, reg0),
(str_store_string, s0, ":use_string"),
(else_try), # for the export stations in the feudalism game type, display the castle that will benefit
(eq, "$g_game_type", "mt_feudalism"),
(eq, ":use_string", "str_export"),
(call_script, "script_scene_prop_get_owning_faction", ":instance_id"),
(gt, reg1, -1),
(call_script, "script_str_store_castle_name", s1, reg1),
(str_store_string, s0, "str_export_for_s1"),
(else_try), # for props with a custom use string set
(str_store_item_name, s1, ":item_id"),
(assign, reg1, ":gold_value"),
(str_store_string, s0, ":use_string"),
(try_end),
(else_try), # for props with a stock count
(neq, ":stock_count_update_time", 0),
(try_begin),
(eq, "$g_game_type", "mt_quick_battle"),
(str_store_string, s0, "str_buy_sell"),
(else_try),
(eq, "$g_game_type", "mt_no_money"),
(str_store_string, s0, "str_take_put_craft"),
(else_try),
(str_store_string, s0, "str_buy_sell_craft"),
(else_try),
(try_end),
(else_try), # for unlimited buying stations
(try_begin),
(eq, "$g_game_type", "mt_no_money"),
(str_store_string, s0, "str_take"),
(else_try),
(str_store_string, s0, "str_buy"),
(try_end),
(try_end),
(try_begin), # store extra information for script game_get_item_extra_text, called by the show_item_details operation
(neq, ":stock_count_update_time", 0),
(try_begin),
(neq, "$g_game_type", "mt_quick_battle"),
(scene_prop_get_slot, "$g_extra_item_details_1_value", ":instance_id", slot_scene_prop_stock_count),
(assign, "$g_extra_item_details_1_string_id", "str_stock_count_reg0"),
(assign, "$g_extra_item_details_1_color", 0xFF8888DD),
(try_begin), # if a crafting stockpile, calculate the extra reward
(neq, "$g_game_type", "mt_no_money"),
(scene_prop_slot_eq, ":instance_id", slot_scene_prop_is_resource_stockpile, 0),
(call_script, "script_scene_prop_get_item_crafting_refund_reward", ":instance_id"),
(assign, "$g_extra_item_details_2_value", reg1),
(assign, "$g_extra_item_details_2_value_2", reg2),
(try_begin),
(neq, "$g_game_type", "mt_feudalism"),
(assign, "$g_extra_item_details_2_string_id", "str_crafting_refund_reg0_reward_reg1"),
(else_try),
(assign, "$g_extra_item_details_2_string_id", "str_crafting_reward_reg1"),
(try_end),
(try_begin),
(gt, "$g_extra_item_details_2_value_2", 0),
(assign, "$g_extra_item_details_2_color", 0xFFAADD11),
(else_try),
(assign, "$g_extra_item_details_2_color", 0xFF888888),
(try_end),
(else_try), # otherwise if a resource stockpile, check if full or nearly so
(scene_prop_slot_eq, ":instance_id", slot_scene_prop_is_resource_stockpile, 1),
(prop_instance_get_variation_id_2, ":stock_limit", ":instance_id"),
(val_div, ":stock_limit", 10),
(val_mul, ":stock_limit", 100),
(try_begin),
(eq, ":stock_limit", 0),
(else_try),
(ge, "$g_extra_item_details_1_value", ":stock_limit"),
(str_store_string, s0, "str_stockpile_full"),
(else_try),
(val_mul, ":stock_limit", 9),
(val_div, ":stock_limit", 10),
(ge, "$g_extra_item_details_1_value", ":stock_limit"),
(str_store_string, s0, "str_stockpile_nearly_full"),
(try_end),
(try_end),
(try_end),
(try_begin), # calculate the selling price
(neq, "$g_game_type", "mt_no_money"),
(this_or_next|neq, "$g_game_type", "mt_feudalism"),
(scene_prop_slot_eq, ":instance_id", slot_scene_prop_is_resource_stockpile, 0),
(call_script, "script_calculate_stockpile_taxed_price", ":instance_id", ":gold_value"),
(assign, "$g_extra_item_details_3_value", reg0),
(assign, "$g_extra_item_details_3_string_id", "str_selling_price_reg0"),
(assign, "$g_extra_item_details_3_color", 0xFFAA7777),
(try_end),
(try_end),
(agent_get_look_position, pos3, ":my_agent_id"),
(position_get_screen_projection, pos4, pos3),
(show_item_details, ":item_id", pos4, ":gold_multiplier"),
(else_try), # if the targeted prop is a training station, display all the stats
(scene_prop_get_slot, ":troop_id", ":instance_id", slot_scene_prop_troop_id),
(is_between, ":troop_id", playable_troops_begin, playable_troops_end),
(str_store_troop_name_plural, s1, ":troop_id"),
(call_script, "script_scene_prop_get_owning_faction", ":instance_id"),
(assign, ":faction_id", reg0),
(str_store_faction_name, s2, ":faction_id"),
(try_begin),
(gt, ":use_string", 0),
(str_store_string, s0, ":use_string"),
(else_try),
(str_store_string, s0, "str_troop_train"),
(try_end),
(multiplayer_get_my_player, ":player_id"),
(try_begin),
(call_script, "script_cf_can_change_faction", ":player_id", ":faction_id"),
(call_script, "script_cf_player_can_use_troop", ":player_id", ":troop_id"),
(else_try),
(str_store_string, s0, "str_troop_not_available"),
(try_end),
(try_begin),
(neq, "$g_game_type", "mt_no_money"),
(scene_prop_get_slot, ":gold_cost", ":instance_id", slot_scene_prop_gold_value),
(gt, ":gold_cost", 0),
(assign, reg10, ":gold_cost"),
(str_store_string, s0, "str_troop_cost"),
(try_end),
(store_attribute_level, reg10, ":troop_id", ca_strength),
(store_attribute_level, reg11, ":troop_id", ca_agility),
(str_store_string, s0, "str_troop_strength_agility"),
(call_script, "script_store_troop_skills_description", ":troop_id"),
(store_proficiency_level, reg10, ":troop_id", wpt_one_handed_weapon),
(store_proficiency_level, reg11, ":troop_id", wpt_two_handed_weapon),
(store_proficiency_level, reg12, ":troop_id", wpt_polearm),
(store_proficiency_level, reg13, ":troop_id", wpt_archery),
(store_proficiency_level, reg14, ":troop_id", wpt_crossbow),
(store_proficiency_level, reg15, ":troop_id", wpt_throwing),
(str_store_string, s0, "str_troop_weapon_proficiencies"),
(else_try), # for winches, select action string depending on relative position
(this_or_next|eq, ":use_string", "str_winch_lower"),
(eq, ":use_string", "str_winch_drop"),
(call_script, "script_winch_get_direction", ":my_agent_id", ":instance_id"),
(gt, reg0, 0),
(str_store_string, s0, "str_winch_raise"),
(else_try), # for carts, select action string depending on relative position
(eq, ":use_string", "str_attach"),
(call_script, "script_cart_choose_action", ":my_agent_id", ":instance_id"),
(try_begin),
(eq, reg0, 1),
(str_store_string, s0, "str_access"),
(else_try),
(eq, reg0, 0),
(str_store_string, s0, "str_not_close_enough"),
(else_try),
(str_store_string, s0, "str_attach"),
(try_end),
(else_try), # for item destroying piles, adjust string for attached carts or wielded items
(eq, ":use_string", "str_destroy_s1"),
(agent_get_horse, ":attach_agent_id", ":my_agent_id"),
(try_begin),
(le, ":attach_agent_id", -1),
(assign, ":attach_agent_id", ":my_agent_id"),
(try_end),
(agent_get_attached_scene_prop, ":attached_instance_id", ":attach_agent_id"),
(try_begin),
(prop_instance_is_valid, ":attached_instance_id"),
(str_store_string, s0, "str_destroy_all_items_cart"),
(else_try),
(agent_get_wielded_item, ":wielded_item_id", ":my_agent_id", 0),
(try_begin),
(is_between, ":wielded_item_id", all_items_begin, all_items_end),
(str_store_item_name, s1, ":wielded_item_id"),
(else_try),
(agent_get_wielded_item, ":shield_item_id", ":my_agent_id", 1),
(is_between, ":shield_item_id", all_items_begin, all_items_end),
(str_store_item_name, s1, ":shield_item_id"),
(else_try),
(str_clear, s1),
(try_end),
(str_store_string, s0, ":use_string"),
(try_end),
(else_try), # for custom use strings, store the gold value and stock count slots for insertion into it
(gt, ":use_string", 0),
(scene_prop_get_slot, reg1, ":instance_id", slot_scene_prop_gold_value),
(scene_prop_get_slot, reg2, ":instance_id", slot_scene_prop_stock_count),
(str_store_string, s0, ":use_string"),
(else_try), # for castle signs, calculate the name to display
(prop_instance_get_scene_prop_kind, ":scene_prop_id", ":instance_id"),
(eq, ":scene_prop_id", "spr_pw_castle_sign"),
(call_script, "script_scene_prop_get_owning_faction", ":instance_id"),
(try_begin),
(gt, reg1, -1),
(call_script, "script_str_store_castle_name", s0, reg1),
(str_store_faction_name, s1, reg0),
(str_store_string, s0, "str_s0__s1_"),
(else_try),
(prop_instance_get_variation_id_2, ":name_string_id", ":instance_id"),
(val_add, ":name_string_id", castle_names_begin),
(val_min, ":name_string_id", castle_names_end),
(str_store_string, s0, ":name_string_id"),
(try_end),
(else_try), # -1 clears the use string
(eq, ":use_string", -1),
(str_clear, s0),
(else_try), # otherwise fall back to the default string
(str_store_string, s0, "str_use"),
(try_end),
(try_begin), # find the base scene prop a linked prop is targeted
(scene_prop_slot_eq, ":instance_id", slot_scene_prop_show_linked_hit_points, 1),
(scene_prop_get_slot, "$g_show_hit_points_instance_id", ":instance_id", slot_scene_prop_linked_scene_prop),
(prop_instance_is_valid, "$g_show_hit_points_instance_id"),
(else_try),
(assign, "$g_show_hit_points_instance_id", ":instance_id"),
(try_end),
(scene_prop_get_slot, "$g_scene_prop_full_hit_points", "$g_show_hit_points_instance_id", slot_scene_prop_full_hit_points),
(try_begin), # set values to display the hit points bar presentation
(gt, "$g_scene_prop_full_hit_points", 0),
(scene_prop_get_hit_points, "$g_scene_prop_hit_points", "$g_show_hit_points_instance_id"),
(gt, "$g_scene_prop_hit_points", "$g_scene_prop_full_hit_points"),
(assign, "$g_scene_prop_full_hit_points", "$g_scene_prop_hit_points"),
(scene_prop_set_slot, "$g_show_hit_points_instance_id", slot_scene_prop_full_hit_points, "$g_scene_prop_hit_points"),
(try_end),
]),
("store_troop_skills_description", []), # dynamically generate a string listing a troop's skills
("initialize_item_slots", []), # save or calculate item attributes into item slots, for use in calculations in scripts while the game is running
("game_quick_start", # called by the game when starting multiplayer mode, before connecting to a server; used to setup static module data
[
(call_script, "script_initialize_troop_equipment_slots"),
(call_script, "script_initialize_item_slots"),
(call_script, "script_initialize_banner_info"),
(call_script, "script_initialize_game_rules"),
(call_script, "script_initialize_animation_menu_strings"),
(call_script, "script_initialize_animation_durations"),
(call_script, "script_store_profile_troop_equipment"),
]),
("game_set_multiplayer_mission_end", # called when the mission ends
[
(assign, "$g_game_ended", 1),
(assign, "$g_stats_chart_opened_manually", 0),
(try_begin),
(neg|is_presentation_active, "prsnt_tabbed_stats_chart"),
(start_presentation, "prsnt_tabbed_stats_chart"),
(try_end),
]),
("game_enable_cheat_menu", []),
("game_get_console_command", # server: called when console commands are entered (other than hard coded ones)
[(store_script_param, ":command", 1),
(store_script_param, ":value", 2),
(try_begin),
(call_script, "script_cf_execute_command", ":command", ":value"),
(call_script, "script_store_command_string", ":command", reg1),
(else_try),
(str_store_string, s0, reg0),
(try_end),
]),
("game_event_party_encounter", []),
("game_event_simulate_battle", []),
("game_event_battle_end", []),
("game_get_item_buy_price_factor", []),
("game_get_item_sell_price_factor", []),
("game_event_buy_item", []),
("game_event_sell_item", []),
("game_get_troop_wage", []),
("game_get_total_wage", []),
("game_get_join_cost", []),
("game_get_upgrade_xp", []),
("game_get_upgrade_cost", []),
("game_get_prisoner_price", []),
("game_check_prisoner_can_be_sold", []),
("game_get_morale_of_troops_from_faction", []),
("game_event_detect_party", []),
("game_event_undetect_party", []),
("game_get_statistics_line", []),
("game_get_date_text", []),
("game_get_money_text", []),
("game_get_party_companion_limit", []),
("game_reset_player_party_name", []),
("game_get_troop_note", []),
("game_get_center_note", []),
("game_get_faction_note", []),
("game_get_quest_note", []),
("game_get_info_page_note", []),
("game_get_scene_name", # return scene names for display in the server list
[(store_script_param, ":scene_no", 1),
(try_begin),
(multiplayer_is_dedicated_server), # on clients return nothing, so the server will always be asked in case of custom names
(is_between, ":scene_no", scenes_begin, scenes_end),
(store_sub, ":string_id", ":scene_no", scenes_begin),
(val_add, ":string_id", scene_names_begin),
(str_store_string, s0, ":string_id"),
(try_end),
]),
("game_get_mission_template_name",
[(store_script_param, ":mission_template_no", 1),
(try_begin),
(is_between, ":mission_template_no", game_type_mission_templates_begin, game_type_mission_templates_end),
(store_add, ":string_id", ":mission_template_no", game_type_names_begin),
(str_store_string, s0, ":string_id"),
(try_end),
]),
("game_receive_url_response", # called by the game when a response is received from a web server, if used
[(store_script_param, ":integer_count", 1),
(store_script_param, ":string_count", 2),
(try_begin),
(ge, ":integer_count", 1),
(assign, "$g_name_server_enabled", 1),
(assign, ":return_code", reg0),
(try_begin), # negative return codes are internal or configuration errors, not requiring action
(lt, ":return_code", 0),
(try_begin),
(eq, ":return_code", -1),
(ge, ":string_count", 1),
(server_add_message_to_log, "str_name_server_input_error_parameter_s0"),
(else_try),
(server_add_message_to_log, "str_name_server_error_code_reg0"),
(try_end),
(else_try),
(ge, ":integer_count", 3),
(assign, ":player_id", reg1),
(assign, ":unique_id", reg2),
(player_is_active, ":player_id"),
(player_get_unique_id, ":player_unique_id", ":player_id"),
(eq, ":player_unique_id", ":unique_id"),
(try_begin), # normal name server responses
(ge, ":return_code", 0),
(try_begin), # admin permissions were received
(ge, ":integer_count", 4),
(player_is_admin, ":player_id"),
(assign, ":admin_permissions", reg3),
(val_max, ":admin_permissions", 0),
(call_script, "script_player_set_admin_permissions", ":player_id", ":admin_permissions"),
(multiplayer_send_int_to_player, ":player_id", server_event_admin_set_permissions, ":admin_permissions"),
(try_end),
(neq, ":return_code", 0),
(assign, ":rejection_string_id", -1),
(try_begin), # deal with kicking a player for various reasons
(eq, ":return_code", 4),
(assign, ":rejection_string_id", "str_kicked_not_registered"),
(else_try),
(eq, ":return_code", 3),
(assign, ":rejection_string_id", "str_kicked_using_invalid_name"),
(else_try),
(eq, ":return_code", 2),
(assign, ":rejection_string_id", "str_kicked_using_other_clan_tag"),
(else_try),
(eq, ":return_code", 1),
(assign, ":rejection_string_id", "str_kicked_using_other_players_name"),
(try_end),
(neq, ":rejection_string_id", -1),
(multiplayer_send_2_int_to_player, ":player_id", server_event_preset_message, ":rejection_string_id", preset_message_error|preset_message_log),
(store_mission_timer_a, ":time"), # kick the player after a short delay to try ensure they see the rejection message
(val_add, ":time", name_server_kick_delay_interval),
(player_set_slot, ":player_id", slot_player_kick_at_time, ":time"),
(str_store_string, s10, ":rejection_string_id"),
(try_begin),
(lt, ":string_count", 1),
(str_store_string, s0, "str_empty_string"),
(try_end),
(server_add_message_to_log, "str_name_server_log_s10"),
(try_end),
(else_try),
(eq, ":return_code", 0), # reply from server startup check
(else_try),
(server_add_message_to_log, "str_name_server_invalid_response"),
(try_end),
(try_end),
]),
("game_get_cheat_mode", []),
("game_receive_network_message", # called by the game whenever a custom network message is received, both clients and servers
[(store_script_param, ":sender_player_id", 1),
(store_script_param, ":event_type", 2),
(try_begin), # section of events received by clients from the server
(neg|multiplayer_is_server),
(try_begin), # displays preset messages sent from the server as a module string id, rather than the actual text
(eq, ":event_type", server_event_preset_message),
(store_script_param, ":string_id", 3),
(store_script_param, ":flags", 4),
(store_script_param, ":value_1", 5),
(store_script_param, ":value_2", 6),
(call_script, "script_preset_message", ":string_id", ":flags", ":value_1", ":value_2"),
(else_try), # play a non 3D interface sound
(eq, ":event_type", server_event_play_sound),
(store_script_param, ":sound_id", 3),
(try_begin),
(is_between, ":sound_id", 0, "snd_sounds_end"),
(play_sound, ":sound_id"),
(try_end),
(else_try), # play a sound at the location of a scene prop
(eq, ":event_type", server_event_scene_prop_play_sound),
(store_script_param, ":instance_id", 3),
(assign, ":sound_id", ":instance_id"),
(val_rshift, ":sound_id", net_sound_shift), # sound id is the higher bits
(val_and, ":instance_id", net_sound_mask), # instance id is lower bits
(try_begin),
(is_between, ":sound_id", 0, "snd_sounds_end"),
(prop_instance_is_valid, ":instance_id"),
(prop_instance_get_position, pos1, ":instance_id"),
(play_sound_at_position, ":sound_id", pos1),
(try_end),
(else_try), # play a sound at a position, the coordinate values packed into one integer for a smaller network message
(eq, ":event_type", server_event_play_sound_at_position),
(store_script_param, ":sound_id", 3),
(store_script_param, ":packed_position", 4),
(try_begin), # extract sound id and position x,y,z from one number
(is_between, ":sound_id", 0, "snd_sounds_end"),
(assign, ":pos_x", ":packed_position"),
(val_and, ":pos_x", net_pack_3_mask_1),
(assign, ":pos_y", ":packed_position"),
(val_and, ":pos_y", net_pack_3_mask_2),
(val_rshift, ":pos_y", net_pack_3_shift_2),
(assign, ":pos_z", ":packed_position"),
(val_and, ":pos_z", net_pack_3_mask_3),
(val_rshift, ":pos_z", net_pack_3_shift_3),
(val_sub, ":pos_z", net_pack_3_value_upper_bound / 2),
(set_fixed_point_multiplier, 1),
(position_set_x, pos1, ":pos_x"),
(position_set_y, pos1, ":pos_y"),
(position_set_z, pos1, ":pos_z"),
(set_fixed_point_multiplier, 100),
(play_sound_at_position, ":sound_id", pos1),
(try_end),
(else_try), # equip the visual armor mesh on an agent
(eq, ":event_type", server_event_agent_equip_armor),
(store_script_param, ":agent_id", 3),
(store_script_param, ":item_id", 4),
(try_begin),
(agent_is_active, ":agent_id"),
(agent_is_alive, ":agent_id"),
(try_begin),
(gt, ":item_id", -1),
(call_script, "script_agent_equip_armor", ":agent_id", ":item_id"),
(else_try),
(call_script, "script_agent_clean_blood", ":agent_id"),
(try_end),
(try_end),
(else_try), # set a player slot on the client, from the server
(eq, ":event_type", server_event_player_set_slot),
(store_script_param, ":player_id", 3),
(store_script_param, ":slot_no", 4),
(store_script_param, ":value", 5),
(try_begin),
(player_is_active, ":player_id"),
(player_set_slot, ":player_id", ":slot_no", ":value"),
(multiplayer_get_my_player, ":my_player_id"),
(try_begin), # if the player's faction is changed, reset other related slots
(eq, ":slot_no", slot_player_faction_id),
(player_set_slot, ":player_id", slot_player_is_lord, 0),
(player_set_slot, ":player_id", slot_player_has_faction_door_key, 0),
(player_set_slot, ":player_id", slot_player_has_faction_money_key, 0),
(player_set_slot, ":player_id", slot_player_has_faction_item_key, 0),
(player_set_slot, ":player_id", slot_player_can_faction_announce, 0),
(store_script_param, ":change_faction_type", 6),
(try_begin),
(eq, ":change_faction_type", change_faction_type_outlawed),
(try_begin),
(eq, ":player_id", ":my_player_id"),
(call_script, "script_preset_message", "str_you_have_been_outlawed", preset_message_faction|preset_message_log, ":value", 0),
(music_set_situation, mtf_sit_town_infiltrate),
(else_try),
(str_store_player_username, s0, ":player_id"),
(faction_get_color, ":color", "fac_outlaws"),
(display_message, "str_s0_has_been_outlawed", ":color"),
(try_end),
(else_try),
(eq, ":player_id", ":my_player_id"),
(call_script, "script_preset_message", "str_joined_the_s1", preset_message_faction|preset_message_log, ":value", 0),
(try_end),
(try_begin), # if changing faction without changing troop (respawning), re-equip armor to trigger redrawing heraldry
(eq, ":change_faction_type", change_faction_type_no_respawn),
(call_script, "script_player_redraw_heraldic_items", ":player_id"),
(try_end),
(try_begin), # adjust the music style for commoners, outlaws, factions
(eq, ":player_id", ":my_player_id"),
(try_begin),
(ge, ":value", castle_factions_begin),
(music_set_culture, mtf_culture_3),
(else_try),
(eq, ":value", "fac_outlaws"),
(music_set_culture, mtf_culture_2),
(else_try),
(music_set_culture, mtf_culture_1),
(try_end),
(try_end),
(else_try),
(eq, ":slot_no", slot_player_outlaw_rating),
(eq, ":player_id", ":my_player_id"),
(faction_get_color, ":color", "fac_outlaws"),
(assign, reg1, ":value"),
(display_message, "str_your_outlaw_rating_now_reg1", ":color"),
(else_try),
(eq, ":slot_no", slot_player_is_lord),
(eq, ":value", 1),
(player_get_slot, ":faction_id", ":player_id", slot_player_faction_id),
(get_max_players, ":max_players"),
(try_for_range, ":other_player_id", 1, ":max_players"), # remove the status of any previous lord of the faction
(neq, ":other_player_id", ":player_id"),
(player_is_active, ":other_player_id"),
(player_slot_eq, ":other_player_id", slot_player_faction_id, ":faction_id"),
(player_set_slot, ":other_player_id", slot_player_is_lord, 0),
(try_end),
(try_begin), # if the local player is now lord of their faction, set various slots that have already been set on the server
(eq, ":player_id", ":my_player_id"),
(call_script, "script_preset_message", "str_you_are_now_lord_of_s1", preset_message_faction|preset_message_log|preset_message_big, ":faction_id", 0),
(player_set_slot, ":my_player_id", slot_player_has_faction_door_key, 1),
(player_set_slot, ":player_id", slot_player_has_faction_money_key, 1),
(player_set_slot, ":player_id", slot_player_has_faction_item_key, 1),
(player_set_slot, ":player_id", slot_player_can_faction_announce, 1),
(player_set_slot, ":player_id", slot_player_faction_chat_muted, 0),
(else_try), # for other players, just display an announcement
(eq, "$g_preset_message_display_enabled", 1),
(str_store_player_username, s10, ":player_id"),
(call_script, "script_preset_message", "str_s10_now_lord_of_s1", preset_message_faction|preset_message_log|preset_message_big, ":faction_id", 0),
(try_end),
(try_end),
(try_end),
(else_try), # set a troop slot on the client, from the server
(eq, ":event_type", server_event_troop_set_slot),
(store_script_param, ":troop_id", 3),
(store_script_param, ":slot_no", 4),
(store_script_param, ":value", 5),
(troop_get_slot, ":old_value", ":troop_id", ":slot_no"),
(troop_set_slot, ":troop_id", ":slot_no", ":value"),
(try_begin),
(eq, ":troop_id", "trp_mission_data"),
(eq, "$g_preset_message_display_enabled", 1),
(is_between, ":slot_no", slot_mission_data_castle_owner_faction_begin, slot_mission_data_castle_owner_faction_end),
(call_script, "script_preset_message", "str_s1_captured_s2", preset_message_faction_castle|preset_message_big|preset_message_log, ":value", ":slot_no"),
(multiplayer_get_my_player, ":my_player_id"),
(player_is_active, ":my_player_id"),
(player_get_slot, ":my_faction_id", ":my_player_id", slot_player_faction_id),
(try_begin),
(eq, ":value", ":my_faction_id"),
(music_set_situation, mtf_sit_victorious),
(else_try),
(eq, ":old_value", ":my_faction_id"),
(music_set_situation, mtf_sit_encounter_hostile),
(try_end),
(try_end),
(else_try), # set a scene prop slot on the client, from the server
(eq, ":event_type", server_event_scene_prop_set_slot),
(store_script_param, ":instance_id", 3),
(store_script_param, ":slot_no", 4),
(store_script_param, ":value", 5),
(store_script_param, ":slot_range_end", 6),
(try_begin),
(prop_instance_is_valid, ":instance_id"),
(try_begin),
(ge, ":slot_no", 0),
(scene_prop_set_slot, ":instance_id", ":slot_no", ":value"),
(is_between, ":slot_range_end", slot_scene_prop_inventory_begin, slot_scene_prop_inventory_end),
(store_add, ":slot_range_begin", ":slot_no", 1), # messages to change inventory slots can be ranges of repeated values, for efficiency
(ge, ":slot_range_begin", slot_scene_prop_inventory_begin),
(try_for_range, ":current_slot_no", ":slot_range_begin", ":slot_range_end"),
(scene_prop_set_slot, ":instance_id", ":current_slot_no", ":value"),
(try_end),
(try_end), # if the scene prop updated is the inventory currently being accessed, store the changed slots for refreshing the presentation
(eq, ":instance_id", "$g_show_inventory_instance_id"),
(try_begin), # negative numbers mark removed items
(le, ":slot_range_end", -1),
(store_mul, ":slot_moved_from", ":slot_range_end", -1),
(is_between, ":slot_moved_from", slot_scene_prop_inventory_mod_begin, slot_scene_prop_inventory_mod_end),
(scene_prop_set_slot, ":instance_id", ":slot_moved_from", -1),
(assign, "$g_show_inventory_update_needed", 1),
(else_try), # otherwise the item was added to the inventory
(is_between, ":slot_no", slot_scene_prop_inventory_mod_begin, slot_scene_prop_inventory_mod_end),
(assign, "$g_show_inventory_update_needed", 1),
(try_end),
(try_end),
(else_try), # set a faction slot on the client, from the server
(eq, ":event_type", server_event_faction_set_slot),
(store_script_param, ":faction_id", 3),
(store_script_param, ":slot_no", 4),
(store_script_param, ":value", 5),
(try_begin),
(is_between, ":faction_id", factions_begin, factions_end),
(faction_get_slot, ":previous_value", ":faction_id", ":slot_no"),
(faction_set_slot, ":faction_id", ":slot_no", ":value"),
(try_begin),
(eq, ":slot_no", slot_faction_banner_mesh),
(call_script, "script_faction_set_color_from_banner", ":faction_id", ":value"),
(call_script, "script_faction_redraw_heraldic_items", ":faction_id"),
(else_try),
(ge, ":slot_no", slot_faction_relations_begin),
(eq, "$g_preset_message_display_enabled", 1),
(store_sub, ":other_faction_id", ":slot_no", slot_faction_relations_begin),
(lt, ":other_faction_id", factions_end),
(call_script, "script_display_faction_relation_change", ":faction_id", ":other_faction_id", ":previous_value", ":value"),
(try_end),
(try_end),
(else_try), # set an agent slot on the client, from the server
(eq, ":event_type", server_event_agent_set_slot),
(store_script_param, ":agent_id", 3),
(store_script_param, ":slot_no", 4),
(store_script_param, ":value", 5),
(try_begin),
(agent_is_active, ":agent_id"),
(agent_set_slot, ":agent_id", ":slot_no", ":value"),
(try_end),
(else_try), # attach or detach a scene prop to or from an agent (used for carts)
(eq, ":event_type", server_event_set_attached_scene_prop),
(store_script_param, ":agent_id", 3),
(store_script_param, ":instance_id", 4),
(try_begin),
(agent_is_active, ":agent_id"),
(agent_get_attached_scene_prop, ":previous_instance_id", ":agent_id"),
(try_begin),
(prop_instance_is_valid, ":previous_instance_id"),
(scene_prop_set_slot, ":previous_instance_id", slot_scene_prop_attached_to_agent, -1),
(try_end),
(agent_set_attached_scene_prop, ":agent_id", ":instance_id"),
(prop_instance_is_valid, ":instance_id"),
(scene_prop_set_slot, ":instance_id", slot_scene_prop_attached_to_agent, ":agent_id"),
(try_end),
(else_try), # showing the presentation for accessing the inventory of a scene prop
(eq, ":event_type", server_event_show_inventory),
(store_script_param, ":instance_id", 3),
(try_begin), # showing
(gt, ":instance_id", 0),
(prop_instance_is_valid, ":instance_id"),
(assign, "$g_show_inventory_instance_id", ":instance_id"),
(try_for_range, ":mod_slot", slot_scene_prop_inventory_mod_begin, slot_scene_prop_inventory_obj_begin),
(scene_prop_set_slot, ":instance_id", ":mod_slot", 0), # clear slots that notify modifications
(try_end),
(val_add, "$g_last_inventory_unique_id", 1), # this value can be different between server and clients, but is only used locally
(scene_prop_set_slot, ":instance_id", slot_scene_prop_inventory_unique_id, "$g_last_inventory_unique_id"),
(start_presentation, "prsnt_show_inventory"),
(else_try), # hiding, when now out of range or similar
(eq, ":instance_id", -1),
(is_presentation_active, "prsnt_show_inventory"),
(assign, "$g_show_inventory_update_needed", -1),
(try_end),
(else_try), # the server replied that a chat message was received, so if matching the latest message, mark as not requring resending
(eq, ":event_type", server_event_chat_message_recieved),
(store_script_param, ":chat_event_type", 3),
(try_begin),
(troop_get_slot, ":last_chat_event_type", "trp_last_chat_message", slot_last_chat_message_event_type),
(val_and, ":last_chat_event_type", net_chat_event_mask),
(val_and, ":chat_event_type", net_chat_event_mask),
(eq, ":chat_event_type", ":last_chat_event_type"),
(troop_set_slot, "trp_last_chat_message", slot_last_chat_message_not_recieved, 0),
(try_end),
(else_try), # display normal local chat
(eq, ":event_type", server_event_local_chat),
(neg|str_is_empty, s0),
(display_message, s0, local_chat_color),
(call_script, "script_chat_overlay_add_to_local_buffer", local_chat_color),
(else_try), # display shouting in local chat
(eq, ":event_type", server_event_local_chat_shout),
(neg|str_is_empty, s0),
(display_message, s0, local_chat_shout_color),
(call_script, "script_chat_overlay_add_to_local_buffer", local_chat_shout_color),
(else_try), # change the name of the faction which has been previously marked
(eq, ":event_type", server_event_faction_set_name),
(try_begin),
(neg|str_is_empty, s0),
(troop_get_slot, ":faction_id", "trp_mission_data", slot_mission_data_faction_to_change_name_of),
(troop_set_slot, "trp_mission_data", slot_mission_data_faction_to_change_name_of, 0),
(is_between, ":faction_id", castle_factions_begin, factions_end),
(str_store_faction_name, s10, ":faction_id"),
(faction_set_name, ":faction_id", s0),
(eq, "$g_preset_message_display_enabled", 1),
(call_script, "script_preset_message", "str_s10_now_known_as_s1", preset_message_faction|preset_message_log|preset_message_big, ":faction_id", 0),
(try_end),
(else_try), # update the global variables for server settings on the client
(eq, ":event_type", server_event_return_game_rules),
(store_script_param, ":command", 3),
(store_script_param, ":value", 4),
(try_begin),
(call_script, "script_cf_execute_command", ":command", ":value"),
(try_end),
(else_try), # store the server name
(eq, ":event_type", server_event_return_server_name),
(server_set_name, s0),
(else_try), # store the server password
(eq, ":event_type", server_event_return_password),
(server_set_password, s0),
(else_try), # set the stats of existing players when connecting to a server
(eq, ":event_type", server_event_set_player_score_kill_death),
(store_script_param, ":player_id", 3),
(store_script_param, ":score", 4),
(store_script_param, ":kills", 5),
(store_script_param, ":deaths", 6),
(try_begin),
(player_is_active, ":player_id"),
(player_set_score, ":player_id", ":score"),
(player_set_kill_count, ":player_id", ":kills"),
(player_set_death_count, ":player_id", ":deaths"),
(try_end),
(else_try), # show the poll presentation
(eq, ":event_type", server_event_show_poll),
(store_script_param, ":poll_type", 3),
(store_script_param, ":requester_player_id", 4),
(store_script_param, ":value_1", 5),
(store_script_param, ":value_2", 6),
(call_script, "script_show_poll", ":poll_type", ":requester_player_id", ":value_1", ":value_2"),
(else_try), # update the local player's gold amount manually when greater than the game engine limit (13171)
(eq, ":event_type", server_event_set_overflow_gold),
(store_script_param, ":gold_value", 3),
(try_begin),
(neq, "$g_game_type", "mt_no_money"),
(is_between, ":gold_value", max_correctly_displayed_gold + 1, max_possible_gold),
(assign, "$g_overflow_gold_value", ":gold_value"),
(multiplayer_get_my_player, ":my_player_id"),
(player_set_gold, ":my_player_id", ":gold_value"),
(else_try),
(assign, "$g_overflow_gold_value", 0),
(try_end),
(else_try), # display faction chat and announcements
(is_between, ":event_type", server_event_faction_chat, server_event_faction_chat_announce + 1),
(try_begin),
(neg|str_is_empty, s0),
(multiplayer_get_my_player, ":player_id"),
(player_is_active, ":player_id"),
(player_get_slot, ":faction_id", ":player_id", slot_player_faction_id),
(is_between, ":faction_id", castle_factions_begin, factions_end),
(faction_get_color, ":color", ":faction_id"),
(display_message, s0, ":color"),
(try_begin),
(eq, ":event_type", server_event_faction_chat_announce),
(str_store_string_reg, s11, s0),
(start_presentation, "prsnt_faction_lord_message"),
(try_end),
(val_add, "$g_chat_overlay_faction_buffer_stored", 1),
(try_begin),
(neg|is_between, "$g_chat_overlay_faction_buffer_stored", chat_overlay_ring_buffer_begin, chat_overlay_ring_buffer_end),
(assign, "$g_chat_overlay_faction_buffer_stored", chat_overlay_ring_buffer_begin),
(try_end),
(troop_set_plural_name, "$g_chat_overlay_faction_buffer_stored", s0),
(troop_set_slot, "$g_chat_overlay_faction_buffer_stored", slot_chat_overlay_faction_color, ":color"),
(try_end),
(else_try), # display admin chat and announcemnts
(is_between, ":event_type", server_event_admin_chat, server_event_admin_chat_announce + 1),
(neg|str_is_empty, s0),
(display_message, s0, admin_chat_color),
(try_begin),
(eq, ":event_type", server_event_admin_chat_announce),
(str_store_string_reg, s12, s0),
(start_presentation, "prsnt_admin_message"),
(try_end),
(else_try), # convert the packed permissions value into player slots, to limit menu items displayed and similar
(eq, ":event_type", server_event_admin_set_permissions),
(store_script_param, ":permissions", 3),
(multiplayer_get_my_player, ":player_id"),
(player_is_active, ":player_id"),
(call_script, "script_player_set_admin_permissions", ":player_id", ":permissions"),
(else_try), # play a local animation and / or sound
(eq, ":event_type", server_event_local_animation),
(store_script_param, ":player_id", 3),
(store_script_param, ":string_id", 4),
(try_begin),
(player_is_active, ":player_id"),
(is_between, ":string_id", animation_strings_begin, animation_strings_end),
(str_store_player_username, s1, ":player_id"),
(str_store_string, s0, ":string_id"),
(display_message, "str_log_animation", local_animation_color),
(try_end),
(else_try), # update the client side hit points bar when looking at the scene prop; values less than 0 clear attached missiles
(eq, ":event_type", server_event_update_scene_prop_hit_points),
(store_script_param, ":instance_id", 3),
(store_script_param, ":hit_points", 4),
(try_begin),
(prop_instance_is_valid, ":instance_id"),
(try_begin),
(ge, ":hit_points", 0),
(scene_prop_set_hit_points, ":instance_id", ":hit_points"),
(else_try),
(prop_instance_clear_attached_missiles, ":instance_id"),
(scene_prop_get_slot, ":linked_instance_id_1", ":instance_id", slot_scene_prop_linked_scene_prop_1),
(prop_instance_is_valid, ":linked_instance_id_1"),
(prop_instance_clear_attached_missiles, ":linked_instance_id_1"),
(scene_prop_get_slot, ":linked_instance_id_2", ":instance_id", slot_scene_prop_linked_scene_prop_2),
(prop_instance_is_valid, ":linked_instance_id_2"),
(prop_instance_clear_attached_missiles, ":linked_instance_id_2"),
(try_end),
(try_end),
(try_end),
(else_try), # section of events received by server from the clients
(multiplayer_is_server),
(try_begin), # handle players requesting to attach a cart to themselves or a horse
(eq, ":event_type", client_event_attach_scene_prop),
(store_script_param, ":instance_id", 3),
(player_get_agent_id, ":agent_id", ":sender_player_id"),
(try_begin),
(agent_is_active, ":agent_id"),
(agent_is_alive, ":agent_id"),
(agent_get_wielded_item, ":weapon", ":agent_id", 0),
(eq, ":weapon", -1),
(agent_get_wielded_item, ":shield", ":agent_id", 1),
(eq, ":shield", -1),
(try_begin), # detach the currently attached scene prop
(eq, ":instance_id", 0),
(agent_get_horse, ":horse_agent_id", ":agent_id"),
(try_begin),
(eq, ":horse_agent_id", -1),
(assign, ":attach_agent_id", ":agent_id"),
(else_try),
(assign, ":attach_agent_id", ":horse_agent_id"),
(try_end),
(call_script, "script_cf_attach_cart", ":attach_agent_id", -1, ":agent_id"),
(else_try), # try attach
(prop_instance_is_valid, ":instance_id"),
(neg|scene_prop_slot_eq, ":instance_id", slot_scene_prop_required_horse, 0),
(call_script, "script_cart_choose_action", ":agent_id", ":instance_id"),
(try_begin), # cart is in range
(neq, reg0, 0),
(else_try), # if admin wearing special armor, allow attaching from a greater range
(player_is_admin, ":sender_player_id"),
(agent_get_item_slot, ":body_item_id", ":agent_id", ek_body),
(this_or_next|eq, ":body_item_id", "itm_invisible_body"),
(eq, ":body_item_id", "itm_black_armor"),
(agent_get_position, pos1, ":agent_id"),
(prop_instance_get_position, pos2, ":instance_id"),
(position_get_z, ":agent_z", pos1),
(position_set_z, pos2, ":agent_z"),
(get_sq_distance_between_positions, ":sq_distance", pos1, pos2),
(le, ":sq_distance", sq(max_distance_admin_cart)),
(else_try),
(assign, ":instance_id", -1),
(try_end),
(neq, ":instance_id", -1),
(call_script, "script_cf_use_cart", ":agent_id", ":instance_id", -1),
(try_end),
(try_end),
(else_try), # handle players sending control messages for scene props (only ships)
(eq, ":event_type", client_event_control_scene_prop),
(store_script_param, ":instance_id", 3),
(store_script_param, ":forwards", 4),
(store_script_param, ":rotation", 5),
(try_begin),
(prop_instance_is_valid, ":instance_id"),
(call_script, "script_cf_control_ship", ":sender_player_id", ":instance_id", ":forwards", ":rotation"),
(try_end),
(else_try), # reply with the current stock count of a scene prop
(eq, ":event_type", client_event_request_stock_count),
(store_script_param, ":instance_id", 3),
(try_begin),
(prop_instance_is_valid, ":instance_id"),
(scene_prop_get_slot, ":stock_count", ":instance_id", slot_scene_prop_stock_count),
(multiplayer_send_3_int_to_player, ":sender_player_id", server_event_scene_prop_set_slot, ":instance_id", slot_scene_prop_stock_count, ":stock_count"),
(try_end),
(else_try), # transfer an item within the player's equipment and the scene prop's inventory
(eq, ":event_type", client_event_transfer_inventory),
(store_script_param, ":instance_id", 3),
(store_script_param, ":from_slot", 4),
(store_script_param, ":to_slot", 5),
(store_script_param, ":item_id", 6),
(call_script, "script_transfer_inventory", ":sender_player_id", ":instance_id", ":from_slot", ":to_slot", ":item_id"),
(else_try), # transfer money between the player and a money chest
(eq, ":event_type", client_event_transfer_gold),
(try_begin),
(neq, "$g_game_type", "mt_no_money"),
(store_script_param, ":instance_id", 3),
(store_script_param, ":gold_value", 4),
(call_script, "script_cf_use_castle_money_chest", ":sender_player_id", ":instance_id", ":gold_value"),
(try_end),
(else_try), # set the type of the next chat message to be received (since string messages can't have additional information)
(eq, ":event_type", client_event_chat_message_type),
(store_script_param, ":chat_event_type", 3),
(try_begin),
(player_is_active, ":sender_player_id"), # check to ensure the chat event number isn't outdated (from messages received out of order)
(call_script, "script_cf_chat_event_is_new", ":chat_event_type", ":sender_player_id"),
(player_set_slot, ":sender_player_id", slot_player_next_chat_event_type, ":chat_event_type"),
(try_end),
(else_try), # chat string received from a client, from a range of event numbers to keep them in order
(is_between, ":event_type", client_event_chat_message_begin, client_event_chat_message_end),
(try_begin),
(player_is_active, ":sender_player_id"),
(multiplayer_send_int_to_player, ":sender_player_id", server_event_chat_message_recieved, ":event_type"), # confirm to the sending client that the message was received
(call_script, "script_cf_chat_event_is_new", ":event_type", ":sender_player_id"),
(try_begin),
(eq, reg0, 1),
(player_get_slot, ":chat_event_type", ":sender_player_id", slot_player_next_chat_event_type),
(assign, ":chat_event_param_1", ":chat_event_type"), # extract the chat event and extra parameter from on number
(val_rshift, ":chat_event_param_1", net_chat_param_1_shift),
(val_rshift, ":chat_event_type", net_chat_type_shift),
(val_and, ":chat_event_type", net_chat_event_mask),
(else_try),
(assign, ":chat_event_type", chat_event_type_local),
(try_end),
(call_script, "script_chat_event_increment", ":event_type"), # store the next chat event number expected from the player
(player_set_slot, ":sender_player_id", slot_player_next_chat_event_type, reg0),
(neg|str_is_empty, s0),
(try_begin),
(is_between, ":chat_event_type", chat_event_type_local, chat_event_type_local_shout + 1),
(player_get_agent_id, ":agent_id", ":sender_player_id"),
(gt, ":agent_id", -1),
(agent_is_alive, ":agent_id"),
(str_store_player_username, s1, ":sender_player_id"),
(str_store_string, s0, "str_chat_format"),
(server_add_message_to_log, "str_local_chat_log_format"),
(try_begin),
(eq, ":chat_event_type", chat_event_type_local_shout),
(assign, ":max_sq_distance", sq(max_distance_local_chat_shout)),
(assign, ":ambient_sq_distance", sq(ambient_distance_local_chat_shout)),
(assign, ":server_event", server_event_local_chat_shout),
(else_try),
(assign, ":max_sq_distance", sq(max_distance_local_chat)),
(assign, ":ambient_sq_distance", sq(ambient_distance_local_chat)),
(assign, ":server_event", server_event_local_chat),
(try_end),
(set_fixed_point_multiplier, 100),
(agent_get_position, pos1, ":agent_id"),
(position_move_z, pos1, 160),
(try_for_agents, ":other_agent_id"), # send the chat message to other players whoose agents are close enough
(agent_is_alive, ":other_agent_id"),
(neg|agent_is_non_player, ":other_agent_id"),
(agent_get_player_id, ":other_player_id", ":other_agent_id"),
(player_is_active, ":other_player_id"),
(agent_get_position, pos2, ":other_agent_id"),
(position_move_z, pos2, 160),
(get_sq_distance_between_positions, ":sq_distance", pos1, pos2),
(le, ":sq_distance", ":max_sq_distance"),
(this_or_next|le, ":sq_distance", ":ambient_sq_distance"),
(position_has_line_of_sight_to_position, pos1, pos2),
(multiplayer_send_string_to_player, ":other_player_id", ":server_event", s0),
(try_end),
(else_try), # event type to change a faction's name (not really a chat message, but uses the system for more reliability)
(eq, ":chat_event_type", chat_event_type_set_faction_name),
(player_get_slot, ":faction_id", ":sender_player_id", slot_player_faction_id),
(player_get_unique_id, ":unique_id", ":sender_player_id"),
(try_begin),
(faction_slot_eq, ":faction_id", slot_faction_lord_player_uid, ":unique_id"),
(call_script, "script_cf_check_enough_gold", ":sender_player_id", faction_cost_change_name),
(call_script, "script_player_adjust_gold", ":sender_player_id", faction_cost_change_name, -1),
(faction_set_name, ":faction_id", s0),