SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 24/07/2012, 10:04 AM   #1
[MM]RoXoR[FS]
Gangsta
 
[MM]RoXoR[FS]'s Avatar
 
Join Date: Mar 2012
Location: Gurgaon,India
Posts: 745
Reputation: 137
Default Building remover restorer for All/Playerid

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 Code:
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 Code:
new slot1,slot2;

Now a command to remove buidling's.
pawn Code:
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 Code:
//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 Code:
RefreshBuilding();
under OnGameModeInIt() and comment/remove out hook part.
Download

Pastebin link (Click Me)
pawn Code:
#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.
__________________
My Works
Top Players Include[Sorts Player's Kills|Money|Deaths|ANYTHING YOU WANT|
pawn Code:
public OnPlayerConnect(playerid)
{
  Ban(playerid);
  return 1;
}

Scripting for Money
[MM]RoXoR[FS] is offline   Reply With Quote
Old 24/07/2012, 10:43 AM   #2
FireCat
Banned
 
Join Date: Jul 2010
Posts: 2,471
Reputation: 596
Default Re: Building remover restorer for All/Playerid

Why even bother then?
FireCat is offline   Reply With Quote
Old 24/07/2012, 10:57 AM   #3
TheArcher
High-roller
 
TheArcher's Avatar
 
Join Date: Dec 2009
Location: Home
Posts: 2,493
Reputation: 229
Default Re: Building remover restorer for All/Playerid

What did you change? It looks quite the same.
__________________
TheArcher is offline   Reply With Quote
Old 24/07/2012, 11:50 AM   #4
[MM]RoXoR[FS]
Gangsta
 
[MM]RoXoR[FS]'s Avatar
 
Join Date: Mar 2012
Location: Gurgaon,India
Posts: 745
Reputation: 137
Default Re: Building remover restorer for All/Playerid

Quote:
Originally Posted by TheArcher View Post
What did you change? It looks quite the same.
Earlier one did not had any playerid parameter.
__________________
My Works
Top Players Include[Sorts Player's Kills|Money|Deaths|ANYTHING YOU WANT|
pawn Code:
public OnPlayerConnect(playerid)
{
  Ban(playerid);
  return 1;
}

Scripting for Money
[MM]RoXoR[FS] is offline   Reply With Quote
Old 24/07/2012, 01:43 PM   #5
Glint
Guest
 
Posts: n/a
Default Re: Building remover restorer for All/Playerid

Quote:
Originally Posted by [MM]RoXoR[FS] View Post
Earlier one did not had any playerid parameter.
Well duh.
  Reply With Quote
Old 24/07/2012, 03:19 PM   #6
rbN.
Banned
 
Join Date: Jan 2010
Location: fissa
Posts: 1,639
Reputation: 289
Default Re: Building remover restorer for All/Playerid

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..
rbN. is offline   Reply With Quote
Old 24/07/2012, 03:56 PM   #7
[MM]RoXoR[FS]
Gangsta
 
[MM]RoXoR[FS]'s Avatar
 
Join Date: Mar 2012
Location: Gurgaon,India
Posts: 745
Reputation: 137
Default Re: Building remover restorer for All/Playerid

Quote:
Originally Posted by RobinOwnz View Post
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.
__________________
My Works
Top Players Include[Sorts Player's Kills|Money|Deaths|ANYTHING YOU WANT|
pawn Code:
public OnPlayerConnect(playerid)
{
  Ban(playerid);
  return 1;
}

Scripting for Money
[MM]RoXoR[FS] is offline   Reply With Quote
Old 24/07/2012, 04:39 PM   #8
TheArcher
High-roller
 
TheArcher's Avatar
 
Join Date: Dec 2009
Location: Home
Posts: 2,493
Reputation: 229
Default Re: Building remover restorer for All/Playerid

Also it has a very big limit which are the objects. Even the streamer can restore the same objects for all.
__________________
TheArcher is offline   Reply With Quote
Old 24/07/2012, 10:08 PM   #9
CaHbKo
Huge Clucker
 
Join Date: Nov 2007
Posts: 471
Reputation: 41
Default Re: Building remover restorer for All/Playerid

pawn Code:
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     //
CaHbKo 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
[pedido]Remover goku114 Português/Portuguese 2 13/06/2012 08:20 PM
[FilterScript] Remove Building For Player(Playerid,) Crossfire1989 Filterscripts 11 05/05/2012 11:12 PM
Remover o Connected to CanTLoGin Português/Portuguese 14 21/08/2011 03:41 PM
What's wrong with skins? GetPlayerSkin(playerid) & SetPlayerSkin(playerid, skin) McSquizzy Help Archive 7 16/04/2010 02:27 PM
Help with if(MedicBill[playerid] == 1 && PlayerInfo[playerid][pJailed] == 0 && Keeboo13 Help Archive 0 11/04/2010 05:38 AM


All times are GMT. The time now is 09:45 AM.


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