Drop/Throw All Items in Player Inventory
by Raster Ron · in Torque 3D Professional · 08/08/2013 (10:59 pm) · 3 replies
Hey guys,
I'm just trying to get around Torque Script and would like to have the player drop/throw all items in the inventory.
I see that current code in scripts/server/player.cs only drops the current weapon/ammo and a health patch:
A little confused on how the default inventory works but I would still like to use it for my game.
How do I accomplish this?
I'm just trying to get around Torque Script and would like to have the player drop/throw all items in the inventory.
I see that current code in scripts/server/player.cs only drops the current weapon/ammo and a health patch:
function Armor::onDisabled(%this, %obj, %state...
{
// Toss current mounted weapon and ammo if any
%item = %obj.getMountedImage($WeaponSlot).item;
if (isObject(%item))
{
%amount = %obj.getInventory(%item.image.ammo);
if (!%item.image.clip)
warn("No clip exists to throw for item ", %item);
if(%amount)
%obj.throw(%item.image.clip, 1);
}
// Toss out a health patch
%obj.tossPatch();
}A little confused on how the default inventory works but I would still like to use it for my game.
How do I accomplish this?
About the author
Artist/Gamer/Developer/Full Stack Web Developer
#2
08/09/2013 (8:38 am)
Just create an array that contains a list of all of the items your player "could" carry, then perform a loop on each of the array items checking if the player has that item, and throwing it if he does.
#3
Anyway, I ended up using this solution:
Not the best one but it will do for now. I guess a custom inventory would be better to create as Robert pointed out with the arrays, etc.
08/13/2013 (4:15 pm)
Thanks for the input guys. Yes, Richard I did notice it is a clip not ammo (got a bit confused there lol)Anyway, I ended up using this solution:
%availableWeapons = 7;
for(%count = 0; %count < %availableWeapons; %count++) {
%item = %obj.getMountedImage($WeaponSlot).item;
if (isObject(%item))
{
%amount = %obj.getInventory(%item.image.ammo);
if (!%item.image.clip)
warn("No clip exists to throw for item ", %item);
if(%amount)
%obj.throw(%item.image.clip, 1);
if(%obj.hasInventory(%item)){
if(%item !$= "ProxMine") {
%obj.throw(%item);
echo("dropped " @ %item);
}
}
%obj.cycleWeapon( "next" );
}Not the best one but it will do for now. I guess a custom inventory would be better to create as Robert pointed out with the arrays, etc.
Torque Owner Richard Ranft
Roostertail Games
As for how to throw everything, you might have to extend the inventory system a little. Dig into scripts/server/inventory.cs, scripts/server/gameCore.cs (specifically in GameCore::loadOut()) and examine how getInventory() and setInvetory() are used. I don't think the system lends itself readily to your task but it shouldn't take too much tweaking....