RE: /card command to draw a random card - Lewwings - 07-25-2019
(07-24-2019, 03:02 AM)Conn Wrote: Another possible solution, this time generating a deck with 1-6 packs of cards in. Obviously a bit of a guessing game and I haven't tested the main code (yet) on a sandbox, but it should work I think..
Spoiler :
Code:
local playerCards = {}
-- Command to create a set of 1-8 decks of playing cards
cityrp.command.add("deck", "b", 1, function(ply, arguments)
local decksize = tonumber(arguments[1])
if (!decksize or decksize < 1 or decksize > 8) then
ply:Notify("Please choose a decksize between 1 and 8.", 1)
return
end, "Commands", "<1-8>", "Creates a pile of 1-8 card decks for casino games")
-- Command to print a random playing card from a generated deck
cityrp.command.add("card", "b", 0, function(ply)
local deck = {}
local index = 0
for k,v in pairs(playerCards) do
if (v[1] == ply) then
deck = v[2]
index = k
break
end
end
if (!deck or table.IsEmpty(deck)) then
ply:Notify("You must generate a deck. Use /deck <1-8>", 1)
return
end
local card, index = table.Random(deck)
table.remove(playerCards,index)
table.insert(playerCards, index, {ply, deck})
ply:ConCommand("cityrp me drew " .. card)
end, "Commands", "<none>", "Picks a random card from the deck")
Changed a bit with Devon, should work
Would it be possible to have something for poker too? Maybe a system where cards could be PM'd instead?
RE: /card command to draw a random card - Conn - 07-25-2019
(07-25-2019, 07:22 PM)Lewwings Wrote:
(07-24-2019, 03:02 AM)Conn Wrote: Another possible solution, this time generating a deck with 1-6 packs of cards in. Obviously a bit of a guessing game and I haven't tested the main code (yet) on a sandbox, but it should work I think..
Spoiler :
Code:
local playerCards = {}
-- Command to create a set of 1-8 decks of playing cards
cityrp.command.add("deck", "b", 1, function(ply, arguments)
local decksize = tonumber(arguments[1])
if (!decksize or decksize < 1 or decksize > 8) then
ply:Notify("Please choose a decksize between 1 and 8.", 1)
return
end, "Commands", "<player>", "PMs a random card from the deck")
Add the validation (commented where in pcard function) and that should work
RE: /card command to draw a random card - Forgee - 07-25-2019
(07-25-2019, 07:22 PM)Lewwings Wrote:
(07-24-2019, 03:02 AM)Conn Wrote: Another possible solution, this time generating a deck with 1-6 packs of cards in. Obviously a bit of a guessing game and I haven't tested the main code (yet) on a sandbox, but it should work I think..
Spoiler :
Code:
local playerCards = {}
-- Command to create a set of 1-8 decks of playing cards
cityrp.command.add("deck", "b", 1, function(ply, arguments)
local decksize = tonumber(arguments[1])
if (!decksize or decksize < 1 or decksize > 8) then
ply:Notify("Please choose a decksize between 1 and 8.", 1)
return