Guest User

Map Revealing

a guest
Oct 11th, 2015
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define     FILTERSCRIPT
  2. #include    <a_samp>
  3. #include    <streamer>
  4. #include    <YSI\y_ini>
  5.  
  6. #define     MAX_GRID        (100)       // dont change
  7. #define     UNLOCK_TIME     (300)       // in seconds
  8.  
  9. new
  10.     GridID[MAX_GANG_ZONES] = {-1, ...},
  11.     ZoneID[MAX_GRID] = {-1, ...},
  12.     LastGridID[MAX_PLAYERS] = {-1, ...},
  13.     TimeSpent[MAX_PLAYERS][MAX_GRID];
  14.  
  15. stock ConvertSeconds(secs)
  16. {
  17.     new string[16], seconds, minutes;
  18.     seconds = secs % 60;
  19.     minutes = (secs - seconds) / 60;
  20.     format(string, sizeof(string), "%02d:%02d", minutes, seconds);
  21.     return string;
  22. }
  23.  
  24. stock IsPlayerSpawned(playerid)
  25. {
  26.     if((1 <= GetPlayerState(playerid) <= 3) || GetPlayerState(playerid) == PLAYER_STATE_SPAWNED) return 1;
  27.     return 0;
  28. }
  29.  
  30. stock SaveTimes(playerid)
  31. {
  32.     new file[64], name[MAX_PLAYER_NAME];
  33.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  34.     format(file, sizeof(file), "mapunlock/%s.ini", name);
  35.     new INI: fHandle = INI_Open(file), key[24];
  36.  
  37.     if(fHandle != INI_NO_FILE)
  38.     {
  39.         INI_SetTag(fHandle, "MapData");
  40.  
  41.         for(new i; i < MAX_GRID; ++i)
  42.         {
  43.             format(key, sizeof(key), "SecondsSpent_%d", i);
  44.             INI_WriteInt(fHandle, key, TimeSpent[playerid][i]);
  45.         }
  46.  
  47.         INI_Close(fHandle);
  48.     }
  49.    
  50.     return 1;
  51. }
  52.  
  53. public OnFilterScriptInit()
  54. {
  55.     new tempid = -1, grid_id = 0, temparea = -1, area_data[2];
  56.  
  57.     for(new fX = - 3000; fX < 3000; fX += 650)
  58.     {
  59.         for(new fY = -3000; fY < 3000; fY += 650)
  60.         {
  61.             // http://forum.sa-mp.com/showpost.php?p=2906806&postcount=13
  62.             tempid = GangZoneCreate(fX, fY, fX + 650, fY + 650);
  63.             GangZoneShowForAll(tempid, 0x000000FF);
  64.             GridID[tempid] = grid_id;
  65.             ZoneID[grid_id] = tempid;
  66.            
  67.             temparea = CreateDynamicRectangle(fX, fY, fX + 650, fY + 650, .interiorid = 0);
  68.             area_data[0] = true;
  69.             area_data[1] = grid_id;
  70.             Streamer_SetArrayData(STREAMER_TYPE_AREA, temparea, E_STREAMER_EXTRA_ID, area_data);
  71.             grid_id++;
  72.         }
  73.     }
  74.    
  75.     SetTimer("UpdateTimes", 1000, true);
  76.     return 1;
  77. }
  78.  
  79. public OnFilterScriptExit()
  80. {
  81.     for(new i; i < MAX_GANG_ZONES; i++)
  82.     {
  83.         if(GridID[i] == -1) continue;
  84.         GangZoneDestroy(i);
  85.     }
  86.    
  87.     return 1;
  88. }
  89.  
  90. public OnPlayerConnect(playerid)
  91. {
  92.     new file[64], name[MAX_PLAYER_NAME];
  93.     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
  94.     format(file, sizeof(file), "mapunlock/%s.ini", name);
  95.     if(!fexist(file)) SaveTimes(playerid);
  96.     INI_ParseFile(file, "LoadTimes", .bExtra = true, .extra = playerid);
  97.    
  98.     for(new i; i < MAX_GRID; ++i)
  99.     {
  100.         if(TimeSpent[playerid][i] >= UNLOCK_TIME) {
  101.             GangZoneHideForPlayer(playerid, ZoneID[i]);
  102.         }else if(TimeSpent[playerid][i] >= floatround(UNLOCK_TIME / 2)) {
  103.             GangZoneShowForPlayer(playerid, ZoneID[i], 0x000000DD);
  104.         }else{
  105.             GangZoneShowForPlayer(playerid, ZoneID[i], 0x000000FF);
  106.         }
  107.     }
  108.    
  109.     LastGridID[playerid] = -1;
  110.     return 1;
  111. }
  112.  
  113. public OnPlayerCommandText(playerid, cmdtext[])
  114. {
  115.     if(!strcmp(cmdtext, "/lockarea"))
  116.     {
  117.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  118.         if(LastGridID[playerid] == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in any area.");
  119.         TimeSpent[playerid][ LastGridID[playerid] ] = 0;
  120.         GangZoneShowForPlayer(playerid, ZoneID[ LastGridID[playerid] ], 0x000000FF);
  121.         SaveTimes(playerid);
  122.         return 1;
  123.     }
  124.    
  125.     if(!strcmp(cmdtext, "/unlockarea"))
  126.     {
  127.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  128.         if(LastGridID[playerid] == -1) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}You're not in any area.");
  129.         TimeSpent[playerid][ LastGridID[playerid] ] = UNLOCK_TIME;
  130.         GangZoneHideForPlayer(playerid, ZoneID[ LastGridID[playerid] ]);
  131.         SaveTimes(playerid);
  132.         return 1;
  133.     }
  134.    
  135.     if(!strcmp(cmdtext, "/hidemap"))
  136.     {
  137.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  138.         for(new i; i < MAX_GRID; ++i)
  139.         {
  140.             TimeSpent[playerid][i] = 0;
  141.             GangZoneShowForPlayer(playerid, ZoneID[i], 0x000000FF);
  142.         }
  143.        
  144.         SaveTimes(playerid);
  145.         return 1;
  146.     }
  147.  
  148.     if(!strcmp(cmdtext, "/showmap"))
  149.     {
  150.         if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xE74C3CFF, "ERROR: {FFFFFF}Only RCON admins can use this command.");
  151.         for(new i; i < MAX_GRID; ++i)
  152.         {
  153.             TimeSpent[playerid][i] = UNLOCK_TIME;
  154.             GangZoneHideForPlayer(playerid, ZoneID[i]);
  155.         }
  156.        
  157.         SaveTimes(playerid);
  158.         return 1;
  159.     }
  160.  
  161.     return 0;
  162. }
  163.  
  164. public OnPlayerDisconnect(playerid, reason)
  165. {
  166.     SaveTimes(playerid);
  167.     return 1;
  168. }
  169.  
  170. public OnPlayerEnterDynamicArea(playerid, areaid)
  171. {
  172.     if(!IsPlayerSpawned(playerid)) return 1;
  173.     if(!IsValidDynamicArea(areaid)) return 1;
  174.     new area_data[2];
  175.     Streamer_GetArrayData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID, area_data);
  176.     if(!area_data[0]) return 1;
  177.     LastGridID[playerid] = area_data[1];
  178.    
  179.     new string[128];
  180.     format(string, sizeof(string), "[ENTERING NEW AREA] {FFFFFF}You've spent %s in this area.", ConvertSeconds(TimeSpent[playerid][ LastGridID[playerid] ]));
  181.     SendClientMessage(playerid, 0x2ECC71FF, string);
  182.     return 1;
  183. }
  184.  
  185. public OnPlayerLeaveDynamicArea(playerid, areaid)
  186. {
  187.     if(!IsPlayerSpawned(playerid)) return 1;
  188.     if(!IsValidDynamicArea(areaid)) return 1;
  189.     new area_data[2];
  190.     Streamer_GetArrayData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID, area_data);
  191.     if(!area_data[0]) return 1;
  192.     LastGridID[playerid] = -1;
  193.     return 1;
  194. }
  195.  
  196. forward UpdateTimes();
  197. public UpdateTimes()
  198. {
  199.     for(new i; i <= GetPlayerPoolSize(); ++i)
  200.     {
  201.         if(!IsPlayerConnected(i)) continue;
  202.         if(!IsPlayerSpawned(i)) continue;
  203.         if(LastGridID[i] == -1) continue;
  204.         if(GetPlayerInterior(i) > 0) continue;
  205.         if(!IsPlayerInAnyDynamicArea(i)) continue;
  206.         TimeSpent[i][ LastGridID[i] ]++;
  207.        
  208.         if(TimeSpent[i][ LastGridID[i] ] <= UNLOCK_TIME)
  209.         {
  210.             if(TimeSpent[i][ LastGridID[i] ] == floatround(UNLOCK_TIME / 2)) {
  211.                 GangZoneShowForPlayer(i, ZoneID[ LastGridID[i] ], 0x000000DD);
  212.                 SendClientMessage(i, -1, "Soon you'll unlock this part of the map.");
  213.             }else if(TimeSpent[i][ LastGridID[i] ] == UNLOCK_TIME) {
  214.                 GangZoneStopFlashForPlayer(i, ZoneID[ LastGridID[i] ]);
  215.                 GangZoneHideForPlayer(i, ZoneID[ LastGridID[i] ]);
  216.                 SendClientMessage(i, -1, "You've unlocked a part of the map.");
  217.                 SaveTimes(i);
  218.             }else if((UNLOCK_TIME - TimeSpent[i][ LastGridID[i] ]) < 5) {
  219.                 GangZoneFlashForPlayer(i, ZoneID[ LastGridID[i] ], 0x00000000);
  220.             }
  221.         }
  222.     }
  223.    
  224.     return 1;
  225. }
  226.  
  227. forward LoadTimes(playerid, name[], value[]);
  228. public LoadTimes(playerid, name[], value[])
  229. {
  230.     new key[24];
  231.     for(new i; i < MAX_GRID; ++i)
  232.     {
  233.         format(key, sizeof(key), "SecondsSpent_%d", i);
  234.         INI_Int(key, TimeSpent[playerid][i]);
  235.     }
  236.    
  237.     return 1;
  238. }
RAW Paste Data