[Include] RemoveBuilding
#1

RemoveBuilding
Global "RemoveBuildingForPlayer"
Good Evening SAMP users!
I'd like to present you with "RemoveBuilding".
Introduction
A player on my server recently requested that a map be added (a house modification) that used the RemoveBuildingForPlayer function. I had not yet used that function for my server (though had used it throughout the RC builds) and was wondering what would be the best way to apply this to all players, no matter when they connect or if they're connected at the time. My solution, was this include!

In short: This include removes the need to use RemoveBuildingForPlayer for everyone (for loop) and removes the need of calling such function when the player connects. This include also brings with it a 'RestoreBuilding' function and a 'RemoveSpecificBuilding' function.

The Functions
RemoveBuilding
pawn Код:
RemoveBuilding(modelid, Float:oX, Float:oY, Float:oZ, Float:oRadius = 0.25, Float:orX = 0.0, Float:orY = 0.0, Float:orZ = 0.0)
This operates the same way as RemoveBuildingForPlayer does, though without the "playerid" parameter. It places the object in a global array (within the include) and removes it for all connected players. If a player connects after RemoveBuilding has been called, it removes the static object for that player too. In this include, specifying the radius is optional. You could merely do
pawn Код:
RemoveBuilding(modelid, x, y, z);
and it would work perfectly fine. This function also has the option of supplying the objects rotation co-ordinates. If you do wish to use 'RestoreBuilding' at some point, you will need to specify these. This function returns a 'slotid' which is the array slot of the data being kept after this function is called. If you wish to call RestoreBuilding for this particular static object, you will need to store what this function returns in a variable. Observe:
pawn Код:
new rem_obj = RestoreBuilding(modelid, x, y, z, radius, rx, ry, rz);
To remove a building accurately, you will need to specify the rotation co-ordinates.
RemoveSpecificBuilding
pawn Код:
RemoveSpecificBuilding(modelid)
With this function, you can merely specify a 'modelid' to remove throughout the map. It returns the 'slotid' for that particular object, however you cannot restore objects using this function (as you give no co-ordinates to this function).
RestoreBuilding
pawn Код:
RestoreBuilding(slotid)
This function allows you to restore a particular building that has been removed using RemoveBuilding. You will need to 'slotid' that RemoveBuilding returns to pass to it (hence the 'slotid' parameter). RestoreBuilding will re-create the object using SA-MP's native CreateObject function. A quick demonstration on how this works:
pawn Код:
new RemoveObjectVar;

public OnFilterScriptInit()
{
    RemoveObjectVar = RemoveBuilding(1697, 236.9922, 1835.3438, 23.2344, 0.25, 356.8584, 0.0000, -0.7854);
}

CMD:restore(playerid, params[])
{
    #pragma unused params
    RestoreBuilding(RemoveObjectVar);
    return SendClientMessage(playerid, COLOUR_GREEN, "The static object has been restored."), 1;
}
CountRemovedObjects
pawn Код:
CountRemovedObjects()
This merely returns how many objects have been 'destroyed' by the RemoveBuilding function.

Setup
You will need to download the include (and place it in pawno > includes). The download link is available toward the end of this post. Include it (with the name you called it).
pawn Код:
#include <removebuilding> //Example
The default "object removal limit" is 100. You can change this by defining it BEFORE you include the file. Example:
pawn Код:
#define MAX_REMOVED_OBJECTS 500
#include <removebuilding>
Remember, the higher this number - the bigger the array, therefore the higher the memory usage.

You can then proceed to using "RemoveBuilding" like you would use "RemoveBuildingForPlayer". You will need to change your RemoveBuildingForPlayer lines to RemoveBuilding for this include to be able to handle them correctly.

Bugs/Issues
If you have found an issue/bug with this include, don't hesitate to post it here! (PM'ing me won't get it fixed, and will just get you blacklisted from contacting me.)

Change Log
Код:
06/08/12:
 - Fixed an issue with RestoreBuilding... (Should've noticed this ages ago tbh...)
Код:
04/12/11: 
 - Added RestoreBuilding; a function for restoring removed buildings.
 - Added RemoveSpecificBuilding; a function for removing all models on the map; regardless of their location.
Код:
06/12/11:
 - Removed the hooking of the RemoveBuildingForPlayer native (as this caused errors with RemoveBuilding itself). You will need to convert the RemoveBuildingForPlayer lines yourself.
Код:
14/12/11
 - Rescripted part of the RemoveBuilding function to properly assign the fact that a building has been removed.
Download
This is the latest download link from Pastebin: http://pastebin.com/Y2pqCSgF

The old (original) version of this include can be found here: http://pastebin.com/vXR5A3n6 - You can use this version if you do not plan on using the RestoreBuilding or RemoveSpecificBuilding functions.
Please refer to the "Setup" section of this post for help on setting both the updated and old version up.

Conclusion
I have tested this script, and can confirm it has worked fine for me. I haven't yet tested it on a public server, and so it hasn't been under a lot of stress; though it should work perfectly fine. If you have any issues, don't hesitate to ask!
Reply


Messages In This Thread
RemoveBuilding - by Ash. - 03.12.2011, 18:34
Re: RemoveBuilding - by Mr.Fames - 03.12.2011, 18:37
Re: RemoveBuilding - by PawnoQ - 03.12.2011, 18:39
Re: RemoveBuilding - by Ash. - 03.12.2011, 19:43
Re: RemoveBuilding - by Kaperstone - 03.12.2011, 20:33
Re: RemoveBuilding - by PlayHard - 03.12.2011, 21:16
Re: RemoveBuilding - by English-Conceptz - 03.12.2011, 21:26
Respuesta: RemoveBuilding - by [Nikk] - 03.12.2011, 21:33
Re: RemoveBuilding - by Ash. - 03.12.2011, 21:41
Re: RemoveBuilding - by Ash. - 04.12.2011, 09:59
Re: RemoveBuilding - by Jack_Rocker - 05.12.2011, 18:48
Re: RemoveBuilding - by MP2 - 05.12.2011, 21:07
Re: RemoveBuilding - by Ash. - 05.12.2011, 21:17
Re: RemoveBuilding - by scottygraham1990 - 06.12.2011, 09:25
Re: RemoveBuilding - by Ash. - 06.12.2011, 16:11
Re: RemoveBuilding - by scottygraham1990 - 06.12.2011, 18:08
Re: RemoveBuilding - by Ash. - 06.12.2011, 18:30
Re: RemoveBuilding - by Orlandino - 07.12.2011, 18:44
Re: RemoveBuilding - by Ash. - 07.12.2011, 20:15
Respuesta: RemoveBuilding - by e-motic - 12.12.2011, 07:46
Re: RemoveBuilding - by Ash. - 12.12.2011, 15:41
Respuesta: Re: RemoveBuilding - by e-motic - 13.12.2011, 06:35
AW: RemoveBuilding - by Gireada - 13.12.2011, 14:06
Re: Respuesta: Re: RemoveBuilding - by Ash. - 13.12.2011, 16:33
Re: RemoveBuilding - by Calgon - 23.12.2011, 08:52
Re: RemoveBuilding - by Chris White - 23.12.2011, 08:56
Re: RemoveBuilding - by Ash. - 23.12.2011, 12:29
Re: RemoveBuilding - by Ash. - 23.12.2011, 13:54
Re: RemoveBuilding - by BravoMan21 - 27.12.2011, 02:15
Re: RemoveBuilding - by Ash. - 27.12.2011, 08:42

Forum Jump:


Users browsing this thread: 10 Guest(s)