Posts: 1,848
Threads: 186
Likes Received: 362 in 313 posts
Likes Given: 1,519
Joined: Nov 2018
Reputation:
30
Country:
07-24-2019, 09:15 PM
(This post was last modified: 09-01-2022, 01:08 AM by Fearless Community .
Edit Reason: Fixed Encoding
)
(07-23-2019, 04:11 PM) Conn Wrote: Big +Support
Really easy to do too, something like this?
Spoiler :
Code:
-- Command to print a random playing card
cityrp.command.add("card", "b", 0, function(ply)
local suits = {"Spades", "Clubs", "Hearts", "Diamonds"}
local value = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}
local card = table.Random(value) .. "of " .. table.Random(suits)
-- output to players
end, "Commands", "<none>", "Picks a random card")
(basing it off Snowred's comment on
https://www.fearlessrp.net/showthread.ph...light=code )
U have done the devs work for them
Posts: 3,290
Threads: 158
Likes Received: 2,301 in 1,264 posts
Likes Given: 5,833
Joined: Jul 2017
Reputation:
71
Country:
07-25-2019, 07:22 PM
(This post was last modified: 09-01-2022, 01:08 AM by Fearless Community .
Edit Reason: Fixed Encoding
)
(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
local suits = {"Spades", "Clubs", "Hearts", "Diamonds"}
local values = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}
local deck = {}
for i=1, decksize do
for k, value in pairs(values) do
for k, suit in pairs(suits) do
table.insert(deck, value .. " of " .. suit)
end
end
end
table.insert(playerCards, {ply, deck})
ply:Notify("Deck generated!")
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?
Posts: 2,097
Threads: 176
Likes Received: 2,007 in 736 posts
Likes Given: 954
Joined: Aug 2014
Reputation:
59
07-25-2019, 07:39 PM
(This post was last modified: 09-01-2022, 01:08 AM by Fearless Community .
Edit Reason: Fixed Encoding
)
(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
local suits = {"Spades", "Clubs", "Hearts", "Diamonds"}
local values = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}
local deck = {}
for i=1, decksize do
for k, value in pairs(values) do
for k, suit in pairs(suits) do
table.insert(deck, value .. " of " .. suit)
end
end
end
table.insert(playerCards, {ply, deck})
ply:Notify("Deck generated!")
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?
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
local suits = {"Spades", "Clubs", "Hearts", "Diamonds"}
local values = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}
local deck = {}
for i=1, decksize do
for k, value in pairs(values) do
for k, suit in pairs(suits) do
table.insert(deck, value .. " of " .. suit)
end
end
end
table.insert(playerCards, {ply, deck})
ply:Notify("Deck generated!")
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")
-- Command to PM a random playing card from a generated deck
cityrp.command.add("pcard", "b", 1, function(ply, arguments)
local target = arguments[1] -- validation here to ensure target is a player on server
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 pm " .. target .. " Card: " .. card)
end, "Commands", "<player>", "PMs a random card from the deck")
Add the validation (commented where in pcard function) and that should work
Regards,
C o n n n n n n n n
Consider giving me a rep point
here .
07-25-2019, 07:54 PM
(This post was last modified: 09-01-2022, 01:08 AM by Fearless Community .
Edit Reason: Fixed Encoding
)
(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
local suits = {"Spades", "Clubs", "Hearts", "Diamonds"}
local values = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"}
local deck = {}
for i=1, decksize do
for k, value in pairs(values) do
for k, suit in pairs(suits) do
table.insert(deck, value .. " of " .. suit)
end
end
end
table.insert(playerCards, {ply, deck})
ply:Notify("Deck generated!")
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?Yes please
Posts: 1,304
Threads: 41
Likes Received: 1,040 in 483 posts
Likes Given: 831
Joined: Apr 2016
Reputation:
38
Country:
07-25-2019, 08:27 PM
(This post was last modified: 09-01-2022, 01:08 AM by Fearless Community .
Edit Reason: Checked Encoding
)
this aint gambling rp
-support
Posts: 3,848
Threads: 352
Likes Received: 2,373 in 1,021 posts
Likes Given: 2,683
Joined: Nov 2015
Reputation:
94
Country:
07-25-2019, 08:48 PM
(This post was last modified: 09-01-2022, 01:08 AM by Fearless Community .
Edit Reason: Checked Encoding
)
Approved.
Posts: 3,848
Threads: 352
Likes Received: 2,373 in 1,021 posts
Likes Given: 2,683
Joined: Nov 2015
Reputation:
94
Country:
07-26-2019, 01:46 AM
(This post was last modified: 09-01-2022, 01:08 AM by Fearless Community .
Edit Reason: Checked Encoding
)
done