Advertisement
Guest User

Singleplayer Collectibles

a guest
Aug 31st, 2016
570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.43 KB | None | 0 0
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3. #include    <izcmd>         // by Yashas - http://forum.sa-mp.com/showthread.php?t=576114
  4. #include    <YSI\y_ini>     // by Y_Less - http://forum.sa-mp.com/showthread.php?t=570884
  5.  
  6. #define     COLLECTIBLE_REWARD      (250)       // $250 for each collectible collected
  7. #define     COMPLETION_REWARD       (15000)     // $15000 reward if somebody collects all collectibles of one type
  8.  
  9. enum    _:E_COLLECTIBLE_DIALOG
  10. {
  11.     DIALOG_COLLECTIBLES_MENU = 24555,
  12.     DIALOG_COLLECTIBLES_PROGRESS,
  13.     DIALOG_COLLECTIBLES_PROGRESS_2,
  14.     DIALOG_COLLECTIBLES_RESET,
  15.     DIALOG_COLLECTIBLES_RESET_2
  16. }
  17.  
  18. enum    E_COLLECTIBLE_TYPE
  19. {
  20.     typeName[16],
  21.     typeModel
  22. }
  23.  
  24. enum    E_COLLECTIBLE
  25. {
  26.     colType,
  27.     Float: colX,
  28.     Float: colY,
  29.     Float: colZ,
  30.     colPickup
  31. }
  32.  
  33. enum    _:E_COLLECTIBLE_TYPE_REF
  34. {
  35.     TYPE_OYSTER,    // reference to CollectibleTypes index 0
  36.     TYPE_HORSESHOE  // reference to CollectibleTypes index 1
  37. }
  38.  
  39. new
  40.     CollectibleTypes[][E_COLLECTIBLE_TYPE] = {
  41.     //  {name, model id}
  42.         {"Oyster", 953},    // index 0
  43.         {"Horseshoe", 954}  // index 1
  44.     };
  45.  
  46. new
  47.     CollectibleData[][E_COLLECTIBLE] = {
  48.     //  {type, pos x, pos y, pos z}
  49.         {TYPE_HORSESHOE, 1224.0, 2617.0, 11.0},
  50.         {TYPE_HORSESHOE, 2323.0, 1284.0, 97.0},
  51.         {TYPE_HORSESHOE, 2035.0, 2305.0, 18.0},
  52.         {TYPE_HORSESHOE, 2491.0, 2263.0, 15.0},
  53.         {TYPE_HORSESHOE, 1433.0, 2796.0, 20.0},
  54.         {TYPE_HORSESHOE, 2071.0, 712.0, 11.0},
  55.         {TYPE_HORSESHOE, 2239.0, 1839.0, 18.0},
  56.         {TYPE_HORSESHOE, 2583.0, 2387.0, 16.0},
  57.         {TYPE_HORSESHOE, 2864.0, 857.0, 13.0},
  58.         {TYPE_HORSESHOE, 2612.0, 2200.0, -1.0},
  59.         {TYPE_HORSESHOE, 2274.0, 1507.0, 24.0},
  60.         {TYPE_HORSESHOE, 2184.0, 2529.0, 11.0},
  61.         {TYPE_HORSESHOE, 1863.0, 2314.0, 15.0},
  62.         {TYPE_HORSESHOE, 2054.0, 2434.0, 166.0},
  63.         {TYPE_HORSESHOE, 1603.0, 1435.0, 11.0},
  64.         {TYPE_HORSESHOE, 1362.92, 1015.24, 11.0},
  65.         {TYPE_HORSESHOE, 2058.7, 2159.1, 16.0},
  66.         {TYPE_HORSESHOE, 2003.0, 1672.0, 12.0},
  67.         {TYPE_HORSESHOE, 2238.0, 1135.0, 49.0},
  68.         {TYPE_HORSESHOE, 1934.06, 988.79, 22.0},
  69.         {TYPE_HORSESHOE, 1768.0, 2847.0, 9.0},
  70.         {TYPE_HORSESHOE, 1084.0, 1076.0, 11.0},
  71.         {TYPE_HORSESHOE, 2879.0, 2522.0, 11.0},
  72.         {TYPE_HORSESHOE, 2371.0, 2009.0, 15.0},
  73.         {TYPE_HORSESHOE, 1521.0, 1690.0, 10.6},
  74.         {TYPE_HORSESHOE, 2417.0, 1281.0, 21.0},
  75.         {TYPE_HORSESHOE, 1376.0, 2304.0, 15.0},
  76.         {TYPE_HORSESHOE, 1393.0, 1832.0, 12.34},
  77.         {TYPE_HORSESHOE, 984.0, 2563.0, 12.0},
  78.         {TYPE_HORSESHOE, 1767.0, 601.0, 13.0},
  79.         {TYPE_HORSESHOE, 2108.0, 1003.0, 46.0},
  80.         {TYPE_HORSESHOE, 2705.98, 1862.52, 24.41},
  81.         {TYPE_HORSESHOE, 2493.0, 922.0, 16.0},
  82.         {TYPE_HORSESHOE, 1881.0, 2846.0, 11.0},
  83.         {TYPE_HORSESHOE, 2020.0, 2352.0, 11.0},
  84.         {TYPE_HORSESHOE, 1680.3, 2226.86, 16.11},
  85.         {TYPE_HORSESHOE, 1462.0, 936.0, 10.0},
  86.         {TYPE_HORSESHOE, 2125.5, 789.23, 11.45},
  87.         {TYPE_HORSESHOE, 2588.0, 1902.0, 15.0},
  88.         {TYPE_HORSESHOE, 919.0, 2070.0, 11.0},
  89.         {TYPE_HORSESHOE, 2173.0, 2465.0, 11.0},
  90.         {TYPE_HORSESHOE, 2031.25, 2207.33, 11.0},
  91.         {TYPE_HORSESHOE, 2509.0, 1144.0, 19.0},
  92.         {TYPE_HORSESHOE, 2215.0, 1968.0, 11.0},
  93.         {TYPE_HORSESHOE, 2626.0, 2841.0, 11.0},
  94.         {TYPE_HORSESHOE, 2440.08, 2161.07, 20.0},
  95.         {TYPE_HORSESHOE, 1582.0, 2401.0, 19.0},
  96.         {TYPE_HORSESHOE, 2077.0, 1912.0, 14.0},
  97.         {TYPE_HORSESHOE, 970.0, 1787.0, 11.0},
  98.         {TYPE_HORSESHOE, 1526.22, 751.0, 29.04},
  99.         {TYPE_OYSTER, 979.0, -2210.0, -3.0},
  100.         {TYPE_OYSTER, 2750.0, -2584.0, -5.0},
  101.         {TYPE_OYSTER, 1279.0, -806.0, 85.0},
  102.         {TYPE_OYSTER, 2945.13, -2051.93, -3.0},
  103.         {TYPE_OYSTER, 67.0, -1018.0, -5.0},
  104.         {TYPE_OYSTER, 2327.0, -2662.0, -5.0},
  105.         {TYPE_OYSTER, 2621.0, -2506.0, -5.0},
  106.         {TYPE_OYSTER, 1249.0, -2687.0, -1.0},
  107.         {TYPE_OYSTER, 725.0, -1849.0, -5.0},
  108.         {TYPE_OYSTER, 723.0, -1586.0, -3.0},
  109.         {TYPE_OYSTER, 155.0, -1975.0, -8.0},
  110.         {TYPE_OYSTER, 1968.0, -1203.0, 17.0},
  111.         {TYPE_OYSTER, -2657.0, 1564.0, -6.0},
  112.         {TYPE_OYSTER, -1252.0, 501.0, -8.0},
  113.         {TYPE_OYSTER, -1625.0, 4.0, -10.0},
  114.         {TYPE_OYSTER, -1484.0, 1489.0, -10.0},
  115.         {TYPE_OYSTER, -2505.406, 1543.724, -22.5553},
  116.         {TYPE_OYSTER, -2727.0, -469.0, -5.0},
  117.         {TYPE_OYSTER, -1266.0, 966.0, -10.0},
  118.         {TYPE_OYSTER, -1013.0, 478.0, -7.0},
  119.         {TYPE_OYSTER, -1364.0, 390.0, -5.0},
  120.         {TYPE_OYSTER, 2578.0, 2382.0, 16.0},
  121.         {TYPE_OYSTER, 2090.0, 1898.0, 8.0},
  122.         {TYPE_OYSTER, 2130.0, 1152.0, 7.0},
  123.         {TYPE_OYSTER, 2013.0, 1670.0, 7.0},
  124.         {TYPE_OYSTER, 2531.0, 1569.0, 9.0},
  125.         {TYPE_OYSTER, 2998.0, 2998.0, -10.0},
  126.         {TYPE_OYSTER, -832.0, 925.0, -2.0},
  127.         {TYPE_OYSTER, 486.0, -253.0, -4.0},
  128.         {TYPE_OYSTER, -90.0, -910.0, -5.0},
  129.         {TYPE_OYSTER, 26.43, -1320.94, -10.04},
  130.         {TYPE_OYSTER, -207.0, -1682.0, -8.0},
  131.         {TYPE_OYSTER, -1672.0, -1641.0, -2.0},
  132.         {TYPE_OYSTER, -1175.0, -2639.0, -2.5},
  133.         {TYPE_OYSTER, -1097.0, -2858.0, -8.0},
  134.         {TYPE_OYSTER, -2889.0, -1042.0, -9.0},
  135.         {TYPE_OYSTER, -659.0, 874.0, -2.0},
  136.         {TYPE_OYSTER, -955.0, 2628.0, 35.0},
  137.         {TYPE_OYSTER, -1066.0, 2197.0, 32.0},
  138.         {TYPE_OYSTER, 40.0, -531.0, -8.0},
  139.         {TYPE_OYSTER, -765.0, 247.0, -8.0},
  140.         {TYPE_OYSTER, 2098.0, -108.0, -2.0},
  141.         {TYPE_OYSTER, 2767.0, 470.0, -8.0},
  142.         {TYPE_OYSTER, -783.0, 2116.0, 35.0},
  143.         {TYPE_OYSTER, -821.0, 1374.0, -8.0},
  144.         {TYPE_OYSTER, -2110.5, 2329.72, -7.5},
  145.         {TYPE_OYSTER, -1538.0, 1708.0, -3.27},
  146.         {TYPE_OYSTER, -2685.0, 2153.0, -5.0},
  147.         {TYPE_OYSTER, 796.0, 2939.0, -5.0},
  148.         {TYPE_OYSTER, 2179.0, 235.0, -5.0}
  149.     };
  150.  
  151. new
  152.     CollectiblePicked[MAX_PLAYERS][ sizeof(CollectibleData) ];
  153.  
  154. GetCollectedCount(playerid, type)
  155. {
  156.     new count = 0;
  157.     for(new i; i < sizeof(CollectibleData); i++) if(CollectibleData[i][colType] == type && CollectiblePicked[playerid][i] > 0) count++;
  158.     return count;
  159. }
  160.  
  161. GetCollectibleCount(type)
  162. {
  163.     new count = 0;
  164.     for(new i; i < sizeof(CollectibleData); i++) if(CollectibleData[i][colType] == type) count++;
  165.     return count;
  166. }
  167.  
  168. LoadPlayerProgress(playerid)
  169. {
  170.     for(new i; i < sizeof(CollectibleData); i++) CollectiblePicked[playerid][i] = 0;
  171.    
  172.     new file[48], name[MAX_PLAYER_NAME];
  173.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  174.     format(file, sizeof(file), "collectibles/%s.ini", name);
  175.     if(!fexist(file)) SavePlayerProgress(playerid);
  176.     INI_ParseFile(file, "ReadCollectibleProgress", .bExtra = true, .extra = playerid);
  177.     return 1;
  178. }
  179.  
  180. SavePlayerProgress(playerid)
  181. {
  182.     new file[48], name[MAX_PLAYER_NAME];
  183.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  184.     format(file, sizeof(file), "collectibles/%s.ini", name);
  185.    
  186.     new INI: fHandle = INI_Open(file), key[24];
  187.     if(fHandle != INI_NO_FILE)
  188.     {
  189.         INI_SetTag(fHandle, "CollectibleData");
  190.  
  191.         for(new i; i < sizeof(CollectibleData); ++i)
  192.         {
  193.             format(key, sizeof(key), "ColPicked_%d", i);
  194.             INI_WriteInt(fHandle, key, CollectiblePicked[playerid][i]);
  195.         }
  196.  
  197.         INI_Close(fHandle);
  198.     }
  199.    
  200.     return 1;
  201. }
  202.  
  203. ShowMenu(playerid, menu_id = DIALOG_COLLECTIBLES_MENU, extra_id = -1)
  204. {
  205.     switch(menu_id)
  206.     {
  207.         case DIALOG_COLLECTIBLES_PROGRESS:
  208.         {
  209.             new string[196];
  210.             format(string, sizeof(string), "Type\tCollected\tTotal\n");
  211.             for(new i; i < sizeof(CollectibleTypes); i++) format(string, sizeof(string), "%s%s\t%d\t%d\n", string, CollectibleTypes[i][typeName], GetCollectedCount(playerid, i), GetCollectibleCount(i));
  212.             ShowPlayerDialog(playerid, menu_id, DIALOG_STYLE_TABLIST_HEADERS, "Collectibles » {FFFFFF}Progress", string, "Select", "Back");
  213.         }
  214.        
  215.         case DIALOG_COLLECTIBLES_PROGRESS_2:
  216.         {
  217.             new string[2048], col_name[16], title[36];
  218.             format(col_name, sizeof(col_name), "%s", CollectibleTypes[extra_id][typeName]);
  219.             format(title, sizeof(title), "Collectibles » {FFFFFF}%ss", col_name);
  220.  
  221.             for(new i, idx; i < sizeof(CollectibleData); i++)
  222.             {
  223.                 if(CollectibleData[i][colType] != extra_id) continue;
  224.                 format(string, sizeof(string), "%s%s %d\t%s\n", string, col_name, idx + 1, (CollectiblePicked[playerid][i]) ? ("{2ECC71}Collected") : ("{E74C3C}Not Collected"));
  225.                 idx++;
  226.             }
  227.            
  228.             ShowPlayerDialog(playerid, menu_id, DIALOG_STYLE_TABLIST, title, string, "Back", "");
  229.         }
  230.        
  231.         case DIALOG_COLLECTIBLES_RESET:
  232.         {
  233.             new string[196];
  234.             for(new i; i < sizeof(CollectibleTypes); i++) format(string, sizeof(string), "%sReset %s Progress\n", string, CollectibleTypes[i][typeName]);
  235.             ShowPlayerDialog(playerid, menu_id, DIALOG_STYLE_LIST, "Collectibles » {FFFFFF}Reset", string, "Continue", "Back");
  236.         }
  237.        
  238.         case DIALOG_COLLECTIBLES_RESET_2:
  239.         {
  240.             new string[128];
  241.             format(string, sizeof(string), "{FFFFFF}Do you want to reset your {F1C40F}%s {FFFFFF}progress?\n\n{E74C3C}It will be gone forever!", CollectibleTypes[extra_id][typeName]);
  242.             ShowPlayerDialog(playerid, menu_id, DIALOG_STYLE_MSGBOX, "Collectibles » {FFFFFF}Reset", string, "Reset", "Back");
  243.         }
  244.        
  245.         default:
  246.         {
  247.             ShowPlayerDialog(playerid, menu_id, DIALOG_STYLE_LIST, "Collectibles", "My Progress\nReset Progress", "Select", "Close");
  248.         }
  249.     }
  250.    
  251.     return 1;
  252. }
  253.  
  254. forward ReadCollectibleProgress(playerid, name[], value[]);
  255. public ReadCollectibleProgress(playerid, name[], value[])
  256. {
  257.     new key[24];
  258.     for(new i; i < sizeof(CollectibleData); ++i)
  259.     {
  260.         format(key, sizeof(key), "ColPicked_%d", i);
  261.         INI_Int(key, CollectiblePicked[playerid][i]);
  262.     }
  263.    
  264.     return 1;
  265. }
  266.  
  267. public OnFilterScriptInit()
  268. {
  269.     for(new i; i < sizeof(CollectibleData); i++) CollectibleData[i][colPickup] = CreatePickup(CollectibleTypes[ CollectibleData[i][colType] ][typeModel], 1, CollectibleData[i][colX], CollectibleData[i][colY], CollectibleData[i][colZ], -1);
  270.     return 1;
  271. }
  272.  
  273. public OnFilterScriptExit()
  274. {
  275.     for(new i; i < sizeof(CollectibleData); i++) DestroyPickup(CollectibleData[i][colPickup]);
  276.     return 1;
  277. }
  278.  
  279. public OnPlayerConnect(playerid)
  280. {
  281.     LoadPlayerProgress(playerid);
  282.     return 1;
  283. }
  284.  
  285. public OnPlayerPickUpPickup(playerid, pickupid)
  286. {
  287.     for(new i; i < sizeof(CollectibleData); i++)
  288.     {
  289.         if(pickupid == CollectibleData[i][colPickup])
  290.         {
  291.             if(!CollectiblePicked[playerid][i])
  292.             {
  293.                 CollectiblePicked[playerid][i] = 1;
  294.                
  295.                 new string[80], type = CollectibleData[i][colType], collected = GetCollectedCount(playerid, type), max_col = GetCollectibleCount(type);
  296.                 format(string, sizeof(string), "~w~%ss %d out of %d", CollectibleTypes[type][typeName] , collected, max_col);
  297.                 GameTextForPlayer(playerid, string, 20000, 3);
  298.                 GivePlayerMoney(playerid, COLLECTIBLE_REWARD);
  299.                
  300.                 if(collected == max_col)
  301.                 {
  302.                     format(string, sizeof(string), "Congratulations! You collected every {F1C40F}%s {FFFFFF}around the map.", CollectibleTypes[type][typeName]);
  303.                     SendClientMessage(playerid, -1, string);
  304.                    
  305.                     format(string, sizeof(string), "Here's your well earned {2ECC71}$%d.", COMPLETION_REWARD);
  306.                     SendClientMessage(playerid, -1, string);
  307.                    
  308.                     GivePlayerMoney(playerid, COMPLETION_REWARD);
  309.                 }
  310.                
  311.                 SavePlayerProgress(playerid);
  312.             }
  313.            
  314.             break;
  315.         }
  316.     }
  317.    
  318.     return 1;
  319. }
  320.  
  321. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  322. {
  323.     switch(dialogid)
  324.     {
  325.         case DIALOG_COLLECTIBLES_MENU:
  326.         {
  327.             if(!response) return 1;
  328.             if(listitem == 0) return ShowMenu(playerid, DIALOG_COLLECTIBLES_PROGRESS);
  329.             if(listitem == 1) return ShowMenu(playerid, DIALOG_COLLECTIBLES_RESET);
  330.         }
  331.        
  332.         case DIALOG_COLLECTIBLES_PROGRESS:
  333.         {
  334.             if(!response) return ShowMenu(playerid);
  335.             ShowMenu(playerid, DIALOG_COLLECTIBLES_PROGRESS_2, listitem);
  336.             return 1;
  337.         }
  338.        
  339.         case DIALOG_COLLECTIBLES_PROGRESS_2:
  340.         {
  341.             ShowMenu(playerid, DIALOG_COLLECTIBLES_PROGRESS);
  342.             return 1;
  343.         }
  344.        
  345.         case DIALOG_COLLECTIBLES_RESET:
  346.         {
  347.             if(!response) return ShowMenu(playerid);
  348.             SetPVarInt(playerid, "progResetType", listitem);
  349.             ShowMenu(playerid, DIALOG_COLLECTIBLES_RESET_2, listitem);
  350.             return 1;
  351.         }
  352.        
  353.         case DIALOG_COLLECTIBLES_RESET_2:
  354.         {
  355.             if(!response) return ShowMenu(playerid, DIALOG_COLLECTIBLES_RESET);
  356.             new res_type = GetPVarInt(playerid, "progResetType");
  357.            
  358.             for(new i; i < sizeof(CollectibleData); i++) if(CollectibleData[i][colType] == res_type) CollectiblePicked[playerid][i] = 0;
  359.             SavePlayerProgress(playerid);
  360.  
  361.             new string[64];
  362.             format(string, sizeof(string), "%s {FFFFFF}progress reset.", CollectibleTypes[res_type][typeName]);
  363.             SendClientMessage(playerid, 0xF1C40FFF, string);
  364.             return 1;
  365.         }
  366.     }
  367.    
  368.     return 0;
  369. }
  370.  
  371. CMD:collectibles(playerid, params[])
  372. {
  373.     ShowMenu(playerid);
  374.     return 1;
  375. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement