Blockland Forums > Modification Help
Items that restore health and ammunition on pick up?
(1/2) > >>
Demian:
I've been planning on making these TF2 ammo and health packs, but I lack the scripting skills. Let's assume I have all the models done that I need. How do I make an item like any other but it restores your health when you walk over it? It doesn't go into your inventory, it just disappears for X seconds and restores X amount of the players health. The time and amount of health is set in RTB prefs. Also, if I were using Tier Tactical 2 ammo system, how would I make it recover ammo?

I am not a scripter so I am looking for more of copypaste snippets of code to add to the item script.
Iban:
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.


--- Code: ---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);
}
--- End code ---

Package this.
Red_Guy:
nicely commented.

for healing - i found there is an applyRepair() function you can use.  so you can change things up a little:

--- Code: ---// Apply a repair amount based on the pick-up item.
%obj.applyRepair(%colDB.pickupHealth);
// Set this to true.
%wasUsed = true;

// If you want to add an emote, do it here.
//%obj.emote(healImage, true);

--- End code ---

no need to mess with percentages and such -- just add XX health to the player.
Space Guy:
The TF2 HP/ammo packs do percentages rather than fixed amounts so Iban's is fine. You may want to just make the item invisible for a few seconds rather than delete it entirely for static health pickups, though - check if it's a dropped one (Candy Cane/Medieval do this) or placed one first.
Chrono:
Playertypes usually have 100 health anyways.
Navigation
Message Index
Next page

Go to full version