[Include] Building remover restorer for All/Playerid
#1

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 remove
Default is 500

Lets us declare variables to store slot of the building
pawn Код:
new slot1,slot2;
Now a command to remove buidling's.
pawn Код:
slot1 = RemovePlayerBuilding(playerid, 3513, 2037.4297, 1302.7422, 13.9922, 0.25);
    slot2 =  RemoveBuildingForAll( 3509, 2057.4063, 1305.0938, 9.7813, 0.25);
slot1 building is removed for playerid whereas slot2 building is removed for everyone.

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();
under OnGameModeInIt() and comment/remove out hook part.
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;
   
}
BUGS :
Please report bugs and suggestions.
Reply
#2

Why even bother then?
Reply
#3

What did you change? It looks quite the same.
Reply
#4

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
What did you change? It looks quite the same.
Earlier one did not had any playerid parameter.
Reply
#5

Quote:
Originally Posted by [MM]RoXoR[FS]
Посмотреть сообщение
Earlier one did not had any playerid parameter.
Well duh.
Reply
#6

So, what happens if you delete all objects of id ... in a range of 5000.0 of the center of SA (0.0, 0.0, 0.0).. Would it just recreate one object at 0.0, 0.0, 0.0 then?

I'm not trying to be a dick, I'm just telling you, this include ain't so awesome and probably would work in a very small radius..
Reply
#7

Quote:
Originally Posted by RobinOwnz
Посмотреть сообщение
So, what happens if you delete all objects of id ... in a range of 5000.0 of the center of SA (0.0, 0.0, 0.0).. Would it just recreate one object at 0.0, 0.0, 0.0 then?

I'm not trying to be a dick, I'm just telling you, this include ain't so awesome and probably would work in a very small radius..
Yup, you are right, I will keep that in mind next time.

Probably store X,Y,Z for each object.
Reply
#8

Also it has a very big limit which are the objects. Even the streamer can restore the same objects for all.
Reply
#9

pawn Код:
CreatePlayerObject(iBuildInfo[slot][id],iBuildInfo[slot][modelid],iBuildInfo[slot][X],iBuildInfo[slot][Y],iBuildInfo[slot][Z],0,0,0,0);

||
\/

playerid = iBuildInfo[slot][id]
modelid = iBuildInfo[slot][modelid]
Float:X = iBuildInfo[slot][X]
Float:Y = iBuildInfo[slot][Y]
Float:Z = iBuildInfo[slot][Z]
Float:rX = 0.0     //
Float:rY = 0.0     // This is hilarious.
Float:rZ = 0.0     //
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)