Author Topic: Making a package?  (Read 1263 times)

Ok i am doing a little test but it seems there is something wrong. All i want to do is when you plant a brick it sends a message to all players saying "Hey".

Copied this code from CashmodII:

Code: [Select]
package CashPackage
}
function fxDTSbrick::Plant(%brick)
{
%e = Parent::Plant(%brick);
if(!%e)
{
%c = getbrickgroupfromobject(%brick).client;
if(isObject(%c) && isObject(%c.player) && isObject(%c.player.tempbrick))
{
%vol = %c.player.tempbrick.getVolume();
%cost = $Cash::BrickCostPerVolume / 10;
%amt = mFloatLength(%c.cashObj.cash,2);
if(%amt < %cost * %vol)
{
commandtoclient(%c,'centerprint',"\c6You need" SPC CashStr(%cost * %vol,"") SPC "\c6to plant this brick.",2);
%brick.schedule(0,"delete");
} else {
%c.cashObj.mod("Cash",0 - (%cost * %vol));
}
}
}
}
};
ActivatePackage(CashPackage);


This is my server.cs:

Code: [Select]
Package Test
{
function fxDTSbrick::Plant(%brick)
{
%e = Parent::Plant(%brick);
if(!%e)
{
MessageAll('', "Hey");
}
}
};
ActivatePackage(Test);
« Last Edit: July 09, 2010, 01:50:43 PM by tyler0 »

Ok, I'm not that knowledgeable, but shouldn't your server.cs have:


Code: [Select]
exec("./otherfilenamehere.cs");

at the end or something?

Ok i am doing a little test but it seems there is something wrong. All i want to do is when you plant a brick it sends a message to all players saying "Hey".

Copied this code from CashmodII:
-snip-

This is my server.cs:

Code: [Select]
Package Test
{
function fxDTSbrick::Plant(%brick)
{
%e = Parent::Plant(%brick);
if(!%e)
{
MessageAll('', "Hey");
}
}
};
ActivatePackage(Test);

Take the %e out completly.
Like this:

Code: [Select]
package test
{
function fxDTSbrick::Plant(%brick)
{
%e = Parent::Plant(%brick);
MessageAll('', "Hey");
}
};
activatepackage(test);

Take the %e out completly.
Like this:

Code: [Select]
package test
{
function fxDTSbrick::Plant(%brick)
{
%e = Parent::Plant(%brick);
MessageAll('', "Hey");
}
};
activatepackage(test);


Tried it but didn't work... :(

Well... Now you have no use for %e, also, I think you have to return the parent. Like this
Code: [Select]
package test
{
function fxDTSbrick::Plant(%brick)
{
return Parent::Plant(%brick);
MessageAll('', "Hey");
}
};
activatepackage(test);

Code: [Select]
Package Test
{
function fxDTSbrick::onPlant(%brick)
{
Parent::onPlant(%brick);

if(isObject(%brick))
{
MessageAll('', "Hey");
}
}
};
ActivatePackage(Test);

Code: [Select]
Package Test
{
function fxDTSbrick::onPlant(%brick)
{
Parent::onPlant(%brick);

if(isObject(%brick))
{
MessageAll('', "Hey");
}
}
};
ActivatePackage(Test);

nope :(

Is your add-on active in the add-ons list?

Take the %e out completly.
Like this:

Code: [Select]
package test
{
function fxDTSbrick::Plant(%brick)
{
%e = Parent::Plant(%brick);
MessageAll('', "Hey");
}
};
activatepackage(test);

Please don't post if you don't know what you're doing. This will cause the function to return "Hey" every time it is called. If you're going to take out the if statement you must do this:

Code: [Select]
package test
{
function fxDTSbrick::Plant(%brick)
{
%e = Parent::Plant(%brick);
MessageAll('', "Hey");
return %e;
}
};
activatepackage(test);

The reason I'm making a big deal of it is .plant(); returns a number value for the error, which many mods probably depend on. For example

if(%this.plant() == 3)
   messageClient(%client,'',"That brick's floating!");

Defaultly, if the brick was floating it would return 3, and that check would work. With your code, it would return "Hey". I don't believe "Hey" is equal to three, even if the brick was floating.

Also; Cry:
Also, I think you have to return the parent. Like this
Code: [Select]
package test
{
function fxDTSbrick::Plant(%brick)
{
return Parent::Plant(%brick);
MessageAll('', "Hey");
}
};
activatepackage(test);
return; skips all the rest of the function, so that wouldn't work at all. You're right about returning the parent, but you'd have to put it below everything like I noted earlier.
« Last Edit: July 10, 2010, 04:03:50 PM by Triple Nickels »

Why not just modify fxDtsBrick::onPlant()? Is .plant() even overwritable?

it must be... because the Cashmod script edits if you have the "Cash" to plant a that brick (the volume of the brick).