Author Topic: How do you check for particular bricks planted by individual players?  (Read 3309 times)

For example, if you wanted to run a check though all a player's bricks to see whether they have any 1x1x5 bricks planted?

%count = <brickgroup>.getCount();

for (%i = 0; %i < %count; %i++) {
    %brick = <brickgroup>.getObject(%i);
    ...
}


where <brickgroup> is something such as %client.brickGroup, BrickGroup_<BLID>, etc.

Depending on how often you check and how many bricks that player has, it may induce some strain on the server. I suggest you implement a system that keeps track if a player has some of those bricks placed instead of iterating through potentially massive brickgroups.

Depending on how often you check and how many bricks that player has, it may induce some strain on the server. I suggest you implement a system that keeps track if a player has some of those bricks placed instead of iterating through potentially massive brickgroups.
Sounds more ideal, not sure how I would go about that though.

is it a specific brick, or could it be any kind of brick?

I'd package the brick placing function to set %client.brickplaced[datablock] to true, and then just check that value
you'd probably need to loop through their bricks on spawn though, in case they leave and come back

you'd probably need to loop through their bricks on spawn though, in case they leave and come back

Alternatively, you could package the onLoadPlant function (which gets called when a brick is loaded) and store the information on the brickgroup itself so that its persistent.

And instead of using an array like %brickgroup.brickPlaced[%datablock] you should use a simset, so that you can both get each brick, and know when the bricks have been deleted (as they'll be automatically removed from the set).

Wouldn't they be detached from the original set the brick came from if you try to add it to another set?

I've made a script object class like how the minigame does with clients using addMember and removeMember, except I'm using it for all kinds of objects like keeping storage for a brick. I can loop the count if needed.

Wouldn't they be detached from the original set the brick came from if you try to add it to another set?

I've made a script object class like how the minigame does with clients using addMember and removeMember, except I'm using it for all kinds of objects like keeping storage for a brick. I can loop the count if needed.

An object can only be a member of one SimGroup, that is correct. He was however talking about a SimSet, for which the former is not the case.

Simsets made this incredibly easy and inexpensive. 
Now how do I make sure these objects save/load as the server closes/boots, as associated to the player that plants them?

Code: [Select]
function SimSet::addTezModsBrick(%this,%brick)
{
if(!isObject(%brick))
return;

if(%this.TezModsBrickCount $= "")
%this.TezModsBrickCount = 0;

%this.TezModsBrick[%this.TezModsBrickCount] = %brick;
%this.TezModsBrickCount++;
}
function SimSet::removeTezModsBrick(%this,%brick)
{
for(%i=0;%this.TezModsBrick[%i] !$= "";%i++)
{
if(%this.TezModsBrick[%i] == %brick)
{
for(%j=%i;%this.TezModsBrick[%j] !$= "";%j++)
{
%this.TezModsBrick[%j] = %this.TezModsBrick[%j+1];
}
%this.TezModsBrickCount--;
}
}
}

function fxDTSBrick::onPlant(%this)
{
Parent::onPlant(%this);

if(isObject(%this.getGroup()) && %this.dataBlock.isTezModsBrick)
%this.getGroup().addTezModsBrick(%this);

}
function fxDTSBrick::onRemove(%this)
{
if(isObject(%this.getGroup()) && %this.dataBlock.isTezModsBrick)
%this.getGroup().removeTezModsBrick(%this);

Parent::onRemove(%this);
}

if you're binding it to ID, just package onloadplant for when the bricks are loaded
that way it's saved in save files, instead of needing to make a separate file for it

Code: [Select]
new SimSet(YourBrickTracker);

package YourBrickTrackerPackage {
    function brick1x1x5Data::onPlant(%this) {
        YourBrickTracker.add(%this);
        parent::onPlant(%this);
    }

    function brick1x1x5Data::onLoadPlant(%this) {
        YourBrickTracker.add(%this);
        parent::onLoadPlant(%this);
    }
};
activatePackage(YourBrickTrackerPackage);

Then, for count:
YourBrickTracker.getCount()

For individual count:
%count = YourBrickTracker.getCount(); for(%i = 0; %i < %count; %i++) if(YourBrickTracker.getObject(%i).getGroup().BL_ID == XXXX) %brickCount++;

%brickCount will be the total for that user. If you only ever need to access them on a per-user basis, you may want to consider making SimSets for every player (if(!isObject("MySimSet_"@%this.owner.BL_ID)) new SimSet("MySimSet_"@%this.owner.BL_ID);) and add the bricks to their individual set ("MySimSet_"@%this.owner.BL_ID) instead.
« Last Edit: June 30, 2015, 02:33:20 AM by $trinick »

Yeah but wouldn't that detach from their brickgroup?

Code: [Select]
new SimSet(YourBrickTracker);

package YourBrickTrackerPackage {
    function brick1x1x5Data::onPlant(%this) {
        YourBrickTracker.add(%this);
        parent::onPlant(%this);
    }

    function brick1x1x5Data::onLoadPlant(%this) {
        YourBrickTracker.add(%this);
        parent::onLoadPlant(%this);
    }
};
activatePackage(YourBrickTrackerPackage);

Instead of using both ::onPlant and ::onLoadPlant, you can just do ::onAdd since it covers both cases.

Code: [Select]
new SimSet(YourBrickTracker);

package YourBrickTrackerPackage {
    function brick1x1x5Data::onAdd(%this) {
        YourBrickTracker.add(%this);
        parent::onAdd(%this);
    }
};
activatePackage(YourBrickTrackerPackage);

Yeah but wouldn't that detach from their brickgroup?

You seem to not understand the difference between a group and a set.

An object has to be in exactly one group (simGroup or scriptGroup or a GUI object), but can be in as many sets (simSet) as you like.



I would recommend that you had a separate simSet for each brickgroup, unless you'll never need to get an individuals bricks.
« Last Edit: June 30, 2015, 03:23:55 PM by boodals 2 »

-snip-, nevermind.

Was about to comment on something about onAdd but I was quickly reminded how poorly written the brick placement system is, so it's irrelevant anyways. The "ultimate" way to safely check if your brick is planted and modify behavior is to just overwrite all the ways players are able to plant bricks (i.e ServerCmdPlantBrick, load brick function..) but it's more work than its worth. onAdd should suffice.


Edit: see http://forum.blockland.us/index.php?topic=281430.msg8445534#msg8445534
« Last Edit: July 06, 2015, 11:43:33 PM by Val »