Question: OOP needed for multiple items?

Hi I was wondering how I could make different items and weapons do different thing, like deal different damage, because the only way I see it possible is just brute forcing everything, like have fifty collision sensors for all the different weapons checking if the player/enemy is hit by each one and dealing appropriate damage based on that. The other way I see it is doing a class for weapons and items and just making objects of them, but I have no idea how I would integrate that into a game.

Thanks :slight_smile:

have properties in each weapon, that all manipulate the same scripts
logic based weapon manager

q= grab weapon

up and down cycle through the weapon list

mouse 1 = shoot
/uploads/default/original/4X/b/c/5/bc5ffc13a09b9cd556073a6891fb623f93ea783e.blendd=1406172933

Ok thanks. Well I lookd at the file and I think I see what you did but I don’t entirely follow, I don’t really know what all the code does and such. I see that you made it possible to have a list as a property and I didn’t even that was possible so thanks! But could you maybe explain in more detail how you got your script to work?

Ok,

That is a little complicated example

Mouse 1 checks to see if manger has a child, if it does that is a gun,
So it sets a property in the gun, that is then handled by logic in the gun,
So the manager nudges the gun into firing mode, or reload mode
Up and down arrow deletes gun, ads ammo back to stock and adds new gun
Q-Picking up a gun adds a value to a list.
And deletes the gun/crate from the map,and grabs its ammo.

You will notice each gun stores what ammo it uses, and then when reloading, the manager looks at this to reload.

My logic is a little hard to follow, because I use logic, and python and properties to try and stay away from always----python

So, recap

Gun manager spawns weapons and parents them to itself, reloads them, and nudges guns into firing mode.

The gun list spawns objects from layer 2,

So the pickup item has a value in it, that is added to gunlist.
Q button handles this.

Ok but my main issue is the list itself. How does the whole list thing work? Like without all the gun logic, because well for me I’m making an rpg. So just how do you go about using the list, like adding to it, checking which one the player selected and such?

index= value on list

so

List[index] = that item

when picking up a item

own[‘Inventory’]+=[new item name]

then you can recall it

object=own[‘Inventory’][index]

to display an inventory

you could do something like take a 2d image of all of the items,

then use a technique similar to uv animations to offset the image for each value

like if object=bacon Uvs=[top left,top right,bottom left,bottom right]


Side note : the gun logic could be any logic

if fire=1 ----python

if fire=1-------and-------Do stuff and set fire 0

(like timers+effects? or?)

Ok thanks so it’s that easy just own[‘Inventory’]+=[new item name]? And the new item name would just be a property of the item he’s picking up, right? So does the inventory have to be a string property basically? Oh also I noticed you had an initializing script for the gun list, and you have:

else:
own[‘GunListString’]=str(own[‘Gun_List’])

is this necessary as well or is this just something specific to your game?

Sorry for all the questions lol

its for debug, :smiley:

see it on the screen of my file? [Gun_1,Gun_2] etc?

And I like answering questions and solving problems :smiley:

ok awsome. so why does the list itself not show up on the debug screen?

I don’t think so, I think only string, int and float and Boolean

List and gameObject are both not viewable using debug in logic.

oh ok so any property that you turn into a list won’t show up ok. And it doesn’t have to be a string right it can be a list of ints and have each int correspon to each item? That might be trippy so i probably wont do that i just want to make sure.

[EDIT] Ok so I looked at your file again and I noticed that you still have properties on your manager for the individual guns. Is there a way around this, because I’m planning on having hundreds of items which would mean hundreds of properties?

Actually, you don’t need too much of work to do this work.
You can use a simple logic brick system.
The object receiving damage, can copy a damage value from the shooter, which can change that value according to the weapon picked. Once the object gets hit by a bullet, you can reduce the shield by the copied value.

If you have different shooters, you may have the bullet have a property, that copies the shooter’s name, then have the receiver copy the damage from the shooter. You can add other variations in the bullet like time (the longer the bullet exists, the less damage it gives).

Example

Ok thanks :slight_smile: