#need help randomizing moves in a game

12 messages · Page 1 of 1 (latest)

wheat summit
#

Hey, I'm making a rpg where the weapons are the things that define the attacks, like, when you get a weapon, the game decides 3 different moves from a pool of a lot of attacks to add to the weapon. How should I do this?
Also there are diferent weapon types as a the type1 and a magic type as type 2. I want to make so there are specific attacks corresponding to each type
This is the code of the resource I made just to define the weapon types


enum ItemType{
    sword,
    lance,
    dagger,
    staff,
    hammer
}

enum MagicType{
    light,
    dark,
    water,
    fire,
    ground,
    grass,
    air,
    technological,
    none
}


@export var Item_Type: ItemType = ItemType.sword
@export var Magic_Type: MagicType = MagicType.none```
#

Let me give an example. I grab a weapon in the game, then the game decides two types for the weapon, sword and dark. Then it decides one move from the sword move pool, one from the dark move pool and another from either one of them randomly

daring quiver
#
    var its = ItemType.keys()
    its.shuffle()
    var it = its[0]

    var mts = MagicType.keys()
    mts.shuffle()
    var mt = mts[0]

    ## Make random choice between both types
    var rs = [its, mts]
    rs.shuffle()
    rs[0].shuffle()
    var r = rs[0][0]

    var result = [mt, it, r]
    result.shuffle()
    print(result)

I don't get your resource needs so put it into my _ready to test.

wheat summit
daring quiver
#

You have to paste my code snippet into a scene func _ready()

And make sure the indentation is fixes. In de code editor menu Edit

#

Then run the scene

wheat summit
#

Ohhh

#

Alright

#

Thanks

daring quiver
#

The result is a little weird as it contains keys from 2 enums. Key takeaway is:

  • Enums have keys()
  • You can shuffle() Arrays

Guess your code will be quite different 🙂

knotty stratus
#

This is a really cool design pattern/ gsme mechanic