Weapons Limit
by Joseph Jonathan · in Torque Game Engine · 01/23/2008 (10:10 am) · 7 replies
Yea finaly after a few years I convinced my dad to let me buy the SDK. He made me ask lots of friends of his who know a lot about programming and gaming to vouch for Torque.
Now my problem::::
I am looking for a way to have a CoD style weapons system. Where the guy can only cary 2 weapons in addition to his grenades and pistol.
Does anyone know which direction I should go in or is there a resorce out there that explaines it.
Now my problem::::
I am looking for a way to have a CoD style weapons system. Where the guy can only cary 2 weapons in addition to his grenades and pistol.
Does anyone know which direction I should go in or is there a resorce out there that explaines it.
#2
If he already has two in his inventory he has to swap one to pick up another.
01/23/2008 (4:22 pm)
No, I mean that the character can only carry two weapons.If he already has two in his inventory he has to swap one to pick up another.
#3
01/23/2008 (4:42 pm)
Actually with the weapon cycling code you can have infinite weapons in your inventory. as long as you add it to your player.cs and game.cs you can have as many weapons as you like. add the weapon cycling code, and you can swap out those items, though id probably keep it down to under 10 weapon choices for simplicty sake(ie quickkeys).
#4
01/24/2008 (7:54 am)
No, he wants to cap it at two weapons (if I read correctly...). But from what I've read of it, the weapon cycling resource should allow you to do this. I haven't looked into it much.
#6
01/24/2008 (11:45 am)
The weapons cycling resource does not have a way to have a maximum amount of weapons in inventory. It just gives a way to have a maximum amount of weapons in the game.
#7
Basically, just keep track of how many weapons the player has with a simple counter variable. Everytime an item is collided with, check it. Is this a weapon (every Item datablock contains a className variable in stock, it'll $= "Weapon" if it's a weapon)? If so, is %player.weaponCount > 1? (%player.weaponCount is an arbitrary script variable held in the player object.. probably best to initialize this in player's onAdd). If the weaponCount is less than 2, %player.weaponCount++ and allow the pickup process to happen. Otherwise, skip this item.
When you drop an item, also check if it's a weapon and %player.weaponCount-- if so.
I really don't have time to make this into a how-to, but I will say that you should look for "::onCollision" in player.cs in order to spot where the item pickup chain begins. Remember that anytime you have access to the player's ID (often a variable like %player in most functions, or %obj when the player is the target of some action) you can create, alter, and access script variables associated with that player simply by using %player.whateverVariableIWant (or %obj.varName, %someVar.someotherVar, etc).
I honestly recommend you spend some time just mapping out how the various scripts get things done before you insist on creating specific features for your particular game, but at the same time just diving in is exactly how I learned, so... =)
02/21/2008 (5:19 pm)
This really shouldn't be so complicated as to require a resource. I'm not using the stock inventory setup, but I still have that collision with item function in the player.cs script. If you collide with an "Item" object, it begins the pickup process and deletes the object, so just intervene here.Basically, just keep track of how many weapons the player has with a simple counter variable. Everytime an item is collided with, check it. Is this a weapon (every Item datablock contains a className variable in stock, it'll $= "Weapon" if it's a weapon)? If so, is %player.weaponCount > 1? (%player.weaponCount is an arbitrary script variable held in the player object.. probably best to initialize this in player's onAdd). If the weaponCount is less than 2, %player.weaponCount++ and allow the pickup process to happen. Otherwise, skip this item.
When you drop an item, also check if it's a weapon and %player.weaponCount-- if so.
I really don't have time to make this into a how-to, but I will say that you should look for "::onCollision" in player.cs in order to spot where the item pickup chain begins. Remember that anytime you have access to the player's ID (often a variable like %player in most functions, or %obj when the player is the target of some action) you can create, alter, and access script variables associated with that player simply by using %player.whateverVariableIWant (or %obj.varName, %someVar.someotherVar, etc).
I honestly recommend you spend some time just mapping out how the various scripts get things done before you insist on creating specific features for your particular game, but at the same time just diving in is exactly how I learned, so... =)
Torque 3D Owner Edward