Blockland Forums > Modification Help
Making Pickupable Gold
jes00:
How would I make pickupable gold and how would I set the text above it and set what happens when you pick it up?
Swollow:
--- Code: ---datablock ItemData(GoldItem)
{
category = "Weapon"; // Mission editor category
className = "Weapon"; // For inventory system
shapeFile = "base/data/shapes/brickweapon.dts";
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;
rotate = true;
uiName = "Gold";
doColorShift = false;
colorShiftColor = "0.823 0.627 0.117 1.000";
canDrop = true;
};
function GoldItem::onAdd(%this, %obj)
{
%obj.setShapeName("TEXT HERE");
Parent::onAdd(%this, %obj);
}
package GoldPackage
{
function Armor::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f)
{
if(%col.dataBlock $= "GoldItem" && %obj.getDamagePercent() < 100 && %col.canPickup)
{
Parent::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f);
//stuff
}
}
};
activatePackage(GoldPackage);
--- End code ---
jes00:
--- Quote from: swollow on January 17, 2012, 11:31:10 AM ---
--- Code: ---datablock ItemData(GoldItem)
{
category = "Weapon"; // Mission editor category
className = "Weapon"; // For inventory system
shapeFile = "base/data/shapes/brickweapon.dts";
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;
rotate = true;
uiName = "Gold";
doColorShift = false;
colorShiftColor = "0.823 0.627 0.117 1.000";
canDrop = true;
};
function GoldItem::onAdd(%this, %obj)
{
%obj.setShapeName("TEXT HERE");
Parent::onAdd(%this, %obj);
}
package GoldPackage
{
function Armor::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f)
{
if(%col.dataBlock $= "GoldItem" && %obj.getDamagePercent() < 100 && %col.canPickup)
{
Parent::onCollision(%this, %obj, %col, %a, %b, %c, %d, %e, %f);
//stuff
}
}
};
activatePackage(GoldPackage);
--- End code ---
--- End quote ---
???
--- Code: ---function serverCmdDropGold(%client, %num)
{
if(%client.Gold >= %num && (%num >= 1))
{
%client.Gold -= %num;
messageClient(%client,'',"\c6You dropped \c3" @ %num @ "\c6 gold.");
%GoldBar = new Item()
{
datablock = GoldBarItem;
canPickup = false;
};
%GoldBar.setVelocity(VectorScale(%client.player.getEyeVector(), 10));
MissionCleanup.add(%GoldBar);
%GoldBar.setShapeName(%amount);
}
else
{
messageClient(%client,'',"\c6Please enter a valid amount of gold to drop.");
}
}
package GoldBar
{
//=========================================================================
// On Gold Bar Pickup
//=========================================================================
function Armor::onCollision(%this, %obj, %col, %thing, %other)
{
if(%col.getDatablock().getName() $= "GoldBarItem")
{
if(isObject(%obj.client))
{
if(isObject(%col))
{
if(%obj.client.minigame)
%col.minigame = %obj.client.minigame;
%this.Gold += %col.value;
messageClient(%obj.client, '', "\c6You picked up\c3" SPC %col.value SPC "\c6gold.");
%col.canPickup = false;
%col.delete();
}
else
{
%col.delete();
MissionCleanup.remove(%col);
}
}
}
parent::onCollision(%this, %obj, %col, %thing, %other);
}
};
activatePackage(GoldBar);
//=========================================================================
// Gold Bar Datablock
//=========================================================================
datablock ItemData(GoldBarItem)
{
category = "Weapon";
className = "Weapon";
shapeFile = "./Gold_Bar.dts";
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;
uiName = "";
doColorShift = false;
colorShiftColor = "252 241 0 1";
image = GoldBarImage;
candrop = true;
canPickup = true;
};
--- End code ---
Headcrab Zombie:
For serverCmdDropGold, You need to also have the position of the gold bar
Something like "position = %client.player.getPosition();" in the new item declaration.
Also I would round up the amount of gold dropped.
jes00:
--- Quote from: Headcrab Zombie on January 17, 2012, 06:06:50 PM ---For serverCmdDropGold, You need to also have the position of the gold bar
Something like "position = %client.player.getPosition();" in the new item declaration.
Also I would round up the amount of gold dropped.
--- End quote ---
Why?