Yup, here you go. I'll modify something from CityRPG.
If there's any syntax or logical errors you cannot resolve, I don't bite.
function Armor::onCollision(%this, %obj, %col, %vec, %speed)
{
// Sanity Checks.
// + Does %obj exist?
// + Does %col exist?
// + Is %obj a player?
// + Is %col an item?
if( isObject(%obj) && isObject(%col) && (%obj.getType() & $TypeMasks::PlayerObjectType) && (%col.getType() & $TypeMasks::ItemObjectType))
{
// Get the datablock once.
%colDB = %col.getDatablock();
// Get our datablock once.
%objDB = %obj.getDatablock();
// Reference variable. If we don't use the pick-up, we don't need to delete it.
%wasUsed = false;
// If we do not have either significant property, just return the parent.
if(!%colDB.pickupHealth && !%colDB.pickupAmmo)
return parent::onCollision(%this, %obj, %col, %vec, %speed);
// Does the item's datablock have the .pickupHealth variable defined and grater than 0?
// Does our %obj have damage? (Also, define %damage to save time)
if(%colDB.pickupHealth > 0 && (%damage = %obj.getDamageLevel()) > 0)
{
// Healing amount is our max HP multiplied by the percent healing of the pick-up.
%heal = %objDB.maxDamage * (%colDB.pickupHealth / 100);
// If our heal is as much or greater than our damage, damage sets to zero.
if(%heal >= %damage)
%damage = 0;
// Else, damage is the remainder.
else
%damage -= %heal;
// Apply our damage modified level.
%obj.setDamageLevel(%damage);
// Set this to true.
%wasUsed = true;
// If you want to add an emote, do it here.
//%obj.emote(healImage, true);
}
// I have no loving clue how the ammo pick-up system works. You'll have to figure it out.
if(%colDB.pickupAmmo > 0 && %someSortOfObjPropertyOrSomething)
{
// Do stuff to give ammo.
doStuffToGiveAmmo();
// Set wasUsed to try.
%wasUsed = true;
}
// If we were used, delete our item and DO NOT return the parent.
if(%wasUsed)
%col.delete();
return %obj;
}
return parent::onCollision(%this, %obj, %col, %vec, %speed);
}
Package this.