Author Topic: OnPlant: Problems...  (Read 1276 times)

I've been trying to script a lil' cash mod for educational purposes and I am having problems with my brick plant detection. Can someone show me the right way to make this?
Code: [Select]
function serverCmdplantbrick(%client, %brick)
{
if(%client.Blocks>=1);
{
Parent::ServerCmdplantbrick(%client);
%client.Blocks--;
}
else
{
schedule(75,0,%brick.killbrick);
}
}
I've tried a few forms other than this one and none of them have been sucessful. (For example, fxDTSbrick::onPlant()...)

Thanks!

Please tell me it's packaged.

There are different ways to do this, I'll just give you my version:
Code: [Select]
package BlockBuild
{
   function fxDTSBrick::OnPlant(%data, %brick)
   {
      if(%client.blocks>=1);
      {
         Parent::OnPlant(%data, %brick)
         %client.blocks--;
      }
      else
      {
         %brick.schedule(0,delete);
         %brick.getGroup().client.centerPrint("<just:center><color:ffffff>You do not have enough blocks to place this brick",3);
      }
   }
};
activatePackage(BlockBuild);

Or you can subtract the amount of resources compared to the area of the brick like so. This isn't tested since I'm not on my home computer.

Code: [Select]
function serverCmdplantbrick(%client, %brick)
{
%Bmass = %brick.BrickSizeX * %brick.BrickSizeY * %brick.BrickSizeZ;

if($BrickMass == "On")
{
if(%Bmass <= 0)
{
echo("Invalid Brick Mass!");
%brick.BrickKill();
return;
}
else
{
Parent::OnPlant(%data, %brick)
%client.Bricks -= %Bmass;
}
}
}

Or you can subtract the amount of resources compared to the area of the brick like so. This isn't tested since I'm not on my home computer.

Code: [Select]
function serverCmdplantbrick(%client, %brick)
{
%Bmass = %brick.BrickSizeX * %brick.BrickSizeY * %brick.BrickSizeZ;

if($BrickMass == "On")
{
if(%Bmass <= 0)
{
echo("Invalid Brick Mass!");
%brick.BrickKill();
return;
}
else
{
Parent::OnPlant(%data, %brick)
%client.Bricks -= %Bmass;
}
}
}
I'm pretty sure it doesn't matter, but I don't believe you need quotes around "on", since it's one word. The parent also looks funny to me (although I wouldn't know) your modifying servercmdplantbrick, but your parenting ::onPlant. Just pointing out what looks funny to me, simply correct me if i'm wrong.

Yeah, that is an error, it wouldn't work.

Well, I feel like an idiot. When I wrote that I had two different notepads open and I guess that I took the wrong snippet from the other notepad. Also, I do believe you need the quotes because it's referring to it as a string, although I have no idea because I'm not on my home computer. Once I get to my other computer I'll post a working version.

« Last Edit: June 29, 2009, 12:07:53 AM by Kunit »

Well, I feel like an idiot. When I wrote that I had two different notepads open and I guess that I took the wrong snippet from the other notepad. Also, I do believe you need the quotes because it's referring to it as a string, although I have no idea because I'm not on my home computer. Once I get to my other computer I'll post a working version.



Plus %brick is not an argument of servercmdplantbrick.

Plus %brick is not an argument of servercmdplantbrick.
I'm not even sure what he's trying to kill in 75 miliseconds if there was no brick planted in the first place.

Well, I feel like an idiot. When I wrote that I had two different notepads open and I guess that I took the wrong snippet from the other notepad. Also, I do believe you need the quotes because it's referring to it as a string, although I have no idea because I'm not on my home computer. Once I get to my other computer I'll post a working version.

But you used == instead of $=?
So you're saying that's it's not a string. It still works, just you should use $= for checking strings.
And lilboarder is correct, you don't need the quotes because it's only 1 word but it's still better to use quotes.

fxDTSBrick::BrickKill does not exist. I assume you meant fxDTSBrick::killBrick.


Your code won't work because you check for %client.blocks when you don't even have %client.

Code: [Select]
function serverCmdplantbrick(%client)
{
if(%client.Blocks>=1);
{
Parent::ServerCmdplantbrick(%client);
%client.Blocks--;
}
else
%client.centerPrint("<just:center><color:ffffff>You do not have enough blocks to place this brick",3);
}
This way the brick isn't even planted at all if they don't have the blocks, and we have %client as an argument so it will work.

Plus %brick is not an argument of servercmdplantbrick.
Yep, what I posted was completely inaccurate.