1
0

removebuilding.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #if !defined MAX_REMOVED_OBJECTS
  2. #define MAX_REMOVED_OBJECTS 20000
  3. #endif
  4. enum RemovedObjectsENUM {_model, Float:_oX, Float:_oY, Float:_oZ, Float:_orX, Float:_orY, Float:_orZ, Float:_oRadius, restored}
  5. new RemovedObjects[MAX_REMOVED_OBJECTS][RemovedObjectsENUM];
  6. /*
  7. 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);
  8. native RestoreBuilding(slotid);
  9. native RemoveSpecificBuilding(modelid);
  10. native CountRemovedObjects();
  11. */
  12. 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)
  13. {
  14. for(new i; i < MAX_REMOVED_OBJECTS; i++)
  15. {
  16. if(RemovedObjects[i][_model] != modelid) continue;
  17. if(RemovedObjects[i][restored] != 0)
  18. {
  19. if((RemovedObjects[i][_oX] == oX) && (RemovedObjects[i][_oY] == oY) && (RemovedObjects[i][_oZ] == oZ))
  20. {
  21. DestroyObject(RemovedObjects[i][restored]);
  22. RemovedObjects[i][restored] = 0;
  23. RemovedObjects[i][_model] = 0;
  24. return i;
  25. }
  26. }
  27. }
  28. new slot2 = GetObjectFreeSlot();
  29. if(slot2 == -1) return printf("\tCannot remove any more objects.\nIncrease MAX_REMOVED_OBJECTS in your script.\nIt is currently: %i", MAX_REMOVED_OBJECTS);
  30. RemovedObjects[slot2][_model] = modelid;
  31. RemovedObjects[slot2][_oX] = oX;
  32. RemovedObjects[slot2][_oY] = oY;
  33. RemovedObjects[slot2][_oZ] = oZ;
  34. RemovedObjects[slot2][_oRadius] = oRadius;
  35. RemovedObjects[slot2][_orX] = orX;
  36. RemovedObjects[slot2][_orY] = orY;
  37. RemovedObjects[slot2][_orZ] = orZ;
  38. for(new i; i < MAX_PLAYERS; i++)
  39. {
  40. if(!IsPlayerConnected(i)) continue;
  41. RemoveBuildingForPlayer(i, modelid, oX, oY, oZ, oRadius);
  42. }
  43. return slot2;
  44. }
  45. stock RemoveSpecificBuilding(modelid)
  46. {
  47. return RemoveBuilding(modelid, 0.0, 0.0, 0.0, 10000.0);
  48. }
  49. forward REMOBJ_OnPlayerConnect(playerid);
  50. public OnPlayerConnect(playerid)
  51. {
  52. for(new i; i < MAX_REMOVED_OBJECTS; i++)
  53. {
  54. if(RemovedObjects[i][_model] != 0) RemoveBuildingForPlayer(playerid, RemovedObjects[i][_model], RemovedObjects[i][_oX], RemovedObjects[i][_oY], RemovedObjects[i][_oZ], RemovedObjects[i][_oRadius]);
  55. }
  56. if(funcidx("REMOBJ_OnPlayerConnect") != -1) CallLocalFunction("REMOBJ_OnPlayerConnect", "i", playerid);
  57. return 1;
  58. }
  59. #if defined _ALS_OnPlayerConnect
  60. #undef OnPlayerConnect
  61. #else
  62. #define _ALS_OnPlayerConnect
  63. #endif
  64. #define OnPlayerConnect REMOBJ_OnPlayerConnect
  65. stock GetObjectFreeSlot()
  66. {
  67. for(new i; i < MAX_REMOVED_OBJECTS; i++)
  68. {
  69. if(RemovedObjects[i][_model] == 0) return i;
  70. }
  71. return -1;
  72. }
  73. stock CountRemovedObjects()
  74. {
  75. new count = 0;
  76. for(new i; i < MAX_REMOVED_OBJECTS; i++)
  77. {
  78. if(RemovedObjects[i][_model] != 0) count++;
  79. }
  80. return count;
  81. }