24.07.2012, 10:04
What and Why?
You all may know about RemoveBuilding include.
I and my friend were scripting and he wanted to remove and restore building for a specific playerid.
So, to get over it, I created this little include.
Contents :
- Introduction
- Stocks
- Example/Usage
- File Needed
- Download
Introduction
Using this include you can do :- Remove Building For Specific Player
- Remove Building For All
- Restore Bulding
Stocks
It have the following stocks/functions.pawn Код:
RemovePlayerBuilding(_playerid,_modelid,Float:_X,Float:_Y,Float:_Z,Float:_radius);
RemoveBuildingForAll(_modelid,Float:_X,Float:_Y,Float:_Z,Float:_radius);
RestoreBuilding(slot);
- RemovePlayerBuilding : It removes a building for a specific player and returns the slot for it.
- RemoveBuildingForAll : It removes building for ALL THE PLAYERS. (irrespective if they are connected or not)
- RestoreBuilding : Restores the building to it's original location.
Example/Usage
We can use #define MAX_PLAYER_BUILDING to change the number of max buildings you want to removeDefault is 500
Lets us declare variables to store slot of the building
pawn Код:
new slot1,slot2;
pawn Код:
slot1 = RemovePlayerBuilding(playerid, 3513, 2037.4297, 1302.7422, 13.9922, 0.25);
slot2 = RemoveBuildingForAll( 3509, 2057.4063, 1305.0938, 9.7813, 0.25);
pawn Код:
//This shall restore building.
RestoreBuilding(slot1);
RestoreBuilding(slot2);
File Needed
You will need Y_Hook for include to work properly.If you dont have it, you will have to use
pawn Код:
RefreshBuilding();
Download
Pastebin link (Click Me)pawn Код:
#include <YSI\y_hooks>
#if !defined MAX_PLAYER_BUILDING
#define MAX_PLAYER_BUILDING 500
#endif
enum EBUILDING
{
id,
modelid,
Float:X,
Float:Y,
Float:Z,
Float:radius
}
new iBuildInfo[MAX_PLAYER_BUILDING][EBUILDING];
/*
native RefreshBuilding();
native RemovePlayerBuilding(playerid,modelid,X,Y,Z,radius);
native RemoveBuildingForAll(modelid,X,Y,Z,radius);
native RestoreBuilding(slot);
*/
hook OnGameModeInit()
{
for(new i=0;i<MAX_PLAYER_BUILDING;++i)
{
iBuildInfo[i][modelid] = -1;
iBuildInfo[i][id] = -1;
}
return 0;
}
stock RefreshBuilding()
{
for(new i=0;i<MAX_PLAYER_BUILDING;++i)
{
iBuildInfo[i][modelid] = -1;
iBuildInfo[i][id] = -1;
}
return 1;
}
stock RemovePlayerBuilding(_playerid,_modelid,Float:_X,Float:_Y,Float:_Z,Float:_radius)
{
new slot=-1;
for(new i=0;i<MAX_PLAYER_BUILDING;++i)
{
if(iBuildInfo[i][modelid] != -1) continue;
slot = i;
break;
}
if(slot == -1)
{
printf("ERROR:No more space left to store data");
printf("Failed to remove Building for %d(model : %s, locations(%f,%f,%f), radius %f)",_playerid,_modelid,_X,_Y,_Z,_radius);
return -1;
}
RemoveBuildingForPlayer(_playerid,_modelid,_X,_Y,_Z,_radius);
iBuildInfo[slot][id] = _playerid;
iBuildInfo[slot][modelid] = _modelid;
iBuildInfo[slot][X] = _X;
iBuildInfo[slot][Y] = _Y;
iBuildInfo[slot][Z] = _Z;
iBuildInfo[slot][radius] = _radius;
return slot;
}
stock RemoveBuildingForAll(_modelid,Float:_X,Float:_Y,Float:_Z,Float:_radius)
{
new slot = -1;
for(new i=0;i<MAX_PLAYER_BUILDING;++i)
{
if(iBuildInfo[i][modelid] != -1) continue;
slot = i;
break;
}
if(slot == -1)
{
printf("ERROR:No more space left to store data");
printf("Failed to remove Building (model : %s, locations(%f,%f,%f), radius %f)",_modelid,_X,_Y,_Z,_radius);
return -1;
}
for(new i=0;i<MAX_PLAYERS;++i)
{
RemoveBuildingForPlayer(i,_modelid,_X,_Y,_Z,_radius);
}
iBuildInfo[slot][id] = -1;
iBuildInfo[slot][modelid] = _modelid;
iBuildInfo[slot][X] = _X;
iBuildInfo[slot][Y] = _Y;
iBuildInfo[slot][Z] = _Z;
iBuildInfo[slot][radius] = _radius;
return slot;
}
stock RestoreBuilding(slot)
{
if(slot < 0 || slot > MAX_PLAYER_BUILDING)
{
printf("ERROR:Invalid slot %d",slot);
return -1;
}
if(iBuildInfo[slot][modelid] == -1)
{
printf("ERROR:%d slot not yet used",slot);
return -1;
}
if (iBuildInfo[slot][id] == -1)
{
CreateObject(iBuildInfo[slot][modelid],iBuildInfo[slot][X],iBuildInfo[slot][Y],iBuildInfo[slot][Z],0,0,0,0);
}
else
{
CreatePlayerObject(iBuildInfo[slot][id],iBuildInfo[slot][modelid],iBuildInfo[slot][X],iBuildInfo[slot][Y],iBuildInfo[slot][Z],0,0,0,0);
}
iBuildInfo[slot][id] = iBuildInfo[slot][modelid] = -1;
return 1;
}
Please report bugs and suggestions.