So I’m working on hopefully a small test project and I wanna use cards in a way similar to Hearthstone or Bloxcards(?) or in my case specifically Wizard 101 only issue is I’m not sure how to kind of do it. I have this module script I’m not sure if it’s helpful, but I plan to basically put all the cards in the spells table.
local spells = {
Choke = {
Name = "Choke";
School = "Fire";
Level = "Any";
Accuracy = 80;
Pips = 2;
Effect = "Stuns all enemies for 1 Round"
};
Immolate = {
Name = "Immolate";
School = "Fire";
Level = "Any";
Accuracy = 100;
Pips = 4;
Effect = "600 fire damage to target and 250 damage to self"
};
Scald = {
Name = "Scald";
School = "Fire";
Accuracy = 75;
Pips = 5;
Effect = "465 fire damage to all enemies over 3 rounds"
};
}
local school = {"Fire","Ice","Storm","Balance","Life","Death","Myth","Sun","Star","Moon","Shadow"}
setmetatable(spells,{
__index = function(table,index,value)
print(index.." doesn't exist!")
print("Creating it")
local randomSchool = math.random(1,#school);
local selectedSchool = school[randomSchool]
return {
Name = index;
School = tostring(selectedSchool);
Level = math.random(0,100);
Accuracy = math.random(0,100);
Pips = math.random(1,20);
print(index.." was created")
}
end
})
return spells
Now I have a few questions so first of all idk if the metatable is necessary I was just kind of using it because I just learned how it works, but how can I add what I just created into the spells table?
For my questions I’m trying to achieve 2 things.
- How can I randomly make a deck with a random selection of cards from the spells table? And make sure that no more than 3 of the same things get selected.
- How can I making a draw system? I tried doing this
local deck = {}
local totalAmountInDeck = #deck
local currentAmountInDeck = #deck
print("Cards")
print(currentAmountInDeck.." of "..totalAmountInDeck)
cardsInHand = 0
maxAmountOfCards = 7
while cardsInHand <= maxAmountOfCards do
if cardsInHand == maxAmountOfCards then
break
end
local draw = math.random(1,#deck)
local drawn = deck[draw]
table.remove(deck,draw)
print(tostring(drawn))
cardsInHand = cardsInHand + 1
end
print(currentAmountInDeck.." of "..totalAmountInDeck)
it doesn’t really work lol or it does but can probably make it better.