I am newish to the blender game engine and have very little knowledge on python but I plan to learn more. I am making a game with a friend and we need to have multiple guns. But I do not know how to make weapons that you can pick up or change to or anything. And we need a limit of 2 pistols and 1 primary. How would I go about doing this?
I will try and write you something easily understood using logic and python to dissect.
Thank you! I will not use it without your permission I will just examine it to learn more unless you allow me to use it
I prefer to use logic bricks and try to avoid use of python to make something like this.
I remenber that I made a weapon change and ammo inventory system many time ago. I think I have it in a Backup HD… I will try to find later, or make a simple demo.
Ok here is a example
it’s not as easy as I thought it was going to be, but it works great.
Tab = pickup and drop weapon 1
Space = Fire weapon 1
I used a child check to store the slot of the pistols key (python)
this is faster then iterating through scene.objects[‘PistolSlot’]
I used python to identify the key of the gun
I used python to trigger firing in the gun.
this setup still requires about a half hour more of logic before it will allow the shooting of 2 pistols at once, and swap to “back weapon” when you press a key.
I’ll try and write it tonight
PickUpPistolDropAndFire.blend (638 KB)
I guess you want to use one weapon at time.
Further I guess you want to have max 2 pistols (weapon type) and 1 other weapon available. But you can have any weapon of the mentioned type as you like.
A) have one “slot” for an current weapon. This can be any weapon type as you can use any weapon. You need to find a way to change the current weapon. As there can be only one current, you need to remove an previous weapon, before switching to the new one. This is usually done, by overwriting the “current weapon” settings (e.g. a property).
Add logic that allows to “use” the weapon referred from current weapon slot
B) have two slots for “available pistols” and one slot for “available primary”. Each slot can work the same (similar to the current weapon slot). Each slot should be able to exchange to weapon. Each slot can be empty. Optional, you can ensure that each pistol slot has a unique weapon. In difference to the current weapon slot, weapons will not bu used, but activated (= referred by the current weapon slot). If you refer the slot or the weapon itself depends on your design.
I know this is a very general description. But this should give you an idea.
BTW. you do not necessarily need Python, but it would help ;).
updated file with 3 “guns”
PickUpPistolDropAndFire (1).blend (671 KB)
I am so sorry but I could not find that file… so I made another.
I only use LOGIC BRICKS. The attached BLEND contains no scripts: A little tank that can get ammo and weapons on the floor. The tank shooting mechanism does not work (I can not spend more time in this today)
I hope this could help someone, you or another one who need look for ideas on this matter.
weapon_ammo.blend (934 KB)
SUPER HELPFUL! Thank you sooo much!