Need help creating a weapon load out

I’m new to panda3d and have been toying around with it for a while. I’ve decided to start a FPS project, I’ve gotten the basics down like moving and firing a projectile but I need help in creating a weapon loadout where I can select different weapons. Thanks in advance

That’s a… rather broad question, I fear.

Are you having trouble creating a UI? Storing multiple weapons in a player-object? Implementing separate weapons? Something else…?

I don’t really have a problem with creating UI’s or storing weapons and their attributes in a class and adding that weapon class into a list or dictionary. Where I have the problem is to find a way to link the UI to the list or dictionary so that the weapon I chose in the load out is the weapon that my character is using

Ah, I see! Thank you for clarifying–it helps! :slight_smile:

Okay, so, if you’re using DirectButtons for your UI then what I might suggest is to use the “extraArgs” property of the DirectButton class, and in that property store the list-index or dictionary-key for the loadout item associated with that button.

You see, when a button’s “command”-function is called, the contents of its “extraArgs” property are sent through as part of the function-call. This can thus be used to transfer information about what a specific button is associated with.

Just note that, if I’m not much mistaken, the value of “extraArgs” is always a list–even if there’s only one object in it!

Here below is a very simple example:

# A simple dictionary for purposes of demonstration:
myWeaponDictionary = {
    "pistol" : myPistolObject,
    "sword" : mySwordObject

# Elsewhere...
    self.myUIButton1 = DirectButton(text = "Loadout 1",
                                    scale = 0.1
                                    command = self.loadoutButtonPressed)
    # (Note: The function "loadoutButtonPressed" is defined below)

# Elsewhere still, associating a button with a weapon:
    weapon1Key = "pistol"
    myUIButton1["text"] = myWeaponDictionary[weapon1Key].name
    myUIButton1["extraArgs"] = [weapon1Key]
    # (Note: as mentioned above, even though there's only one "extra arg",
    #  we're storing it in a list.)

# And then the command-function for the button:
def loadoutButtonPressed(self, weaponKey):
    self.player.loadout = myWeaponDictionary[weaponKey]

Thanks for clarifying it for me at least now I have an I idea of how to do a load out.

1 Like