Advertisement
Kartik_Sharma

Buildng Remover\Restorer SAMP

Jul 24th, 2012
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.80 KB | None | 0 0
  1. #include <YSI\y_hooks>
  2.  
  3. #if !defined MAX_PLAYER_BUILDING
  4.     #define MAX_PLAYER_BUILDING 500
  5. #endif
  6.  
  7. enum EBUILDING
  8. {
  9.     id,
  10.     modelid,
  11.     Float:X,
  12.     Float:Y,
  13.     Float:Z,
  14.     Float:radius
  15. }
  16.  
  17. new iBuildInfo[MAX_PLAYER_BUILDING][EBUILDING];
  18.  
  19. /*
  20. native RefreshBuilding();
  21. native RemovePlayerBuilding(playerid,modelid,X,Y,Z,radius);
  22. native RemoveBuildingForAll(modelid,X,Y,Z,radius);
  23. native RestoreBuilding(slot);
  24. */
  25.  
  26. hook OnGameModeInit()
  27. {
  28.     for(new i=0;i<MAX_PLAYER_BUILDING;++i)
  29.     {
  30.         iBuildInfo[i][modelid] = -1;
  31.         iBuildInfo[i][id] = -1;
  32.     }
  33.     return 0;
  34. }
  35.  
  36. stock RefreshBuilding()
  37. {
  38.     for(new i=0;i<MAX_PLAYER_BUILDING;++i)
  39.     {
  40.         iBuildInfo[i][modelid] = -1;
  41.         iBuildInfo[i][id] = -1;
  42.     }
  43.     return 1;  
  44. }
  45. stock RemovePlayerBuilding(_playerid,_modelid,Float:_X,Float:_Y,Float:_Z,Float:_radius)
  46. {
  47.     new slot=-1;
  48.     for(new i=0;i<MAX_PLAYER_BUILDING;++i)
  49.     {
  50.         if(iBuildInfo[i][modelid] != -1) continue;
  51.         slot = i;
  52.         break;
  53.     }
  54.     if(slot == -1)
  55.     {
  56.         printf("ERROR:No more space left to store data");
  57.         printf("Failed to remove Building for %d(model : %s, locations(%f,%f,%f), radius %f)",_playerid,_modelid,_X,_Y,_Z,_radius);
  58.         return -1;
  59.     }
  60.     RemoveBuildingForPlayer(_playerid,_modelid,_X,_Y,_Z,_radius);
  61.     iBuildInfo[slot][id] = _playerid;
  62.     iBuildInfo[slot][modelid] = _modelid;
  63.     iBuildInfo[slot][X] = _X;
  64.     iBuildInfo[slot][Y] = _Y;
  65.     iBuildInfo[slot][Z] = _Z;
  66.     iBuildInfo[slot][radius] = _radius;
  67.     return slot;
  68. }
  69.  
  70. stock RemoveBuildingForAll(_modelid,Float:_X,Float:_Y,Float:_Z,Float:_radius)
  71. {
  72.     new slot = -1;
  73.     for(new i=0;i<MAX_PLAYER_BUILDING;++i)
  74.     {
  75.         if(iBuildInfo[i][modelid] != -1) continue;
  76.         slot = i;
  77.         break;
  78.     }
  79.     if(slot == -1)
  80.     {
  81.         printf("ERROR:No more space left to store data");
  82.         printf("Failed to remove Building (model : %s, locations(%f,%f,%f), radius %f)",_modelid,_X,_Y,_Z,_radius);
  83.         return -1;
  84.     }
  85.    
  86.     for(new i=0;i<MAX_PLAYERS;++i)
  87.     {
  88.         RemoveBuildingForPlayer(i,_modelid,_X,_Y,_Z,_radius);
  89.     }
  90.     iBuildInfo[slot][id] = -1;
  91.     iBuildInfo[slot][modelid] = _modelid;
  92.     iBuildInfo[slot][X] = _X;
  93.     iBuildInfo[slot][Y] = _Y;
  94.     iBuildInfo[slot][Z] = _Z;
  95.     iBuildInfo[slot][radius] = _radius;
  96.     return slot;
  97. }
  98.  
  99. stock RestoreBuilding(slot)
  100. {
  101.     if(slot < 0 || slot > MAX_PLAYER_BUILDING)
  102.     {
  103.         printf("ERROR:Invalid slot %d",slot);
  104.         return -1;
  105.     }
  106.     if(iBuildInfo[slot][modelid] == -1)
  107.     {
  108.         printf("ERROR:%d slot not yet used",slot);
  109.         return -1;
  110.     }
  111.     if (iBuildInfo[slot][id] == -1)
  112.     {
  113.         CreateObject(iBuildInfo[slot][modelid],iBuildInfo[slot][X],iBuildInfo[slot][Y],iBuildInfo[slot][Z],0,0,0,0);
  114.     }
  115.     else
  116.     {
  117.        CreatePlayerObject(iBuildInfo[slot][id],iBuildInfo[slot][modelid],iBuildInfo[slot][X],iBuildInfo[slot][Y],iBuildInfo[slot][Z],0,0,0,0);
  118.     }
  119.     iBuildInfo[slot][id] = iBuildInfo[slot][modelid] = -1;
  120.     return 1;
  121.    
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement