Automatic Pickup
by Eddie Saunders · in Torque Game Engine · 02/10/2005 (6:55 pm) · 5 replies
Evening,
I've been working through just making a few bits and bobs with Torque, and one this I'd like to achieve is not to pickup items such as weapons automatically, although somethings, say grenades would be picked up automatically.
In a nutshell, I want the player to collide with a weapon, and the game display "Press X to pickup Weapon".
I remarked out Shapedbase::pickup in Inventory, and got the message displayed by adding in weaponname::onCollision in the actual weapon script, but now I'm stuck and can't figure out how to get a keybind (I can bind keys fine) to actually pickup the weapon. I've tried a function weaponsname::onpickup function but that made Torque a little upset and spit a few errors at me... :)
Any pointers would be appreciated, I'm not after answers, just general pointers to get me facing the correct direction again. :)
Thanks,
Eddie.
I've been working through just making a few bits and bobs with Torque, and one this I'd like to achieve is not to pickup items such as weapons automatically, although somethings, say grenades would be picked up automatically.
In a nutshell, I want the player to collide with a weapon, and the game display "Press X to pickup Weapon".
I remarked out Shapedbase::pickup in Inventory, and got the message displayed by adding in weaponname::onCollision in the actual weapon script, but now I'm stuck and can't figure out how to get a keybind (I can bind keys fine) to actually pickup the weapon. I've tried a function weaponsname::onpickup function but that made Torque a little upset and spit a few errors at me... :)
Any pointers would be appreciated, I'm not after answers, just general pointers to get me facing the correct direction again. :)
Thanks,
Eddie.
#2
05/01/2006 (6:30 pm)
When you go over the item and pickup is called, store a reference to the item on a variable on the player. Then make a serverCmd that will look for this item, and if it's still close enough to the player, run the pickup code. Finally make a keybind that uses CommandToServer to call the serverCmd.
#3
I wrote a simple client code block:
And its corresponding server code block:
Works, makes you receive a Plasma Repeater with full ammo, and sets it so you use it when you press X as well, thus picking up and using a weapon. Problem is I don't know what variable to put in for plasmaRepeater that will be named if a collision is happening between the player and a weapon.
05/06/2006 (6:12 pm)
Having a little trouble coming up with what exactly to put in the Armor::onCollision area and what variable to send to the client. I wrote a simple client code block:
function pickupWeapon(%val)
{
commandToServer( 'PickupWeapon', %val );
}
moveMap.bind(keyboard, "x", pickupWeapon);And its corresponding server code block:
function serverCmdPickupWeapon(%client)
{
%theWeapon = [b]plasmaRepeater[/b];
%client.player.incInventory(%theWeapon, 1);
%client.player.setInventory(%theWeapon.image.ammo,%theWeapon.image.ammo.maxInventory);
%client.getControlObject().use(%theWeapon);
}Works, makes you receive a Plasma Repeater with full ammo, and sets it so you use it when you press X as well, thus picking up and using a weapon. Problem is I don't know what variable to put in for plasmaRepeater that will be named if a collision is happening between the player and a weapon.
#4
So you can probably just store the reference to the item in ShapeBase::pickup, and not call onPickup right away, then have your serverCmd call onPickup for the item instead.
05/06/2006 (6:36 pm)
Items aren't collided with, they have their own method. I believe youl'd want to look at the function ShapeBase::pickup in the inventory.cs. That function should give you the data to set that variable, but you'll have to remove/comment out a lot of the default item code that makes it try to delete an item and add it to your inventory (or add a new case for items that are weapons). Remeber the default pickup function calls the function Item::onPickup in item.cs, and this is where the code for adding to your inventory, deleting the item, blah blah is stored. So you can probably just store the reference to the item in ShapeBase::pickup, and not call onPickup right away, then have your serverCmd call onPickup for the item instead.
#5
05/06/2006 (8:08 pm)
Heh found that the Dual Wielding resource has a tiny bit of code that does exactly what I want, picking up a weapon from the Armor::onCollision method. Needed a little fix to work networked, but it works with some tweaking, to perfection.
Torque Owner Chris Byars
Ion Productions