Author Topic: FarmMod  (Read 2616 times)

Recently I have tried to code something called Farm Mod. I got the brick and stuff working and all, I can place it.

But apparently whenever I click it, it doesn't do anything. Since there's probably a ton of people on the forums. I was wondering if you could help me out.

Here is the code.

Code: [Select]
datablock fxDTSBrickData(FarmRPGBlueberryData)
{
brickFile = "Add-Ons/Script_FarmMod/brickShapes/1x1F.blb";
category = "Farm Mod";
subCategory = "Small Plants";
uiName = "Blueberry Plant";
iconName = "Add-Ons/Script_FarmMod/brickIcons/blueberry.png";
};

function FarmRPGBlueberryData::Plant(%datablock, %client)
{
%datablock.setcolor(54);
}


function FarmRPGBlueberryData::Activate(%datablock, %client)
{
if(!%datablock.isWatered)
{
messageClient(%client,'',"\c6You have watered your \c5blueberry\c6 plant.");
%datablock.isWatered = 1;
schedule(120000,0,eval,"%datablock.growth = 1;");
schedule(120000,0,eval,"%datablock.setcolor(55);");
schedule(120000*2,0,eval,"%datablock.growth = 2;");
schedule(120000*2,0,eval,"%datablock.setcolor(56);");
schedule(120000*3,0,eval,"%datablock.growth = 3;");
schedule(120000*3,0,eval,"%datablock.setcolor(57);");
schedule(120000*4,0,eval,"%datablock.growth = 4;");
schedule(120000*4,0,eval,"%datablock.setcolor(58);");
schedule(120000*5,0,eval,"%datablock.growth = 5;");
schedule(120000*5,0,eval,"%datablock.setcolor(59);");
}
else if(%datablock.isWatered)
{
messageClient(%client,'',"\c6You have already watered your \c5blueberry\c6 plant!");
}
else if(%datablock.growth = 1)
{
messageClient(%client,'',"\c6The \c5blueberry\c6 plant is \c320\c6% done!");
}
else if(%datablock.growth = 2)
{
messageClient(%client,'',"\c6The \c5blueberry\c6 plant is \c340\c6% done!");
}
else if(%datablock.growth = 3)
{
messageClient(%client,'',"\c6The \c5blueberry\c6 plant is \c360\c6% done!");
}
else if(%datablock.growth = 4)
{
messageClient(%client,'',"\c6The \c5blueberry\c6 plant is \c380\c6% done!");
}
else if(%datablock.growth = 5)
{
messageClient(%client,'',"\c6You harvested your \c5blueberry \c6plant!");
%datablock.growth = 0;
%datablock.setcolor(63);
%datablock.isWatered = 0;
%client.blueberry += 1;
}
return;
}

Post if any of you can fix this. It should work a LITTLE BIT like Cromedome's drug mod.

There is no syntax errors or anything, its all clean. It just doesn't do anything on activate.


Thanks for your help :)

EDIT: Topic was moved by Badspot.
« Last Edit: November 20, 2011, 12:26:39 AM by FFSO »

It's onActivate, not Activate

Also I believe onActivate will only be called if there is an onActivate event on the brick

Code: [Select]
else if(%datablock.growth = 1)
Really?

You might wanna also change:
Code: [Select]
function FarmRPGBlueberryData::Plant(%datablock, %client)
{
%datablock.setcolor(54);
}
To:
Code: [Select]
function FarmRPGBlueberryData::onPlant(%datablock, %client)
{
%datablock.setcolor(54);
}

Code: [Select]
function fxDTSbrick::UpDuplicate(%this)
{
%xsize = %this.getDatablock().brickSizeX * 0.2;
%pos = vectorAdd(%this.getPosition(), %xsize SPC "0 0");
%brick = new FxDTSbrick()
{
datablock = %this.getDatablock();
position = %pos;
rotation = %this.rotation;
colorID = %this.colorID;
scale = "1 1 1";
angleID = %this.angleID;
colorFxID = %this.colorFxID;
shapeFxID = %this.shapeFxID;
isPlanted = 1;
client = %this.client;
};
%brick.plant();
%brick.setTrusted(1);
if(isObject(%this.getGroup()))
{
%this.getGroup().add(%brick);
}
$Server::BrickCount++;
return %brick;
}

function Plant::dead(%this)
{
%this.killBrick();
}

function Plant::onActivate(%this,%obj,%player)
{
if(%obj.finished)
{
%this.killBrick();
%player.client.FinishedPlants++;
messageClient(%client,'',"You have harvested your Grown Plant!");
}
}
function FarmingTick()
{
cancel($FarmingTick);
for(%i=0;%i<FarmBricks.getCount();%i++)
{
%brick = FarmBricks.getObject(%i);
if(%brick.stage == 10)
{
%brick.finished += 1;
}
else if(%brick.finished == 3)
%brick.dead();
else
{
%brick.UpDuplicate();
%brick.stage++;
}
}
$FarminTick = schedule(60000,0,FarmingTick);
}

In this mod, the brick actually grows up instead of just changing colors.
but heres the fixed version:
Code: [Select]
datablock fxDTSBrickData(FarmRPGBlueberryData)
{
brickFile = "Add-Ons/Script_FarmMod/brickShapes/1x1F.blb";
category = "Farm Mod";
subCategory = "Small Plants";
uiName = "Blueberry Plant";
iconName = "Add-Ons/Script_FarmMod/brickIcons/blueberry.png";
};

function FarmRPGBlueberryData::onPlant(%datablock, %client)
{
%datablock.setcolor(54);
}


function FarmRPGBlueberryData::onActivate(%datablock, %client)
{
if(!%datablock.isWatered)
{
messageClient(%client,'',"\c6You have watered your \c5blueberry\c6 plant.");
%datablock.isWatered = 1;
schedule(120000,0,eval,"%datablock.growth = 1;");
schedule(120000,0,eval,"%datablock.setcolor(55);");
schedule(120000*2,0,eval,"%datablock.growth = 2;");
schedule(120000*2,0,eval,"%datablock.setcolor(56);");
schedule(120000*3,0,eval,"%datablock.growth = 3;");
schedule(120000*3,0,eval,"%datablock.setcolor(57);");
schedule(120000*4,0,eval,"%datablock.growth = 4;");
schedule(120000*4,0,eval,"%datablock.setcolor(58);");
schedule(120000*5,0,eval,"%datablock.growth = 5;");
schedule(120000*5,0,eval,"%datablock.setcolor(59);");
}
else if(%datablock.isWatered)
{
messageClient(%client,'',"\c6You have already watered your \c5blueberry\c6 plant!");
}
else if(%datablock.growth == 1)
{
messageClient(%client,'',"\c6The \c5blueberry\c6 plant is \c320\c6% done!");
}
else if(%datablock.growth == 2)
{
messageClient(%client,'',"\c6The \c5blueberry\c6 plant is \c340\c6% done!");
}
else if(%datablock.growth == 3)
{
messageClient(%client,'',"\c6The \c5blueberry\c6 plant is \c360\c6% done!");
}
else if(%datablock.growth == 4)
{
messageClient(%client,'',"\c6The \c5blueberry\c6 plant is \c380\c6% done!");
}
else if(%datablock.growth == 5)
{
messageClient(%client,'',"\c6You harvested your \c5blueberry \c6plant!");
%datablock.growth = 0;
%datablock.setcolor(63);
%datablock.isWatered = 0;
%client.blueberry += 1;
}
return;
}

That is still wrong. Growth should not be a property of the datablock.

That is still wrong. Growth should not be a property of the datablock.
Instead criticizing people, why don't you help?

You think I'm getting personal because I said your "correction" was wrong? I stated it was wrong and gave you a tip about what was wrong. If you want me to help you more then baby better put his bib on because here comes the airplane.

You think I'm getting personal because I said your "correction" was wrong? I stated it was wrong and gave you a tip about what was wrong. If you want me to help you more then baby better put his bib on because here comes the airplane.
Even moderators hate you Cheese! I was ahead of the group!

Lol this Coding Help topic is turning into a drama between Ephialtes and cheese6

Code: [Select]
else if(%datablock.growth = 1)
Really?

Well, how else would I keep track of growth? I'm trying to make this to the point where it can become a usefull add-on for everyone to use.

Also, I'm sure its activate, not onActivate. This isn't events here

I might just try changing it all. Gimme a sec.

And this is a stuff load better then the crap I used to try to post on RTB forums, correct?

EDIT: I changed it. These are the things I changed.

Code: [Select]
FarmRPGBlueberryData::onPlant(%datablock, %client)
And

Code: [Select]
FarmRPGBlueberryData::onActivate(%datablock, %client)
I am starting to think that I am turning the variables wrong in
Code: [Select]
(%datablock, %client)
Because I don't really think the "%datablock" records the object number.

I'm ficklefarkled in my corn stalk :)
« Last Edit: November 20, 2011, 12:21:39 PM by Freebuild »

Well, how else would I keep track of growth? I'm trying to make this to the point where it can become a usefull add-on for everyone to use.
The object, not the datablock

Also, I'm sure its activate, not onActivate. This isn't events here
If you want it to do something when you click it, it's onActivate (which I believe also requires an onActivate event on the brick for it to even be called)
If you don't want it to do something when you click it, then your function name is misleading


::onPlant has two argument:, the datablock, and the individual brick
::onActivate has five arguments: the brick, the player who clicked it, the client who clicked it, the position of the brick, and some sort of vector that I'm not sure what it means

You're handicapped if you really think you need an "onActivate event" to make it be called.

That would have nothing to do with that, think about what your saying and if it sounds right and would be true.