Multi Slot Weapon Management
by joint heir · in Torque Game Engine · 06/10/2005 (2:10 pm) · 2 replies
Hi everybody. I'm trying to script a multi-slot weapon system. Below is an example of how I want the logic to work:
Example: (On pick up) Weapon checks for object located in slot 0. If object is in slot 0, check for object in slot 1. If no object is found mount weapon in slot 1.
My idea is that this could be used to "show" weapons mounted on the player character, as if in a holster or strapped to the characters back.
Please help me with scripting this! I've got a short time to do this & i've gone over weapon.cs in various examples time after time again! Need Some Help Soon!!! Thanx!
Example: (On pick up) Weapon checks for object located in slot 0. If object is in slot 0, check for object in slot 1. If no object is found mount weapon in slot 1.
My idea is that this could be used to "show" weapons mounted on the player character, as if in a holster or strapped to the characters back.
Please help me with scripting this! I've got a short time to do this & i've gone over weapon.cs in various examples time after time again! Need Some Help Soon!!! Thanx!
About the author
#2
06/10/2005 (6:39 pm)
Thats about as easy as it gets, something like..function ItemData::onCollision(%data, %obj, %col, %vec, %speed)
{
//echo("\c3ItemData::onCollision( " @ %data.className @ ", " @ %obj.getDataBlock().getName() @ ", " @ %col.getDataBlock().getName() @ ", " @ %vec @ ", " @ %speed @ " )");
// Default behavior for items is to get picked up by the colliding object.
if(!isObject(%obj) || %col.getState() $= "Dead")
return;
switch$ (%data.className)
{
case "Weapon":
%inv = %col.incInventory(%data, 1);
if(%inv)
{
if(%col.getMountedImage(0) == 0)
%col.use(%data.getName());
else // Loop through the slots and find an empty mount to put this in
{
for(%i = 1; %i <= 4; %i++)
{
if(%col.getMountedImage(%i) == 0)
{
%col.mountImage(%data.image, %i);
break;
}
}
}
if(%col.client)
messageClient(%col.client, 'MsgItemPickup', '\c2You picked up a %1', %data.pickupName);
if(%obj.isStatic())
%obj.respawn();
else
%obj.delete();
}
default:
%inv = %this.incInventory(%data, 1);
if(%inv)
{
if(%col.client)
messageClient(%col.client, 'MsgItemPickup', '\c2You picked up %1\'s', %data.pickUpName);
if(%obj.isStatic())
%obj.respawn();
else
%obj.delete();
}
}
}
Torque 3D Owner Matthew Langley
Torque