SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 03/12/2011, 06:34 PM   #1
Ash.
High-roller
 
Ash.'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 2,094
Reputation: 163
Default RemoveBuilding

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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
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 Code:
#include <removebuilding> //Example
The default "object removal limit" is 100. You can change this by defining it BEFORE you include the file. Example:
pawn Code:
#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
Code:
06/08/12:
 - Fixed an issue with RestoreBuilding... (Should've noticed this ages ago tbh...)
Code:
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.
Code:
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.
Code:
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!
__________________
TruckingWorld
Work, Play, Make Friends
Written from scratch, and originally released in 2011, play today!
Visit the forum | Play the game

Last edited by Ash.; 06/08/2012 at 08:03 PM.
Ash. is offline   Reply With Quote
Old 03/12/2011, 06:37 PM   #2
Mr.Fames
Huge Clucker
 
Join Date: Oct 2011
Posts: 341
Reputation: 24
Default Re: RemoveBuilding

good job man really great job i like it
__________________
Mr.Fames is offline   Reply With Quote
Old 03/12/2011, 06:39 PM   #3
PawnoQ
Huge Clucker
 
Join Date: Nov 2011
Posts: 381
Reputation: 7
Thumbs up Re: RemoveBuilding

awesome work! thx funky!
PawnoQ is offline   Reply With Quote
Old 03/12/2011, 07:43 PM   #4
Ash.
High-roller
 
Ash.'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 2,094
Reputation: 163
Default Re: RemoveBuilding

Quote:
Originally Posted by Mr.Fames View Post
good job man really great job i like it
Quote:
Originally Posted by PawnoQ View Post
awesome work! thx funky!
Thanks.

I may implement a "RestoreBuilding" at some point too. However, this will use the CreateObject native.
//This has since been implemented.
__________________
TruckingWorld
Work, Play, Make Friends
Written from scratch, and originally released in 2011, play today!
Visit the forum | Play the game

Last edited by Ash.; 04/12/2011 at 10:48 AM.
Ash. is offline   Reply With Quote
Old 03/12/2011, 08:33 PM   #5
Kaperstone
Banned
 
Join Date: May 2011
Location: Russia
Posts: 3,346
Reputation: 824
Default Re: RemoveBuilding

what the difference between this and the new native from 0.3d:
pawn Code:
RemoveBuildingForPlayer(playerid, modelid, Float:fX, Float:fY, Float:fZ, Float:fRadius);
Kaperstone is offline   Reply With Quote
Old 03/12/2011, 09:16 PM   #6
PlayHard
Huge Clucker
 
PlayHard's Avatar
 
Join Date: Nov 2011
Location: In an apartment
Posts: 218
Reputation: 22
Default Re: RemoveBuilding

Excellent. I would love to see RemoveCertainBuilding(objectid);! @xkirill: this one is global notjust forone player I think.
PlayHard is offline   Reply With Quote
Old 03/12/2011, 09:26 PM   #7
English-Conceptz
Big Clucker
 
Join Date: Oct 2011
Posts: 148
Reputation: 8
Default Re: RemoveBuilding

Quote:
Originally Posted by xkirill View Post
what the difference between this and the new native from 0.3d:
pawn Code:
RemoveBuildingForPlayer(playerid, modelid, Float:fX, Float:fY, Float:fZ, Float:fRadius);
cant you read ? he said it removes it for all players that connect....
__________________

If i helped you please give me rep everyone needs it right ?
English-Conceptz is offline   Reply With Quote
Old 03/12/2011, 09:33 PM   #8
[Nikk]
High-roller
 
[Nikk]'s Avatar
 
Join Date: Jun 2011
Location: Argentina.
Posts: 1,491
Reputation: 63
Default Respuesta: RemoveBuilding

Great Job!
__________________


[Nikk] is offline   Reply With Quote
Old 03/12/2011, 09:41 PM   #9
Ash.
High-roller
 
Ash.'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 2,094
Reputation: 163
Default Re: RemoveBuilding

Quote:
Originally Posted by xkirill View Post
what the difference between this and the new native from 0.3d:
pawn Code:
RemoveBuildingForPlayer(playerid, modelid, Float:fX, Float:fY, Float:fZ, Float:fRadius);
You obviously haven't read the original post thoroughly. This include removes the need for the 'playerid' parameter of the 0.3d native; therefore meaning it can be called anywhere (OnGameModeInit, so you can keep certain map segments separate, for example).

Quote:
Originally Posted by PlayHard View Post
Excellent. I would love to see RemoveCertainBuilding(objectid);!
This wouldn't be so difficult with this include. I may add this when I get round to adding the RestoreBuilding function.
//This has since been implemented.

Thanks to everyone that has given me such thankful/nice comments.
__________________
TruckingWorld
Work, Play, Make Friends
Written from scratch, and originally released in 2011, play today!
Visit the forum | Play the game

Last edited by Ash.; 04/12/2011 at 10:48 AM.
Ash. is offline   Reply With Quote
Old 04/12/2011, 09:59 AM   #10
Ash.
High-roller
 
Ash.'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 2,094
Reputation: 163
Default Re: RemoveBuilding

Quote:
Originally Posted by funky1234 View Post
Code:
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.
Update: Added two new functions. Refer to the original post for more information.
__________________
TruckingWorld
Work, Play, Make Friends
Written from scratch, and originally released in 2011, play today!
Visit the forum | Play the game
Ash. is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mapping with removebuilding ? Vukilore Scripting Help 4 03/11/2011 07:04 PM


All times are GMT. The time now is 04:34 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.