Author Topic: Brick Making Limets  (Read 2039 times)

I am working on a thing for a cash mod and I want to make a set of bricks that can only be made if you have the right amount, so lets say you have the Melon Mod 1x1 brick and you had 100 cash that you could set it to - cash every time you make one of these bricks and then stop you from being able to make more when you no longer have the right amount of cash. I have been trying to think of an example but none have come to mind (apart from trench wars which I cant get my hands on anyway)

Does anyone know how I could do this?


Mmm melon..
Great help.

Code: [Select]
function serverCmdPlantBrick(%client){
if(%client.cash >= $BuildCost){
%client.cash = %client.cash-$buildCost;
Parent::serverCmdPlantBrick(%client);
} else if(%client.cash < $BuildCost){
messageclient(%client,"","\c6You dont have enough money, you need " @ ($CurrencyFront ? ($Currency @ "\c0" @ $BuildCost) : ("\c0" @ $BuildCost @ "\c6" @ $Currency)) @ " \c6to plant a brick");
}
}
Taken from Mr. Pickle's cashmod, hope this is what you wanted.

NOTE: You will have to make a $BuildCost for this to work.

EDIT: This must be in a package, or it will screw up your building.
« Last Edit: November 01, 2008, 07:36:07 PM by Darius »

That is very useful and will come in handy but it leaves one thing not answered.

 I will have a brick on my brick menu and it might be called cash mod 1x1, how can I make it so it only stops you from making if you this brick if you have no cash, but still leaving the other bricks so you can make as many as you like. Also this code has "server cmd" stuff how can I make it so it - the cash you have every time you make one of these bricks. So you don't need to say /plantbrick which seems a bit odd.

You don't need to say /plantbrick. It already happens when you press enter.

You don't need to say /plantbrick. It already happens when you press enter.

Oh silly me, but that does not solve the big prob here.

Great help.

Code: [Select]
function serverCmdPlantBrick(%client){
if(%client.cash >= $BuildCost){
%client.cash = %client.cash-$buildCost;
Parent::serverCmdPlantBrick(%client);
} else if(%client.cash < $BuildCost){
messageclient(%client,"","\c6You dont have enough money, you need " @ ($CurrencyFront ? ($Currency @ "\c0" @ $BuildCost) : ("\c0" @ $BuildCost @ "\c6" @ $Currency)) @ " \c6to plant a brick");
}
}
Taken from Mr. Pickle's cashmod, hope this is what you wanted.

NOTE: You will have to make a $BuildCost for this to work.

Yeah, thats even less help than me commenting on how appetizing the thought of a melon was. Thats just going to break brick planting on his server. If you don't even understand basic scripting I can't imagine why you keep posting here misleading and misinforming people.

Here is some nice code to manage brick planting costs:
Code: [Select]
package PlantLimits
{
     function serverCmdPlantBrick(%client)
     {
          if(!isObject(%client.player.tempBrick))
               return;

          if(%client.player.tempBrick.dataBlock.cost > 0)
          {
               if(%client.money < %client.player.tempBrick.dataBlock.cost)
               {
                    messageClient(%client,'','You can't afford to plant this brick.');
               }
               else
               {
                    %client.money -= %client.player.tempBrick.dataBlock.cost;
                    Parent::serverCmdPlantBrick(%client);
               }
          }
          else
               Parent::serverCmdPlantBrick(%client);
     }
};
activatePackage(PlantLimits);

Then in your brick dataBlock you can add:

Code: [Select]
dataBlock fxDTSBrickData(MelonBrick)
{
     blahblahblb = "blahbrick";
     category = "blah melon mod";

     cost = 100;
};

Then it will cost 100 of %client.money to plant that brick.
« Last Edit: November 01, 2008, 09:21:31 AM by Ephialtes »

Won't that still cost the player if they get a brick error?

Yeah, but thats his problem. This is Coding Help - I don't intend to write the whole thing for him. If he can't implement something as simple as this then he shouldn't even be attempting to make something.

If you post code, at least bother to post code that doesn't have a design flaw in it.  This is code that I used to manage building in a arctic survival RPG that I was making, but haven't the will to continue.  (Note that this is only the building part, the rest of my code isn't shown here)

Code: [Select]
function checkbrick(%obj)
{
switch(%obj.colorid)
{
case 0: %type="wood";
case 1: %type="stone";
case 2: %type="ice";
case 3: %type="raw_meat";
case 4: %type="meat";
case 5: %type="snow";
default: %type = "admin";
}
%x = %obj.getdatablock().bricksizex;
%y = %obj.getdatablock().bricksizey;
%z = %obj.getdatablock().bricksizez;
%vol = %x * %y * %z;
%client = %obj.client;
%amount = %client.resource[%type];
if(%type $= "snow")
{
if( %x > 2 )
{
commandtoclient(%client,'centerprint', "\c6That brick is too large to be made out of snow.", 3);
%obj.killbrick();
}
else if( %y > 4 )
{
commandtoclient(%client,'centerprint', "\c6That brick is too large to be made out of snow.", 3);
%obj.killbrick();
}
else if( %z > 6 )
{
commandtoclient(%client,'centerprint', "\c6That brick is too large to be made out of snow.", 3);
%obj.killbrick();
}
return;
}
if(%type $= "admin")
{
if(!%client.issuperadmin)
{
%obj.killbrick();
}
return;
}
if(%vol > %amount)
{
commandtoclient(%client,'centerprint', "Not enough" SPC %type @ "!", 3);
%obj.killbrick();
return;
}
%client.resource[%type]= %client.resource[%type] - %vol;
if($messagestep==2)
{
messagecurrentstock(%client);
}
}

package buildingrestrictions
{
function GameConnection::createPlayer(%this,%t)
{
Parent::createPlayer(%this,%t);
resetstock(%this);
}
function fxDTSBrick::onToolBreak(%obj, %client)
{
switch(%obj.colorid)
{
case 0: %type="wood";
case 1: %type="stone";
case 2: %type="ice";
case 3: %type="raw_meat";
case 4: %type="meat";
default: %type = "none";
}
%x = %obj.getdatablock().bricksizex;
%y = %obj.getdatablock().bricksizey;
%z = %obj.getdatablock().bricksizez;
if( %type !$= "none")
{
gather(%client, %x * %y * %z, %type);
}
Parent::onToolBreak(%obj, %client);
}
function fxDTSBrick::onPlant(%this,%brick)
{
Parent::onPlant(%this,%brick);
schedule(10,0,checkbrick, %this);
}
  function servercmdUseSprayCan(%client,%num)
{
servercmdcancelbrick(%client);
%client.currentcolor= %num;
switch(%num)
{
case 0: %type="wood";
case 1: %type="stone";
case 2: %type="ice";
case 3: %type="raw meat";
case 4: %type="meat";
case 5: %type="snow";
default: %type="admin";
}
if( %type $= "admin")
{
commandtoclient(%client,'centerprint', "\c6This paint is \c0ADMIN ONLY!", 3);
}
else
{
commandtoclient(%client,'centerprint', "\c6Currently building with \c2" SPC %type @ "\c6.", 3);
}
}
function servercmdUseFxCan(%client, %num)
{
commandtoclient(%client,'centerprint', "\c6Use of the Fx can is disabled.", 3);
return;
}
};
activatepackage(buildingrestrictions);
The code will have to be changed to work for you (since allot of this is stuff needed for my RPG specifically), but a combination of what Ephi and I posted will work.

There is probably a better way, but I don't know it, so if you want it, you'll have to figure it out yourself.
« Last Edit: November 01, 2008, 01:52:44 PM by laremere »

If you post code, at least bother to post code that doesn't have a design flaw in it.

Oh honestly. If I wrote code that didn't have a design floor, this guy wouldn't have to do anything. The "design flaw" in your code is that it doesn't even charge the user money.

Please don't post code that has design flaws, laremere!

I believe there is a function to get the brick volume that could condense the code a bit lare.

Oh honestly. If I wrote code that didn't have a design floor, this guy wouldn't have to do anything. The "design flaw" in your code is that it doesn't even charge the user money.
Wasn't that your entire argument against MegaScience?

Wasn't that your entire argument against MegaScience?
Megascience posted stuff that wouldn't even run in the first place and said "fix it up yourself".

I'm fairly certain Ephi's will at least run.

Megascience posted stuff that wouldn't even run in the first place and said "fix it up yourself".

I'm fairly certain Ephi's will at least run.
Fair enough.

Okay ephi don't rip my head off now please :c