Guest User

Untitled

a guest
Mar 18th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. #if !defined MAX_REMOVED_OBJECTS
  2. #define MAX_REMOVED_OBJECTS 100
  3. #endif
  4.  
  5. enum RemovedObjectsENUM {_model, Float:_oX, Float:_oY, Float:_oZ, Float:_orX, Float:_orY, Float:_orZ, Float:_oRadius, restored}
  6. new RemovedObjects[MAX_REMOVED_OBJECTS][RemovedObjectsENUM];
  7.  
  8. /*
  9. native RemoveBuilding(modelid, Float:oX, Float:oY, Float:oZ, Float:oRadius = 0.25, Float:orX = 0.0, Float:orY = 0.0, Float:orZ = 0.0);
  10. native RestoreBuilding(slotid);
  11. native RemoveSpecificBuilding(modelid);
  12.  
  13. native CountRemovedObjects();
  14. */
  15.  
  16. stock RemoveBuilding(modelid, Float:oX, Float:oY, Float:oZ, Float:oRadius = 0.25, Float:orX = 0.0, Float:orY = 0.0, Float:orZ = 0.0)
  17. {
  18. for(new i; i < MAX_REMOVED_OBJECTS; i++)
  19. {
  20. if(RemovedObjects[i][_model] != modelid) continue;
  21. if(RemovedObjects[i][restored] != 0)
  22. {
  23. if((RemovedObjects[i][_oX] == oX) && (RemovedObjects[i][_oY] == oY) && (RemovedObjects[i][_oZ] == oZ))
  24. {
  25. DestroyObject(RemovedObjects[i][restored]);
  26. RemovedObjects[i][restored] = 0;
  27. RemovedObjects[i][_model] = 0;
  28. return i;
  29. }
  30. }
  31. }
  32.  
  33. new slot = GetObjectFreeSlot();
  34. if(slot == -1) return printf("\tCannot remove any more objects.\nIncrease MAX_REMOVED_OBJECTS in your script.\nIt is currently: %i", MAX_REMOVED_OBJECTS);
  35.  
  36. RemovedObjects[slot][_model] = modelid;
  37. RemovedObjects[slot][_oX] = oX;
  38. RemovedObjects[slot][_oY] = oY;
  39. RemovedObjects[slot][_oZ] = oZ;
  40. RemovedObjects[slot][_oRadius] = oRadius;
  41.  
  42. RemovedObjects[slot][_orX] = orX;
  43. RemovedObjects[slot][_orY] = orY;
  44. RemovedObjects[slot][_orZ] = orZ;
  45.  
  46. for(new i; i < MAX_PLAYERS; i++)
  47. {
  48. if(!IsPlayerConnected(i)) continue;
  49. RemoveBuildingForPlayer(i, modelid, oX, oY, oZ, oRadius);
  50. }
  51. return slot;
  52. }
  53.  
  54. stock RestoreBuilding(slotid)
  55. {
  56. if(slotid < 0 || slotid > MAX_REMOVED_OBJECTS) return 0;
  57. if(RemovedObjects[slotid][_model] == 0) return 0;
  58. RemovedObjects[slot][restored] = CreateObject(RemovedObjects[slot][_model], RemovedObjects[slot][_oX], RemovedObjects[slot][_oY], RemovedObjects[slot][_oZ], RemovedObjects[slot][_orX], RemovedObjects[slot][_orY], RemovedObjects[slot][_orZ]);
  59. return 1;
  60. }
  61.  
  62. stock RemoveSpecificBuilding(modelid)
  63. {
  64. return RemoveBuilding(modelid, 0.0, 0.0, 0.0, 10000.0);
  65. }
  66.  
  67. forward REMOBJ_OnPlayerConnect(playerid);
  68. public OnPlayerConnect(playerid)
  69. {
  70. for(new i; i < MAX_REMOVED_OBJECTS; i++)
  71. {
  72. if(RemovedObjects[i][_model] != 0) RemoveBuildingForPlayer(playerid, RemovedObjects[i][_model], RemovedObjects[i][_oX], RemovedObjects[i][_oY], RemovedObjects[i][_oZ], RemovedObjects[i][_oRadius]);
  73. }
  74. if(funcidx("REMOBJ_OnPlayerConnect") != -1) CallLocalFunction("REMOBJ_OnPlayerConnect", "i", playerid);
  75. return 1;
  76. }
  77. #if defined _ALS_OnPlayerConnect
  78. #undef OnPlayerConnect
  79. #else
  80. #define _ALS_OnPlayerConnect
  81. #endif
  82. #define OnPlayerConnect REMOBJ_OnPlayerConnect
  83.  
  84. stock GetObjectFreeSlot()
  85. {
  86. for(new i; i < MAX_REMOVED_OBJECTS; i++)
  87. {
  88. if(RemovedObjects[i][_model] == 0) return i;
  89. }
  90. return -1;
  91. }
  92.  
  93. stock CountRemovedObjects()
  94. {
  95. new count = 0;
  96. for(new i; i < MAX_REMOVED_OBJECTS; i++)
  97. {
  98. if(RemovedObjects[i][_model] != 0) count++;
  99. }
  100. return count;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment