Guest User

Untitled

a guest
Feb 12th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '#####################
  2. '# UNI script v 1.0  #
  3. '# Author: Morio     #
  4. '#####################
  5.  
  6. 'Commands:
  7. '!uno   - starts a new game (if a game is not being played at the moment)
  8. '!join  - join a game
  9. '!play  - play a card
  10. '!draw  - draw a card from the deck
  11. '!pass  - pass over your turn to the next player (can only be done if you have already drawn a card from the deck
  12. '!stop  - stops the game (for the gamestarter and operators only)
  13. '!help  - shows a list of commands
  14.  
  15.  
  16. Dim Players,TotalCards,CardsInDeck,UnoChannel,GameStarter,NewString,CardOnTop,CardsOnTable,Playerlist,Turn,HasDrawn,HasStarted
  17. Set Players = CreateObject("Scripting.Dictionary")
  18.  
  19. 'all cards found in a deck
  20. TotalCards = "p:0,p:1,p:1,p:2,p:2,p:3,p:3,p:4,p:4,p:5,p:5,p:6,p:6,p:7,p:7,p:8,p:8,p:9,p:9,p:dr2,p:dr2,p:r,p:r,p:s,p:s,b:0,b:1,b:1,b:2,b:2,b:3,b:3,b:4,b:4,b:5,b:5,b:6,b:6,b:7,b:7,b:8,b:8,b:9,b:9,b:dr2,b:dr2,b:r,b:r,b:s,b:s,r:0,r:1,r:1,r:2,r:2,r:3,r:3,r:4,r:4,r:5,r:5,r:6,r:6,r:7,r:7,r:8,r:8,r:9,r:9,r:dr2,r:dr2,r:r,r:r,r:s,r:s,g:0,g:1,g:1,g:2,g:2,g:3,g:3,g:4,g:4,g:5,g:5,g:6,g:6,g:7,g:7,g:8,g:8,g:9,g:9,g:dr2,g:dr2,g:r,g:r,g:s,g:s,y:0,y:1,y:1,y:2,y:2,y:3,y:3,y:4,y:4,y:5,y:5,y:6,y:6,y:7,y:7,y:8,y:8,y:9,y:9,y:dr2,y:dr2,y:r,y:r,y:s,y:s,wild,wild,wild,wild,wd4,wd4,wd4,wd4"
  21. 'put the cards to the deck
  22. CardsInDeck = TotalCards
  23.  
  24. UnoChannel = ""
  25. PlayerList = ""
  26. HasStarted = False
  27. Turn = 0
  28. HasDrawn = False
  29.  
  30. Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
  31.     Message = LCase(Message)
  32.     If not Channel = "#lru" then Exit Sub 'can be used to make the script work on a specific channel only (recommended)
  33.    
  34.     If UnoChannel = "" then
  35.         CardOnTop = ""
  36.         If Message = "!uno" then
  37.             UnoChannel = Channel
  38.             GameStarter = Nickname
  39.             HasStarted = False
  40.             SendCommand "/msg " & Channel & " " & Nickname & " started a game of uno. Type !join to join. The game will start in 30s",ServerNumber
  41.             'start the game after 30s
  42.             SendCommand "/timer unotimer 1 30 /! PlayUNO " & "newgame|"  & UnoChannel & "|" & ServerNumber & "|newgame"
  43.  
  44.             'shuffle the deck
  45.             ArrayShuffle Split(TotalCards,","), True
  46.             CardsInDeck = NewString
  47.  
  48.         End If
  49.     Else
  50.         If Not Channel = UnoChannel then Exit Sub
  51.         If Message = "!join" then AddUnoPlayer Nickname,Channel,ServerNumber 'joining the game
  52.        
  53.         If Left(Message,6) = "!play " and Len(Message) > 6 then 'playing a card
  54.             If Not Nickname = GetCurrentPlayer(Turn) then Exit Sub
  55.             If Players.exists(Nickname) then
  56.                 Card = Mid(Message,7)
  57.                 Card = Replace(Card, " ", "")
  58.                 If Left(Card,1) = "w" then
  59.                 Card = Left(Card, Len(Card)-1) & " " & Right(Card, 1)
  60.                 End If
  61.                 If Card = "newgame" then Exit Sub
  62.                 If Not Left(Card,1) = "w" then
  63.                 Card = Left(Card,1) & ":" & Mid(Card,2)
  64.                 End If
  65.                 PlayUNO Nickname,Channel,ServerNumber,Card
  66.             Else
  67.                 SendCommand "/msg " & Channel & " " & Nickname & ": you haven't joined the game yet, type !join to join",ServerNumber
  68.             End If
  69.        
  70.         ElseIf Message = "!draw" and HasDrawn = False then 'drawing a card from the deck
  71.             If Not Nickname = GetCurrentPlayer(Turn) then Exit Sub
  72.             NewCard = GetNewCards(1)
  73.             Players.item(Nickname) = Players.item(Nickname) & "," & NewCard
  74.             HasDrawn = True
  75.             If Not NewCard = "" then
  76.                 SendCommand "/notice " & Nickname & " --- You drew: " & AddColors(NewCard),ServerNumber
  77.             Else
  78.                 SendCommand "/msg " & Channel & " Not enough cards in the deck, use !pass to pass your turn",ServerNumber
  79.             End If
  80.         ElseIf Message = "!pass" then 'passing your turn
  81.             If Not Nickname = GetCurrentPlayer(Turn) then Exit Sub
  82.             If HasDrawn = True then
  83.                 If Nickname = Kitsune then
  84.                     SendCommand "/msg " & Channel & " " & Nickname & " Passes hizzle turzzle. Next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  85.                     SendCommand "/notice " & GetCurrentPlayer(Turn+1) & " --- Your cards: " & AddColors(Players.item(GetCurrentPlayer(Turn+1))),ServerNumber
  86.                 Else    SendCommand "/msg " & Channel & " " & Nickname & " Passes his turn. Next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  87.                     SendCommand "/notice " & GetCurrentPlayer(Turn+1) & " --- Your cards: " & AddColors(Players.item(GetCurrentPlayer(Turn+1))),ServerNumber
  88.                 End If 
  89.                     Turn = Turn + 1
  90.                 HasDrawn = False
  91.             Else
  92.                 SendCommand "/msg " & Channel & " " & Nickname & ": You need to !draw before you can !pass",ServerNumber
  93.             End If
  94.  
  95.         ElseIf Message = "!cards" then 'wiev your cards
  96.             Plays = False
  97.             AllPlayers = Players.keys
  98.                 For i = 0 to UBound(AllPlayers)
  99.                     If Nickname = AllPlayers(i) then
  100.                         Plays = True
  101.                         Exit For
  102.                     End If
  103.                 Next
  104.                 If Plays = True then
  105.                     SendCommand "/notice " & Nickname & " --- Your cards are: " & AddColors(Players.item(Nickname)),ServerNumber
  106.                 Else
  107.                     SendCommand "/notice " & Nickname & " --- you are not in the game, type !join to join",ServerNumber
  108.                 End If
  109.  
  110.         ElseIf Message = "!count" then 'show how many cards each player has
  111.             AllPlayers = Players.keys
  112.             PlayerCount = ""
  113.             For i = 0 to UBound(AllPlayers)
  114.                 NumberOfCards = UBound(Split(Players.item(AllPlayers(i)),",")) + 1
  115.                 If PlayerCount = "" then
  116.                     PlayerCount = AllPlayers(i) & ": " & NumberOfCards
  117.                 Else
  118.                     PlayerCount = PlayerCount & ", " & AllPlayers(i) & ": " & NumberOfCards
  119.                 End If
  120.             Next
  121.             SendCommand "/msg " & Channel & " [" & PlayerCount & "]",ServerNumber
  122.  
  123.         ElseIf Message = "!turn" then 'show whose turn it is
  124.             SendCommand "/msg " & Channel & " Current turn: " & GetCurrentPlayer(Turn),ServerNumber
  125.            
  126.         ElseIf Message = "!quit" then 'quit the game
  127.             AllPlayers = Players.keys
  128.             For i = 0 to UBound(AllPlayers)
  129.                 If AllPlayers(i) = Nickname then RemoveUNOPlayer Nickname,UnoChannel,ServerNumber
  130.             Next
  131.         ElseIf Message = "!card"  and HasStarted = True then 'show the top card on the table
  132.             If InStr(CardsOnTable,",") > 0 then
  133.                 TopCard = Left(CardsOnTable,InStr(CardsOnTable,",")-1)
  134.             Else
  135.                 TopCard = CardsOnTable
  136.             End If
  137.  
  138.             If Mid(TopCard,3,1) = "w" then
  139.             CardColor = Left(TopCard,1)
  140.             CardType = Mid(TopCard,3)
  141.                 if CardColor = "b" then
  142.                     NewColor2 = "1,12 BLUE "
  143.                 Elseif CardColor = "g" then
  144.                     NewColor2 = "1,9 GREEN "
  145.                 Elseif CardColor = "y" then
  146.                     NewColor2 = "1,8 YELLOW "
  147.                 Elseif CardColor = "r" then
  148.                     NewColor2 = "1,4 RED "
  149.                 Elseif CardColor = "p" then
  150.                     NewColor2 = "1,13 PINK "
  151.                 End If
  152.                 SendCommand "/msg " & Channel & " The Card on top is: " & GetLongCardName(CardType) & " and the color is: " & NewColor2,ServerNumber
  153.             Else
  154.                 SendCommand "/msg " & Channel & " The Card on top is: " & GetLongCardName(TopCard)
  155.             End If
  156.            
  157.         ElseIf Message = "!stop" and (Nickname = GameStarter or IsOp(Nickname,Channel,ServerNumber))then 'stop the game (gamestarter and operators only)
  158.             SendCommand "/msg " & Channel & " Game stopped by: " & Nickname,ServerNumber
  159.             GameOver Nickname,Channel,False,ServerNumber
  160.             If HasStarted = False then SendCommand "/timer unotimer off",ServerNumber
  161.         ElseIf Message = "!help" then
  162.             SendCommand "/notice " & Nickname & " --- Commands available: !uno, !join, !play, !draw, !pass, !stop",ServerNumber
  163.  
  164.         End If
  165.     End If
  166.    
  167. End Sub
  168.  
  169. 'when changing nickname, your cards are transferred to the new nick, and your turn in the game is preserved
  170. Sub ONNICK(NewNick,OldNick,ServerNumber)
  171.     AllPlayers = Players.keys
  172.     PlayerList = ""
  173.     For i = 0 to UBound(AllPlayers)
  174.         If AllPlayers(i) = OldNick then
  175.             Players.add NewNick, Players.item(OldNick)
  176.             Players.remove(OldNick)
  177.             If OldNick = GameStarter then GameStarter = NewNick
  178.             If PlayerList = "" then
  179.                 PlayerList = NewNick
  180.             Else
  181.                 PlayerList = PlayerList & "," & NewNick
  182.             End If
  183.            
  184.         Else
  185.             If PlayerList = "" then
  186.                 PlayerList = AllPlayers(i)
  187.             Else
  188.                 PlayerList = PlayerList & "," & AllPlayers(i)
  189.             End If
  190.            
  191.         End If
  192.     Next
  193. End Sub
  194.  
  195. 'if you part the channel you quit the game
  196. Sub ONPART(Nickname,Host,Channel,Reason,ServerNumber)
  197.     AllPlayers = Players.keys
  198.     For i = 0 to UBound(AllPlayers)
  199.         If AllPlayers(i) = Nickname then
  200.             RemoveUNOPlayer Nickname,UnoChannel,ServerNumber
  201.         End If
  202.     Next
  203. End Sub
  204.  
  205. 'if you quit from the server, you quit the game
  206. Sub ONQUIT(Nickname,Host,Reason,ServerNumber)
  207.     AllPlayers = Players.keys
  208.     For i = 0 to UBound(AllPlayers)
  209.         If AllPlayers(i) = Nickname then
  210.             RemoveUNOPlayer Nickname,UnoChannel,ServerNumber
  211.         End If
  212.     Next
  213. End Sub
  214.  
  215. 'if you get kicked, you quit the game
  216. Sub ONKICK(Nickname,Host,Channel,WhoKicked,Reason,ServerNumber)
  217.     AllPlayers = Players.keys
  218.     For i = 0 to UBound(AllPlayers)
  219.         If AllPlayers(i) = Nickname then
  220.             RemoveUNOPlayer Nickname,UnoChannel,ServerNumber
  221.         End If
  222.     Next
  223. End Sub
  224.  
  225. 'this sub adds a new player to the game
  226. Sub AddUNOPlayer(Nickname,Channel,ServerNumber)
  227.     If Not Players.exists(Nickname) then 'if he hasn't joined yet
  228.         NewPlayerCards = GetNewCards(7) 'draw 7 cards from the top of the deck
  229.         If Not NewPlayerCards = "" then
  230.             Players.add Nickname, NewPlayerCards
  231.             SendCommand "/msg " & UnoChannel & " " & Nickname & " joined the game",ServerNumber
  232.             SendCommand "/notice " & Nickname & " --- Your cards are: " & AddColors(NewPlayerCards)
  233.             If PlayerList = "" then
  234.                 PlayerList = Nickname
  235.             Else
  236.                 PlayerList = PlayerList & "," & Nickname 'add the player to the playerlist
  237.             End If
  238.         Else 'if there aren't enough cards for the player to join, he can't join
  239.             SendCommand "/msg " & Channel & " " & Nickname & ": There are not enough cards left in the deck for you to join",ServerNumber
  240.             Player.remove Nickname
  241.         End If
  242.     Else
  243.    
  244.     End If
  245.  
  246. End Sub
  247.  
  248. 'this sub removes a player from the game
  249. Sub RemoveUNOPlayer(Nickname,Channel,ServerNumber)
  250.     CardsInDeck = CardsInDeck & "," & Players.item(Nickname) 'put the players cards to the bottom of the deck
  251.     Players.remove(Nickname)
  252.     AllPlayers = Split(PlayerList,",") 'remove the player from the playerlist
  253.     NewPlayerList = ""
  254.     NicknameInTurn = False
  255.     For i = 0 to UBound(AllPlayers)
  256.         If Not AllPlayers(i) = Nickname then
  257.             If NewPlayerList = "" then
  258.                 NewPlayerList = AllPlayers(i)
  259.             Else
  260.                 NewPlayerList = NewPlayerList & "," & AllPlayers(i)
  261.             End If
  262.         Else
  263.             If GetCurrentPlayer(Turn) = AllPlayers(i) then 'if the player was in turn when leaving the game, pass the turn to the next player
  264.                 NicknameInTurn = True
  265.             End If
  266.         End If
  267.     Next
  268.     SendCommand "/msg " & Channel & " Removed " & Nickname & " from the game",ServerNumber
  269.     PlayerList = NewPlayerList
  270.     If HasStarted = True then
  271.         If UBound(Split(PlayerList,",")) = 0 then 'if there is only one player left in the game at any time, the game ends
  272.  
  273.         SendCommand "/msg " & Channel & " Not enough player to continue game. Game terminated",ServerNumber
  274.         Gameover Nickname,Channel,False,ServerNumber
  275.         End If
  276.        
  277.         If NicknameInTurn = True then
  278.             SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn)
  279.             SendCommand "/notice " & GetCurrentPlayer(Turn) & " --- You cards are: " & AddColors(Players.item(GetCurrentPlayer(Turn))),ServerNumber
  280.         End If
  281.     End If
  282. End Sub
  283.  
  284.  
  285. 'this function handles drawing cards from the deck
  286. Function GetNewCards(NumberOfCards)
  287.     if Not UBound(Split(CardsInDeck,",")) + UBound(Split(CardsOnTable,",")) +1 > NumberOfCards then 'if there aren't enough cards, we do nothing
  288.         If NumberOfCards = 7 or NumberOfCards = 1 then
  289.             GetNewCards = ""
  290.             Exit Function
  291.         Else
  292.             NumberOfCards = UBound(Split(CardsInDeck,",")) + UBound(Split(CardsOnTable,","))
  293.         End If
  294.     End If
  295.    
  296.  
  297.     NewCards = ""
  298.     For i = 0 to NumberOfCards-1
  299.         If InStr(CardsInDeck,",") > 0 then
  300.             Card = Left(CardsInDeck,InStr(CardsInDeck,",")-1)
  301.             CardsInDeck = Mid(CardsInDeck,InStr(CardsInDeck,",")+1)
  302.         Else 'if we take the last card from the deck, we take the already played cards and shuffle them and make them the new deck
  303.             Card = CardsInDeck
  304.            
  305.             If InStr(Mid(CardsOnTable,InStr(CardsOnTable,",")+1),",") > 0 then
  306.                 ArrayShuffle Split(Mid(CardsOnTable,InStr(CardsOnTable,",")+1),","), True
  307.                 CardsInDeck = NewString
  308.             Else
  309.                 CardsInDeck = Mid(CardsOnTable,InStr(CardsOnTable,",")+1)
  310.             End If
  311.             CardsOnTable = Left(CardsOnTable,InStr(CardsOnTable,",")-1)
  312.         End If
  313.        
  314.         If NewCards = "" then
  315.             NewCards = Card
  316.         Else
  317.             NewCards = NewCards & "," & Card
  318.         End If
  319.        
  320.     Next
  321.     GetNewCards = NewCards
  322.  
  323. End Function
  324.  
  325.  
  326.  
  327. 'this function adds color to the cards in your hand
  328. Function AddColors(CardSequence)
  329. ColoredCards = ""
  330.     CardArr = Split(CardSequence,",")
  331.     For i = 0 to UBound(CardArr)   
  332.         if Left(CardArr(i),1) = "b" then
  333.             CardArr(i) = "1,12" & " " & Mid(CardArr(i),3) & " "
  334.         Elseif Left(CardArr(i),1) = "g" then
  335.             CardArr(i) = "1,9" & " " & Mid(CardArr(i),3) & " "      
  336.         Elseif Left(CardArr(i),1) = "y" then
  337.             CardArr(i) = "1,8" & " " & Mid(CardArr(i),3) & " "      
  338.         Elseif Left(CardArr(i),1) = "r" then
  339.             CardArr(i) = "1,4" & " " & Mid(CardArr(i),3) & " "      
  340.         Elseif Left(CardArr(i),1) = "p" then
  341.             CardArr(i) = "1,13" & " " & Mid(CardArr(i),3) & " "     
  342.         ElseIf CardArr(i) = "wild" then
  343.             CardArr(i) = "1,12 w1,9i1,8l1,4d "
  344.         ElseIf CardArr(i) = "wd4" then
  345.             CardArr(i) = "1,12 1,9w1,8d41,4 "
  346.         End If
  347.        
  348.         If ColoredCards = "" then
  349.             ColoredCards = CardArr(i)
  350.         Else
  351.             ColoredCards = ColoredCards & " " & CardArr(i)     
  352.         End If
  353.     Next
  354.     AddColors = ColoredCards
  355. End Function
  356.  
  357. 'this sub shuffles an array
  358. Sub ArrayShuffle(arr,MakeString)
  359.     Randomize
  360.     Dim index
  361.     Dim newIndex
  362.     Dim firstIndex
  363.     Dim itemCount
  364.     Dim tmpValue
  365.     firstIndex = LBound(arr)
  366.     itemCount = UBound(arr) - LBound(arr) + 1
  367.     For index = UBound(arr) To LBound(arr) + 1 Step -1
  368.         ' evaluate a random index from LBound to INDEX
  369.         newIndex = firstIndex + Int(Rnd * itemCount)
  370.         ' swap the two items
  371.         tmpValue = arr(index)
  372.         arr(index) = arr(newIndex)
  373.         arr(newIndex) = tmpValue
  374.         ' prepare for next iteration
  375.         itemCount = itemCount - 1
  376.     Next
  377.     If MakeString = True then
  378.         NewString = ""
  379.         For i = 0 to UBound(arr)
  380.             If NewString = "" then
  381.                 NewString = arr(i)
  382.             Else
  383.                 NewString = NewString & "," & arr(i)
  384.             End If
  385.         Next
  386.     End If
  387. End Sub
  388.  
  389. 'this function converts the card code into the real name of the card
  390. Function GetLongCardName(Card)
  391.     if Left(Card,1) = "b" then
  392.         Color = "1,12 BLUE "
  393.     Elseif Left(Card,1) = "g" then
  394.         Color = "1,9 GREEN "
  395.     Elseif Left(Card,1) = "y" then
  396.         Color = "1,8 YELLOW "
  397.     Elseif Left(Card,1) = "r" then
  398.         Color = "1,4 RED "
  399.     Elseif Left(Card,1) = "p" then
  400.         Color = "1,13 PINK "
  401.     End If
  402.    
  403.     If IsNumeric(Mid(Card,3)) then
  404.         GetLongCardName = Color & "NUMBER " & Mid(Card,3) & " "
  405.     ElseIf Mid(Card,3) = "dr2" then
  406.         GetLongCardName = Color & "DRAW TWO "
  407.     ElseIf Mid(Card,3) = "r" then
  408.         GetLongCardName = Color & "REVERSE "
  409.     ElseIf Mid(Card,3) = "s" then
  410.         GetLongCardName = Color & "SKIP "
  411.     End If
  412.    
  413.    
  414.     If Card = "wild" then
  415.         GetLongCardName = "1,12 w1,9i1,8l1,4d "
  416.     ElseIf Card = "wd4" then
  417.         GetLongCardName = "1,12 WILD1,9 DRA1,8W FO1,4UR "
  418.     End If
  419.     GetLongCardName = GetLongCardName & ""
  420.    
  421. End Function
  422.  
  423. 'this function checks if the player has the card he is trying to play
  424. Function CheckHasCard(Nickname,Card)
  425.     CheckHasCard = False
  426.     NicknameCards = Players.item(Nickname)
  427.     If InStr(NicknameCards,",") > 0 then
  428.         CardArr = Split(NicknameCards,",")
  429.         For i = 0 to UBound(CardArr)
  430.             If CardArr(i) = Card then
  431.                 CheckHasCard = True
  432.                 Exit For
  433.             End If
  434.         Next
  435.     Else
  436.         If NicknameCards = Card then CheckHasCard = True
  437.     End If
  438. End Function
  439.  
  440. 'this function checks if the card the player is trying to play, can be played
  441. Function CanBePut(ColorOnTable,TypeOnTable,ColorOfCard,TypeOfCard)
  442.     CanBePut = False
  443.     If ColorOfCard = "w" then
  444.         CanBePut = True
  445.         Exit Function
  446.     Elseif ColorOnTable = ColorOfCard then
  447.         CanBePut = True
  448.         Exit Function
  449.     Elseif TypeOnTable = TypeOfCard then
  450.         CanBePut = True
  451.         Exit Function
  452.     End If
  453. End Function
  454.  
  455. 'this function returns the current player
  456. Function GetCurrentPlayer(AssignedTurn)
  457. TotalPlayers = Split(PlayerList,",")
  458. If AssignedTurn = UBound(TotalPlayers) + 1 then AssignedTurn = 0
  459. If AssignedTurn = UBound(TotalPlayers) + 2 then AssignedTurn = 1
  460.  
  461. GetCurrentPlayer = TotalPlayers(AssignedTurn)
  462. End Function
  463.  
  464. 'this function removes a card from a player, and returns the number of cards the player has left
  465. Function RemoveCard(Nickname,Card)
  466.     NicknameCards = Players.Item(Nickname)
  467.     If InStr(NicknameCards,",") > 0 then
  468.         CardArr = Split(NicknameCards,",")
  469.         Found = False
  470.         NicknameCards = ""
  471.         For i = 0 to UBound(CardArr)
  472.             If Found = False then
  473.                 If Not CardArr(i) = Card then
  474.                     If NicknameCards = "" then
  475.                         NicknameCards = CardArr(i)
  476.                     Else
  477.                         NicknameCards = NicknameCards & "," & CardArr(i)
  478.                     End If
  479.                 Else
  480.                 Found = True
  481.                 End If
  482.             Else
  483.                 If NicknameCards = "" then
  484.                     NicknameCards = CardArr(i)
  485.                 Else
  486.                     NicknameCards = NicknameCards & "," & CardArr(i)
  487.                 End If
  488.             End If
  489.         Next
  490.         Players.item(Nickname) = NicknameCards
  491.         If InStr(NicknameCards,",") > 0 then
  492.             RemoveCard = UBound(Split(NicknameCards,","))+1
  493.         Else
  494.             RemoveCard = 1
  495.         End If
  496.     Else
  497.         RemoveCard = 0
  498.         Players.item(Nickname) = ""
  499.         Exit Function
  500.     End If
  501. End Function
  502.  
  503. 'this sub ends the game
  504. Sub GameOver(Winner,Channel,Win,ServerNumber)
  505.     If Win = True then
  506.         SendCommand "/msg " & Channel & " " & Winner & " has won the game",ServerNumber
  507.     End If
  508.     UnoChannel = ""
  509.     GameStarter = ""
  510.     PlayerList = ""
  511.     HasStarted = False
  512.     Players.RemoveAll
  513. End Sub
  514.  
  515. 'this sub is where the actual magic happens
  516. Sub PlayUNO(Nickname,Channel,ServerNumber,Card)
  517.  
  518.     If Card = "newgame" then
  519.  
  520.         If UBound(Split(PlayerList,",")) < 1 then 'if only one player has joined before the game starts, the game is terminated
  521.             SendCommand "/msg " & Channel & " Not enough players to start a game. Game terminated",ServerNumber
  522.             GameOver Nickname,Channel,False,ServerNumber
  523.             Exit Sub
  524.         End If
  525.         HasStarted = True
  526.         CardOnTop = Left(CardsInDeck,InStr(CardsInDeck,",")-1)
  527.         CanStart = False
  528.         CardsInDeck = Mid(CardsInDeck,InStr(CardsInDeck,",")+1)
  529.         Do While CanStart = False
  530.             If CardOnTop = "wd4" then 'the game can not start with a wild draw 4 card
  531.                 CardsInDeck = CardsInDeck & "," & CardOnTop
  532.                 CardOnTop = Left(CardsInDeck,InStr(CardsInDeck,",")-1)
  533.             Else
  534.                 CanStart = True
  535.             End If
  536.         Loop
  537.        
  538.  
  539.         If CardOnTop = "wild" then 'if the first card is a wild card, the starting color is random
  540.             TopColor = Int(rnd * 5) + 1
  541.             If TopColor = 1 then
  542.                 NewColor = "r"
  543.                 NewColor2 = "1,4 RED "
  544.             ElseIf TopColor = 2 then
  545.                 NewColor = "g"
  546.                 NewColor2 = "1,9 GREEN "        
  547.             ElseIf TopColor = 3 then
  548.                 NewColor = "b"
  549.                 NewColor2 = "1,16 BLUE "
  550.             ElseIf TopColor = 4 then
  551.                 NewColor = "y"
  552.                 NewColor2 = "1,8 YELLOW "   
  553.             ElseIf TopColor = 5 then
  554.                 NewColor = "p"
  555.                 NewColor2 = "1,13 PINK "
  556.             End If
  557.        
  558.             SendCommand "/msg " & Channel & " The play order is: " & PlayerList,ServerNumber
  559.             SendCommand "/msg " & Channel & " Game started, the first card is: " & GetLongCardName(CardOnTop) & " and the color is: " & NewColor2,ServerNumber
  560.             SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn),ServerNumber
  561.             CardsOnTable = NewColor & ":" & CardOnTop
  562.                
  563.         Else
  564.             TypeOfCard = Mid(CardOnTop,3)
  565.             SendCommand "/msg " & Channel & " The playing order is: " & PlayerList,ServerNumber
  566.             SendCommand "/msg " & Channel & " Game started, the first card is: " & GetLongCardName(CardOnTop),ServerNumber
  567.             If TypeOfCard = "s" then 'the first card is a skip card
  568.                 SendCommand "/msg " & Channel & " " & GetCurrentPlayer(Turn) & " is skipped, next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  569.                 Turn = Turn + 1
  570.             ElseIf TypeOfCard = "r" then 'the first card is reverse
  571.                 TotalPlayers = Split(PlayerList,",")
  572.                 PlayerList = ""
  573.                 for i = UBound(TotalPlayers) to 0 Step -1
  574.                     If PlayerList = "" then
  575.                         PlayerList = TotalPlayers(i)
  576.                     Else
  577.                         PlayerList = PlayerList & "," & TotalPlayers(i)
  578.                     End If
  579.                 Next
  580.                 SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn),ServerNumber
  581.                
  582.             ElseIf TypeOfCard = "dr2" then 'the first card is draw 2
  583.                 SendCommand "/msg " & Channel & " " & GetCurrentPlayer(Turn) & " Draws 2 cards and is skipped. Next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  584.                 DrawnCards = GetNewCards(2)
  585.                 Players.item(GetCurrentPlayer(Turn)) = Players.item(GetCurrentPlayer(Turn)) & "," & DrawnCards
  586.                 SendCommand "/notice " & GetCurrentPlayer(Turn) & " --- You drew: " & AddColors(DrawnCards),ServerNumber
  587.                 Turn = Turn + 1
  588.            
  589.             Else
  590.                 SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn),ServerNumber
  591.             End If
  592.             CardsOnTable = CardOnTop
  593.         End If
  594.     Else
  595.         If Left(Card,1) = "w" and InStr(Card," ") = 0 then
  596.             SendCommand "/msg " & Channel & " " & Nickname & ": Please assign a color when playing this card (!play card p/r/g/b/y)",ServerNumber
  597.             Exit Sub
  598.         ElseIf Left(Card,1) = "w" and InStr(Card," ") > 0 and Len(Card) > InStr(Card," ") then
  599.             Card = Replace(Card,":","")
  600.             NewColor = Mid(Card,InStr(Card," ")+1)
  601.             If Not (NewColor = "p" or NewColor = "r" or NewColor = "g" or NewColor = "b" or NewColor = "y") then
  602.                 SendCommand "/msg " & Channel & " Invalid color: " & NewColor,ServerNumber
  603.                 Exit Sub
  604.             Else
  605.                 Card = Left(Card,InStr(Card," ")-1)
  606.                 if NewColor = "b" then
  607.                     NewColor2 = "1,12 BLUE "
  608.                 Elseif NewColor = "g" then
  609.                     NewColor2 = "1,9 GREEN "
  610.                 Elseif NewColor = "y" then
  611.                     NewColor2 = "1,8 YELLOW "
  612.                 Elseif NewColor = "r" then
  613.                     NewColor2 = "1,4 RED "
  614.                 Elseif NewColor = "p" then
  615.                     NewColor2 = "1,13 PINK "
  616.                 End If
  617.                
  618.             End If
  619.         End If
  620.        
  621.         If CheckHasCard(Nickname,Card) = True then
  622.            
  623.             ColorOnTable = Left(CardsOnTable,1)
  624.             If InStr(CardsOnTable,",") > 0 then
  625.                 TypeOnTable = Mid(CardsOnTable,InStr(CardsOnTable,":")+1,InStr(CardsOnTable,",")-InStr(CardsOnTable,":")-1)
  626.             Else
  627.                 TypeOnTable = Mid(CardsOnTable,3)
  628.             End If
  629.             ColorOfCard = Left(Card,1)
  630.             TypeOfCard = Mid(Card,3)
  631.             If CanBePut(ColorOnTable,TypeOnTable,ColorOfCard,TypeOfCard) = True then
  632.                 If Mid(CardsOnTable,3,4) = "wild" or Mid(CardsOnTable,3,3) = "wd4" then CardsOnTable = Mid(CardsOnTable,3)
  633.                 CardsLeft = RemoveCard(Nickname,Card)
  634.                 HasDrawn = False
  635.  
  636.                
  637.                 CardsOnTable = Card & "," & CardsOnTable
  638.  
  639.  
  640.                 If TypeOfCard = "s" then 'player played a skip card
  641.                     SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card),ServerNumber
  642.  
  643.                     If CardsLeft = 0 then
  644.                         GameOver Nickname,Channel,True,ServerNumber
  645.                         Exit Sub
  646.                     ElseIf CardsLeft = 1 then
  647.                         SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  648.                     End If
  649.                     SendCommand "/msg " & Channel & " " & GetCurrentPlayer(Turn+1) & " is skipped. Next in turn: " & GetCurrentPlayer(Turn+2),ServerNumber
  650.                     Turn = Turn + 2
  651.  
  652.  
  653.                 ElseIf TypeOfCard = "dr2" then 'player played a draw 2 card
  654.                     SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card),ServerNumber
  655.                     If CardsLeft = 0 then
  656.                         GameOver Nickname,Channel,True,ServerNumber
  657.                         Exit Sub
  658.                     ElseIf CardsLeft = 1 then
  659.                         SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  660.                     End If
  661.                     SendCommand "/msg " & Channel & " " & GetCurrentPlayer(Turn+1) & " Draws 2 cards and is skipped. Next in turn: " & GetCurrentPlayer(Turn+2),ServerNumber
  662.                     DrawnCards = GetNewCards(2)
  663.                     If Not DrawnCards = "" then
  664.                         Players.item(GetCurrentPlayer(Turn+1)) = Players.item(GetCurrentPlayer(Turn+1)) & "," & DrawnCards
  665.                         SendCommand "/notice " & GetCurrentPlayer(Turn+1) & " --- You drew: " & AddColors(DrawnCards),ServerNumber
  666.                     Else
  667.                         SendCommand "/msg " & Channel & " Not enough cards in the deck",ServerNumber
  668.                     End If
  669.  
  670.                     Turn = Turn + 2
  671.  
  672.                    
  673.  
  674.                 ElseIf TypeOfCard = "r" then 'player played a reverse card
  675.                     If UBound(Split(PlayerList,",")) > 1 then
  676.                         TotalPlayers = Split(PlayerList,",")
  677.                         PlayerList = ""
  678.                         for i = UBound(TotalPlayers) to 0 Step -1
  679.                             If PlayerList = "" then
  680.                                 PlayerList = TotalPlayers(i)
  681.                             Else
  682.                                 PlayerList = PlayerList & "," & TotalPlayers(i)
  683.                             End If
  684.                         Next
  685.                         Turn = UBound(TotalPlayers)-Turn + 1
  686.                     Else
  687.                         Turn = Turn + 2
  688.                     End If
  689.  
  690.                        
  691.                     SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card),ServerNumber
  692.                     If CardsLeft = 0 then
  693.                         GameOver Nickname,Channel,True,ServerNumber
  694.                         Exit Sub
  695.                     ElseIf CardsLeft = 1 then
  696.                         SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  697.                     End If
  698.                     SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn),ServerNumber
  699.  
  700.  
  701.                 ElseIf ColorOfCard = "w" then
  702.                     CardsOnTable = NewColor & ":" & CardsOnTable
  703.                     If Card = "wild" then 'player played a wild card
  704.                         SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card) & " New color: " & NewColor2,ServerNumber
  705.                         If CardsLeft = 0 then
  706.                             GameOver Nickname,Channel,True,ServerNumber
  707.                             Exit Sub
  708.                         ElseIf CardsLeft = 1 then
  709.                             SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  710.                         End If
  711.                         SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  712.                         Turn = Turn + 1
  713.                        
  714.                     ElseIf Card = "wd4" then 'player played a wild draw 4 card
  715.                         SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card) & " New color: " & NewColor2,ServerNumber
  716.                         If CardsLeft = 0 then
  717.                             GameOver Nickname,Channel,True,ServerNumber
  718.                             Exit Sub
  719.                         ElseIf CardsLeft = 1 then
  720.                             SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  721.                         End If
  722.                         SendCommand "/msg " & Channel & " " & GetCurrentPlayer(Turn+1) & " Draws 4 cards and is skipped. Next in turn: " & GetCurrentPlayer(Turn+2),ServerNumber
  723.                         DrawnCards = GetNewCards(4)
  724.                         If Not DrawnCards = "" then
  725.                             Players.item(GetCurrentPlayer(Turn+1)) = Players.item(GetCurrentPlayer(Turn+1)) & "," & DrawnCards
  726.                             SendCommand "/notice " & GetCurrentPlayer(Turn+1) & " --- You drew: " & AddColors(DrawnCards),ServerNumber
  727.                         Else
  728.                             SendCommand "/msg " & Channel & " Not enough cards in the deck",ServerNumber
  729.                         End If
  730.                         Turn = Turn + 2
  731.  
  732.                     End If
  733.  
  734.  
  735.                 Else
  736.                     SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card),ServerNumber
  737.                     If CardsLeft = 0 then
  738.                         GameOver Nickname,Channel,True,ServerNumber
  739.                         Exit Sub
  740.                     ElseIf CardsLeft = 1 then
  741.                         SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  742.                     End If
  743.                     SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  744.                     Turn = Turn + 1
  745.                 End If
  746.                 SendCommand "/notice " & GetCurrentPlayer(Turn) & " --- Your cards are: " & AddColors(Players.item(GetCurrentPlayer(Turn))),ServerNumber
  747.             Else
  748.                 SendCommand "/msg " & Channel & " " & Nickname & ": You can not play that card",ServerNumber
  749.             End If
  750.         Else
  751.             SendCommand "/msg " & Channel & " " & Nickname & ": You do not have that card",ServerNumber
  752.         End If
  753.     End If
  754. End Sub
Add Comment
Please, Sign In to add comment