Weapon & Ammo Drop
by Adam Beaty · 02/17/2003 (12:06 pm) · 23 comments
This is the code to have the last weapon and the ammo left in the clip dropped when dead. So when someone kills you they can runover your dead body and pick up you last gun and any ammo left in the clip. If their clip is empty the gun doesn't drop for pick up.
1) First open fps/server/scripts/player.cs
2) Find the function: function Armor::onDisabled(%this,%obj,%state) around line 830.
3) add this to the top of that function:
1) First open fps/server/scripts/player.cs
2) Find the function: function Armor::onDisabled(%this,%obj,%state) around line 830.
3) add this to the top of that function:
%image = %obj.getMountedImage($WeaponSlot); %amount = %obj.getInventory(%image.ammo); %obj.throw(%image.ammo,%amount); %obj.throw(%image.item);Thats all there is to the death throw. Simple but effective in the gamming world. On an added note, I lowered my throw velocity so it lands closer to the person dieing. You can adjust that however. Its in the onThrow function in the inventory.cs file.
#2
Phil.
02/17/2003 (5:57 pm)
I'd recommend adding a random direction offset to this guys, unless you intend on having the old counterstrike gun-running going on :)Phil.
#3
02/17/2003 (6:04 pm)
can you please explain what you mean, the way I have it is more life like. If a personn is running forward and you shoot him in the back, his gun shouldn't get thrown behind him.
#4
02/17/2003 (9:57 pm)
Good timing, just when I needed this \:)
#5
02/18/2003 (6:22 am)
Good point Phil, always disliked those Llama's ;) and those awpw*ores as well *snicker*
#6
Adam Beaty
Rhino Productions
02/18/2003 (12:49 pm)
Well I tried my best to come up with something that alot of people would use, and it was easy for a newb scriptor like me.Adam Beaty
Rhino Productions
#7
02/19/2003 (11:13 am)
I think this is a great resource. If you want to add a random to the direction of the throw add it in. The point is that it is a good script that you can expand upon if you like.
#8
02/24/2003 (12:08 am)
Hey guys, I noticed I had a problem when standing on top of an object that it'd "climb" my character. So here is the majority of the function I use to create a random drop for my item. You can use it outright, or change it up some for this resource.%obj = new Item() {datablock = %dataBlockID;};
MissionGroup.add(%obj);
// We want to drop the item around the player in a 3 meter
// circle with a random rotation. This should get our new Y and Z
//Random number, the next few lines make our object drop in a radius of 3 around
// the player. Sqrt 9 is 3, duh!
%newYsq = getRandom() * 9.0;
%newXsq = 9.0 - %newYsq;
%incY = mSqrt(%newYsq);
%incX = mSqrt(%newXsq);
//This code is so we can adjust the rotation of the drop. We need
//to hit all 4 quadrants of the circle
%neg1 = getRandom();
%neg2 = getRandom();
%sign1 = 1;
%sign2 = 1;
if(%neg1 < 0.5)
%sign1 = -1;
if(%neg2 < 0.5)
%sign2 = -1;
//Let's get the coords where the player who is dropping, is currently
%itemTrans = %client.getControlObject().getTransform();
%oldX = getWord(%itemTrans, 0);
%oldY = getWord(%itemTrans, 1);
//Let's get new coords to adjust the old ones by
%newX = getWord(%itemTrans, 0) + (%incX * %sign1); // Plane
%newY = getWord(%itemTrans, 1) + (%incY * %sign2); // Plane
%newZ = getWord(%itemTrans, 2) + 3; // Height
//And let's apply those coords
%itemTrans = setWord(%itemTrans, 0, %newX);
%itemTrans = setWord(%itemTrans, 1, %newY);
%itemTrans = setWord(%itemTrans, 2, %newZ);
//Set the box to the coords we want
%obj.setTransform(%itemTrans);
return %obj;
#9
@Jared- where am I supposed to put this code in the same place as Beaty's code?
Thanks,
- Jordan
09/28/2004 (12:38 am)
In TGE 1.3, Adam Beaty's code causes a crash when you kill yourself (not ctrl-k, but shooting into a ground/wall) in the FPS Starter Kit. @Jared- where am I supposed to put this code in the same place as Beaty's code?
Thanks,
- Jordan
#10
12/09/2004 (2:22 pm)
hmm why does that happen I was excited about this
#11
@Jordan and Master:
The crash is caused by the line
%obj.setImageTrigger(0,false);
at the end of the function. Basically it was trying to release the trigger for a weapon that had already been thrown. Move this line to the top of the function, before the throw code, this will solve the crash problem.
12/26/2004 (7:27 pm)
@Adam: great resource thanks a lot!@Jordan and Master:
The crash is caused by the line
%obj.setImageTrigger(0,false);
at the end of the function. Basically it was trying to release the trigger for a weapon that had already been thrown. Move this line to the top of the function, before the throw code, this will solve the crash problem.
#12
01/24/2005 (4:05 pm)
Still crashes in 1.3, even with the above change.
#13
04/05/2005 (3:24 pm)
Yea I get the same crash with the fix as well.
#14
04/05/2005 (5:46 pm)
Yep, still crashes.
#15
That will dump all of your stuff on the ground.
Works perfect for players, but randomly crashes on bots.
Anyways, I'm pretty sure my crashes have something to do with my AI.
Ari Rule
"That bot over there is running around with yer stuff, I suggest you go get it back..."
*I'm using TGE v1.3.
**Special thanks to Rob Davidson.
05/19/2005 (5:02 am)
If anyone is using the scripted inventory system, I have a pretty cool piece of code to use instead of this one.%obj.setImageTrigger(0,false);
%totalInvCount = %obj.totalInvNum;
for(%i = 1; %i <= %totalInvCount; %i++)
{
%invName = %obj.totalInvName[%i];
%invQty = %obj.getInventory(%invName);
if(%invQty>0)
{
%obj.throw(%invName,%invQty);
//echo("Attempted to drop " @ %invQty @ " " @ %invName @ "(s).");
}
}That will dump all of your stuff on the ground.
Works perfect for players, but randomly crashes on bots.
Anyways, I'm pretty sure my crashes have something to do with my AI.
Ari Rule
"That bot over there is running around with yer stuff, I suggest you go get it back..."
*I'm using TGE v1.3.
**Special thanks to Rob Davidson.
#16
05/20/2005 (2:44 pm)
I'm not, however I'd like to get the simple toss weapon and ammo to work in 1.3. =/
#17
When I throw an item, there is about a 30% chance that I crash.
I thought it might be an art problem so I loaded the orc back up.
Still no luck.
Has anybody solved this?
Ari Rule
05/24/2005 (5:31 pm)
No matter which example I use, or however I code it.When I throw an item, there is about a 30% chance that I crash.
I thought it might be an art problem so I loaded the orc back up.
Still no luck.
Has anybody solved this?
Ari Rule
#20
I modified this a little bit so that it would throw the weapon and the flag (in a CTF game).
05/22/2006 (3:06 pm)
Great resource, I modified this a little bit so that it would throw the weapon and the flag (in a CTF game).

Torque Owner John Eder