Advertisement
BigETI

show_recordings.pwn

Nov 26th, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 6.66 KB | None | 0 0
  1. #include <a_samp>
  2. #include <list>
  3.  
  4. #define NO_RESPONSE_DIALOGID    (0)
  5. #define LOAD_RECORDING_DIALOGID (1000)
  6. #define LIST_RECORDING_DIALOGID (1001)
  7.  
  8. #if LOAD_RECORDING_DIALOGID == NO_RESPONSE_DIALOGID
  9.     #error You are not allowed to define "LOAD_RECORDING_DIALOGID" equal "NO_RESPONSE_DIALOGID".
  10. #endif
  11.  
  12. #define MAX_RECORDING_ROWS      (96)
  13. #define NULL_PTR                (Pointer:0)
  14.  
  15. MEM::struct player_info
  16. {
  17.     player_info_time,
  18.     player_info_skin_weapon,
  19.     player_info_vehicle,
  20.     Float:player_info_pos[4],
  21.     Float:player_info_velocity[3],
  22.     player_info_animation
  23. }
  24.  
  25. new LIST::init<player_session[MAX_PLAYERS]>, Pointer:session_ptrs_arr[MAX_PLAYERS] = {NULL_PTR, ...}, listed_events[MAX_PLAYERS] = {0, ...};
  26.  
  27. stock ShowRecording(playerid, ListIt:list_it)
  28. {
  29.     MEM::free(session_ptrs_arr[playerid]);
  30.     if((session_ptrs_arr[playerid] = MEM::calloc(MAX_RECORDING_ROWS)) == NULL_PTR)
  31.     {
  32.         LIST::clear(player_session[playerid]);
  33.         SendClientMessage(playerid, 0xFF0000FF, "An unexpected error has occured.");
  34.         return;
  35.     }
  36.     new title[20], dstr[2042] = "{FF7F00}More\n{7F7F7F}Exit";
  37.     listed_events[playerid] = 0;
  38.     for(new ListIt:t_list_it = list_it; _:t_list_it != LIST_NULL_; t_list_it = ListIt:MEM_EX::get_val(Pointer:(t_list_it)->LIST_IT_data_next))
  39.     {
  40.         if(listed_events[playerid] >= MAX_RECORDING_ROWS) break;
  41.         if(LIST_IT::data_size(t_list_it) != player_info)
  42.         {
  43.             LIST::clear(player_session[playerid]);
  44.             MEM::free(session_ptrs_arr[playerid]);
  45.             session_ptrs_arr[playerid] = NULL_PTR;
  46.             listed_events[playerid] = 0;
  47.             SendClientMessage(playerid, 0xFF0000FF, "Corrupt recording file.");
  48.             return;
  49.         }
  50.         MEM::set_val(session_ptrs_arr[playerid], listed_events[playerid]++, _:t_list_it);
  51.         format(dstr, sizeof dstr, "%s\n%d ms later", dstr, MEM::get_val(LIST_IT::data_ptr(t_list_it), player_info_time));
  52.     }
  53.     if(listed_events[playerid] <= 0)
  54.     {
  55.         LIST::clear(player_session[playerid]);
  56.         MEM::free(session_ptrs_arr[playerid]);
  57.         session_ptrs_arr[playerid] = NULL_PTR;
  58.         listed_events[playerid] = 0;
  59.         SendClientMessage(playerid, 0xFF0000FF, "No more results found.");
  60.         return;
  61.     }
  62.     format(title, sizeof title, "%d %s", listed_events[playerid], (listed_events[playerid] == 1)?("result"):("results"));
  63.     ShowPlayerDialog(playerid, LIST_RECORDING_DIALOGID, DIALOG_STYLE_LIST, title, dstr, "Select", "Exit");
  64. }
  65.  
  66. public OnFilterScriptInit()
  67. {
  68.     print("\n=================================");
  69.     print("= Show recordings filter script =");
  70.     print("=        Made by BigETI         =");
  71.     print("=            Loaded!            =");
  72.     print("=================================\n");
  73.     return 1;
  74. }
  75.  
  76. public OnFilterScriptExit()
  77. {
  78.     for(new i = 0; i < MAX_PLAYERS; i++)
  79.     {
  80.         ShowPlayerDialog(i, -1, DIALOG_STYLE_MSGBOX, "", "", "", "");
  81.         LIST::clear(player_session[i]);
  82.         MEM::free(session_ptrs_arr[i]);
  83.     }
  84.     print("\n=================================");
  85.     print("= Show recordings filter script =");
  86.     print("=        Made by BigETI         =");
  87.     print("=           Unloaded!           =");
  88.     print("=================================\n");
  89.     return 1;
  90. }
  91.  
  92. public OnPlayerDisconnect(playerid, reason)
  93. {
  94.     LIST::clear(player_session[playerid]);
  95.     MEM::free(session_ptrs_arr[playerid]);
  96.     session_ptrs_arr[playerid] = NULL_PTR;
  97.     listed_events[playerid] = 0;
  98. }
  99.  
  100. public OnPlayerCommandText(playerid, cmdtext[])
  101. {
  102.     if(!strcmp("/loadrecording", cmdtext, true, 14))
  103.     {
  104.         ShowPlayerDialog(playerid, LOAD_RECORDING_DIALOGID, DIALOG_STYLE_INPUT, "Load recording", "Copy and paste the recording file into this dialog.", "Load", "Exit");
  105.         return 1;
  106.     }
  107.     return 0;
  108. }
  109.  
  110. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  111. {
  112.     switch(dialogid)
  113.     {
  114.         case LOAD_RECORDING_DIALOGID:
  115.         {
  116.             if(!response) return 1;
  117.             if(LIST::load(player_session[playerid], inputtext)) ShowRecording(playerid, LIST::begin(player_session[playerid]));
  118.             else SendClientMessage(playerid, 0xFF0000FF, "Failed to load session file.");
  119.         }
  120.         case LIST_RECORDING_DIALOGID:
  121.         {
  122.             if(!response)
  123.             {
  124.                 LIST::clear(player_session[playerid]);
  125.                 MEM::free(session_ptrs_arr[playerid]);
  126.                 session_ptrs_arr[playerid] = NULL_PTR;
  127.                 listed_events[playerid] = 0;
  128.                 SendClientMessage(playerid, 0xFF0000FF, "You have left the dialog.");
  129.                 return 1;
  130.             }
  131.             switch(listitem)
  132.             {
  133.                 case 0:
  134.                 {
  135.                     new ListIt:last_it = ListIt:MEM::get_val(session_ptrs_arr[playerid], listed_events[playerid]-1);
  136.                     if(_:last_it == LIST_NULL_ || last_it == LIST::end(player_session[playerid]))
  137.                     {
  138.                         LIST::clear(player_session[playerid]);
  139.                         MEM::free(session_ptrs_arr[playerid]);
  140.                         session_ptrs_arr[playerid] = NULL_PTR;
  141.                         listed_events[playerid] = 0;
  142.                         SendClientMessage(playerid, 0xFF0000FF, "No more results found.");
  143.                         return 1;
  144.                     }
  145.                     ShowRecording(playerid, LIST_IT::next(last_it));
  146.                 }
  147.                 case 1:
  148.                 {
  149.                     LIST::clear(player_session[playerid]);
  150.                     MEM::free(session_ptrs_arr[playerid]);
  151.                     session_ptrs_arr[playerid] = NULL_PTR;
  152.                     listed_events[playerid] = 0;
  153.                     SendClientMessage(playerid, 0xFF0000FF, "You have left the dialog.");
  154.                 }
  155.                 default:
  156.                 {
  157.                     if(listitem < listed_events[playerid]+2)
  158.                     {
  159.                         new buffer[player_info], anim[2][32], title[21], dstr[332];
  160.                         MEM::get_arr(LIST_IT::data_ptr(ListIt:MEM::get_val(session_ptrs_arr[playerid], listitem-2)), _, buffer);
  161.                         GetAnimationName(buffer[player_info_animation], anim[0], sizeof anim[], anim[1], sizeof anim[]);
  162.                         format(dstr, sizeof dstr, "Time after recording: %d\n\nSkin ID: %d\nHolding Weapon ID: %d\nAnimation: %s %s ( ID: %d )", buffer[player_info_time], buffer[player_info_skin_weapon]&0xFFFF, (buffer[player_info_skin_weapon]>>>16)&0xFFFF, anim[0], anim[1], buffer[player_info_animation]);
  163.                         if(buffer[player_info_vehicle]&0xFFFF) format(dstr, sizeof dstr, "%s\n\nVehicle Model: %d\nVehicle Seat ID: %d", dstr, buffer[player_info_vehicle]&0xFFFF, (buffer[player_info_vehicle]>>>16)&0xFFFF);
  164.                         else strcat(dstr, "\n\nNo Vehicle");
  165.                         format(dstr, sizeof dstr, "%s\n\n\nX: %.6f\nY: %.6f\nZ: %.6f\nRotZ: %.6f\n\nVelX: %.6f\nVelY: %.6f\nVelZ: %.6f", dstr, buffer[player_info_pos][0], buffer[player_info_pos][1], buffer[player_info_pos][2], buffer[player_info_pos][3], buffer[player_info_velocity][0], buffer[player_info_velocity][1], buffer[player_info_velocity][2]);
  166.                         format(title, sizeof title, "%d ms later", buffer[player_info_time]);
  167.                         ShowPlayerDialog(playerid, NO_RESPONSE_DIALOGID, DIALOG_STYLE_MSGBOX, title, dstr, "OK", "");
  168.                     }
  169.                     LIST::clear(player_session[playerid]);
  170.                     MEM::free(session_ptrs_arr[playerid]);
  171.                     session_ptrs_arr[playerid] = NULL_PTR;
  172.                     listed_events[playerid] = 0;
  173.                 }
  174.             }
  175.         }
  176.     }
  177.     return 1;
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement