#script_wse_console_command_received
# Called each time a command is typed on the dedicated server console or received with RCON (after parsing standard commands)
# INPUT
# script param 1 = command type (0 - local, 1 - remote)
# s0 = text
# OUTPUT
# trigger result = anything non-zero if the command succeeded
# result string = message to display on success (if empty, default message will be used)
("wse_console_command_received", [
(store_script_param, ":command_type", 1),
(assign, ":size", 10),
(try_begin),
(str_equals, s0, "@create"),
(array_create, "$ar", 0, ":size", 2), #integer, 2D array - 10x2
(try_for_range, ":i", 0, ":size"),
(try_for_range, ":j", 0, 2),
(store_random_in_range, ":val", 0, 15),
(array_set_val, "$ar", ":val", ":i", ":j"), #just some random numbers
(try_end),
(try_end),
(else_try),
(str_equals, s0, "@free"),
(array_free, "$ar"),
(else_try),
(str_equals, s0, "@sort"),
(array_sort, "$ar", sort_m_int_asc, 0), #Sort 2D array using [x][0]
(else_try),
(str_equals, s0, "@sort2"),
(array_sort, "$ar", sort_m_int_asc, 1), #Sort 2D array using [x][1]
(else_try),
(str_equals, s0, "@psort"),
(array_create, ":tmp", 2, 0), #positions, 1D array - empty
(init_position, pos10), #-> 0,0,0
(display_message, "@--- creating pos array ---"),
(try_for_range, reg0, 0, 10),
(store_random_in_range, reg1, 0, 20),
(store_random_in_range, reg2, 0, 20),
(store_random_in_range, reg3, 0, 20),
(position_set_x, pos0, reg1),
(position_set_y, pos0, reg2),
(position_set_z, pos0, reg3),
(array_push, ":tmp", pos0),
(get_distance_between_positions, reg4, pos0, pos10),
(display_message, "@{reg0} - x: {reg1}, y: {reg2}, z: {reg3}, distance from 0,0,0: {reg4}"),
(try_end),
(array_sort_custom, ":tmp", "script_cmp_pos"),
(display_message, "@--- sorted pos array ---"), #should be in reverse order, since we are poping from the back of the array.
(try_for_range, reg0, 0, 10),
(array_pop, pos0, ":tmp"),
(position_get_x, reg1, pos0),
(position_get_y, reg2, pos0),
(position_get_z, reg3, pos0),
(get_distance_between_positions, reg4, pos0, pos10),
(display_message, "@{reg0} - x: {reg1}, y: {reg2}, z: {reg3}, distance from 0,0,0: {reg4}"),
(try_end),
(array_free, ":tmp"),
(else_try),
(str_equals, s0, "@show"),
(display_message, "@-----------"),
(try_for_range, reg1, 0, ":size"),
(str_store_string, s0, "@ - [{reg1}]|"),
(try_for_range, reg2, 0, 2),
(array_get_val, reg0, "$ar", reg1, reg2),
(str_store_string, s0, "@{s0} [{reg2}]: {reg0}"),
(try_end),
(display_message, s0),
(try_end),
(try_end),
]),
("cmp_pos", [ #sorts by distance from origin (0,0,0)
(init_position, pos10),
(get_distance_between_positions, ":a", pos0, pos10),
(get_distance_between_positions, ":b", pos1, pos10),
(try_begin),
(le, ":a", ":b"),
(return_values, 1),
(else_try),
(return_values, 0),
(try_end),
]),