Author Topic: onPlant in trigger.  (Read 912 times)

I'm trying to make it so you can only plant a certain type of brick in a trigger, but it doesn't seem it work.
Quote
package testp
{
        function bricktestbrickData::onPlant(%this,%brick,%client)
        {
             if(%client.intesttrig)
             {
                %client.hastbrick = 1;   
             }
   
             if(!%client.intesttrig)
             {
                     %brick.killbrick();
                          return;
                          %client.hastbrick = 0;
             }
        }
};
activatepackage(testp);

Edit: Updated it, but now it wont let you plant it, even if you are in the trigger.
« Last Edit: August 31, 2008, 06:18:00 AM by TheBoltster »

You need to call Parent::onPlant() somewhere in there for the normal plant code and you need to actually get %client - it isn't an argument of fxDTSBrick::onPlant.

Quote
package asdf
{
function brickhousebData::onPlant(%this,%obj)
{
   if(%obj.client.inhone)
   {
      %obj.client.hashouse = 1;   
      Parent::onPlant(%this,%obj);
   }
   
   if(!%obj.client.inhone)
   {
   schedule(100, false, "killBrick", %this);
   %obj.client.hashouse = 0;
   return;
   }
}
};
activatepackage(asdf);

Hone = Trigger

But it still doesn't work.
« Last Edit: August 31, 2008, 06:52:36 AM by TheBoltster »

Quote
package asdf
{
 ...
};
activatepackage(asfd);

Yeh, but thats not the problem, I just made up those names instead of the real, and long ones.

EDIT: I don't think %obj is the person who's planting it. Try %this.client and %this.client.player.

Isnt %this the brick?

Possibly. %this might be the datablock rather than the brick. (Making %obj the brick, but that wouldn't work with %obj.inhone)

The brick's "client" is set either when it's created or when it's planted (I don't know), only for bricks created in the current server. (not loaded bricks)

If you do get this to work, you'll be able to plant the brick itself anywhere as long as you are standing in the trigger...

Code: [Select]
package testp
{
        function bricktestbrickData::onPlant(%this,%brick,%a)
        {
             %client=%brick.client;
             if(%client.intesttrig)
             {
                %client.hastbrick = 1;   
             }
   
             if(!%client.intesttrig)
             {
                     %brick.killbrick();
                          %client.hastbrick = 0;
                     return;
             }
             parent::onplant(%this,%brick,%a);
        }
};
activatepackage(testp);

If that doesn't work, stuff it in a function and schedule it for 75 ms after the plant process, and that should work.

If you do get this to work, you'll be able to plant the brick itself anywhere as long as you are standing in the trigger...

This means that your current method of doing it wouldn't work too well.

You could check the brick's position (center +/- brick sizes) against the position +/- widths and heights of the trigger you are in, and only place the brick if you are in a house that you 'own' and the brick is in the same area.