Scripts, Tutorials & Tools This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.

Ad Content
Reply
 
Thread Tools
  #1   Link to this post, but load the entire thread.  
Old 1 Week Ago (4:13 PM). Edited 1 Week Ago by alex995.
alex995 alex995 is offline
     
    Join Date: Sep 2018
    Posts: 3
    EDIT:
    Thanks for helping me mgriffin! I do a trial with the changes you adviced and they seem all to work, except for the value assignment part (pbValueBJ), due by your suggest I make this

    Spoiler:

    Code:
    def pbValueBJ 
      numero=@index[1..-1]
      if numero == "A"
        if @turn==0
    		 if (@pp+11)>21
    			 return 1
    		 else
    			 return 11
    		 end
        else
    		 if (@dp+11)>21
    			 return 1
    		 else
    			 return 11
         end
       end
    	elsif numero == "J" or numero == "Q" or numero == "K"
        return 10
      else
        return numero.to_i
      end
    end


    In a Ruby Interpreter this code returns the right values, but in Pokémon Essentials it returns only 0.
    -------------------------------------------------------------------------------------------------------------------------------------------------
    -------------------------------------------------------------------------------------------------------------------------------------------------
    Hi!
    I'm working on my project in Pokémon Essentials for at least one and half year.
    In this time I've solved lots of problems and I learned about programming and about the use of RPG Maker.

    Often I used tools, materials or scripts that community's people share, now for the first time I've written this script totally anew, and I would share with anyone would be interested.

    One of the thing I would insert inmy project is a more featured casino, so, inspired by a similar feature in the Hack Rom "Pokémon Prism" I tried to write this text-based BlackJack Game.

    At the moment there isn't any graphical issue, pure text.

    I hope you enjoy this and I hope also to improve this work, to make others and finally publish my project.

    NOTES:

    - Copy the script in Printable Version to preserve the integrity of the script.

    - The language of the script is English, name of variables and other things in this script could be in Italian (my mother language), so if you are confident with scripting or doubtful about the translation don't modify the script or it couldn't work.

    - Other information are in comment lines above the script.

    - For make properly display the card suits symbols the font need to had those! In Pokémon Essentials the only default font which has this set is DP-style one.

    - Look at the attachment to see how to configure (how i did, you could do anything you want) an event that start the script.
    Spoiler:

    Code:
    #-------------------------------------------------------------------------------
    #BlackJack by alex995
    #-------------------------------------------------------------------------------
    #INTRO
    #-------------------------------------------------------------------------------
    #I was influenced by a feature of the Hack Rom Pokémon Prism.
    #There's not graphical issues (at least for the moment), it's a text game.
    #This script is written totally anew. It provides a BlackJack-like game.
    #Credits are appreciated.
    #-------------------------------------------------------------------------------
    #HOW TO MAKE IT WORK
    #-------------------------------------------------------------------------------
    #For making this script work simply put a script in an event with BlackJack.new
    #Note that I have reserved the variable 111 for store the money the player bets.
    #If that variable is used by your project change the number 111 in the script, 
    #with any number you want (up to 5000).
    #If you don't want to bet money comment the lines with the variable @im.
    #-------------------------------------------------------------------------------
    #MAIN GAME PART
    #-------------------------------------------------------------------------------
    class  BlackJack
    
    def initialize
    @@semi = ["♥","♦","♣","♣"]
    @@cards = ["A","2","3","4","5","6","7","J","Q","K"]
    @@randomMazzo = []
    @draft = nil
    @pp=0 #punteggio giocatore
    @dp=0 #punteggio banco
    @index=nil
    @turn=nil
    @im=pbGet(111) #variabile dove sono memorizzati i soldi puntati
    @exit=0
    pbMazzoACaso
    pbBlackJack
    end
    
    def pbBlackJack #struttura del gioco
      pbInitialDrawBJ #prima manche
      while pbCheckBJ == true #ciclo che fa ripetere fino alle condizioni di vittoria/sconfitta
        pbDrawBJ #turno "classico"
      end
      pbBettingBJ #attribuzione vittoria e posta relativa
      $game_variables[111]= @im
    end
    
    def pbInitialDrawBJ
    @turn=0
    pbPesca
      pd1= @draft #sorteggio carta uno giocatore
        @index=pd1 #variabile per il confronto carta/punteggio
          vpd1=pbValueBJ.to_i #attribuzione punteggio
    pbPesca
      pd2=@draft
        @index=pd2
          vpd2=pbValueBJ.to_i
      @pp=vpd1+vpd2 #punteggio giocatore dopo il primo turno
    @turn=1
    pbPesca
      dd1=@draft
        @index=dd1
          vdd1=pbValueBJ.to_i
    pbPesca
      dd2=@draft
        @index=dd2
          vdd2=pbValueBJ.to_i
      @dp=vdd1+vdd2 #punteggio banco dopo il primo turno
      Kernel.pbMessage(INTL_("Your cards: "+pd1.to_s+" e "+pd2.to_s+"."))
      Kernel.pbMessage (INTL_("Dealer's cards: "+dd1.to_s+" e "+dd2.to_s+"."))
      Kernel.pbMessage(INTL_("Points: "+@pp.to_s+". Dealer: "+@dp.to_s+".")
      @turn=nil
    end
    
    def pbDrawBJ
      #scelta = gets.chomp
      if Kernel.pbConfirmMessage((INTL_"Do you want draw another card?"))
      @turn=0
      pbPesca
        pd=@draft
          @index=pd
            vpd=pbValueBJ.to_i
        @pp+=vpd
        if pbAIBJ
        @turn = 1
        pbPesca
          dd=@draft
            @index=dd
              vdd=pbValueBJ.to_i
          @dp+=vdd
          Kernel.pbMessage(INTL_("Your draft: "+pd.to_s+"."))
          Kernel.pbMessage(INTL_("Dealer's draft: "+dd.to_s+"."))
          Kernel.pbMessage((INTL_("Points: "+@pp.to_s+". Dealer: "+@dp.to_s+"."))
    	  @turn = nil
        @exit=0
        else
    	  Kernel.pbMessage((INTL_"Your draft: "+pd.to_s+"."))
          Kernel.pbMessage(INTL_"Points: "+@pp.to_s+". Dealer: "+@dp.to_s+"."))
    	  @exit=1
        end
      else
        if pbAIBJ
    	@turn=1
    	pbPesca
          dd=@draft
            @index=dd
              vdd=pbValueBJ.to_i
          @dp+=vdd
          Kernel.pbMessage((INTL_("Dealer's draft: "+dd.to_s+"."))
          Kernel.pbMessage(INTL_("Points: "+@pp.to_s+". Dealer: "+@dp.to_s+"."))
    	  @turn=nil
    	  @exit=1
        else
          Kernel.pbMessage(INTL_("Points: "+@pp.to_s+". Dealer: "+@dp.to_s+"."))
    	  @turn=nil
    	  @exit=1
        end
      end
      pbCheckBJ
    end
    
    def pbAIBJ #AI del banco (gioca carta o sta) forse da migliorare
      if @dp < 17
        return true
      else
        return false
      end
    end
    
    def pbCheckBJ #check per le condizioni di vittoria/sconfitta, forse anche qui da migliorare
      if @pp > 21 or @dp > 21 or @exit != 0
        return false
      else
        return true
      end
    end
      
    def pbValueBJ 
      if (@index =="♥A" or @index =="♦A" or @index =="♣A" or @index =="♣A") 
    	if @turn==0
    		if (@pp+11)>21
    			return 1
    		else
    			return 11
    		end
        else
    		if (@dp+11)>21
    			return 1
    		else
    			return 11
    		end
    	end
      elsif (@index == "♥2" or @index == "♦2" or @index == "♣2" or @index=="♣2") 
    	return 2
      elsif (@index == "♥3" or @index == "♦3" or @index == "♣3" or @index == "♣3")
        return 3
      elsif (@index == "♥4" or @index == "♦4" or @index == "♣4" or @index == "♣4")
        return 4
      elsif (@index == "♥5" or @index == "♦5" or @index == "♣5" or @index == "♣5")
        return 5
      elsif (@index == "♥6" or @index == "♦6" or @index == "♣6" or @index == "♣6")
        return 6
      elsif (@index == "♥7" or @index == "♦7" or @index == "♣7" or @index == "♣7")
        return 7
      elsif (@index == "♥J" or @index == "♦J" or @index == "♣J" or @index == "♣J")
        return 10
      elsif (@index == "♥Q" or @index == "♦Q" or @index == "♣Q" or @index == "♣Q")
        return 10
      elsif (@index == "♥K" or @index == "♦K" or @index == "♣K" or @index == "♣K")
        return 10
      end
    end
    
    def pbBettingBJ
      if @pp > @dp
        if @pp <= 21
          @im+=@im
          Kernel.pbMessage("You won!")
          if @pp == 21
            Kernel.pbMessage("BlackJack!")
          end
        elsif @pp>21 && @dp>21
          Kernel.pbMessage("Draw!")
        else
         @im=0
         Kernel.pbMessage("The dealer won!")
        end
      elsif @pp==@dp
        Kernel.pbMessage("Draw!")
      elsif @pp<@dp
        if @dp <= 21
          @im=0
          Kernel.pbMessage("The dealer won!")
        elsif @pp <=21 && @dp > 21
          @im+=@im
          Kernel.pbMessage("You won!")
        elsif
          Kernel.pbMessage("Draw!")
        end
      end
    end
    #-------------------------------------------------------------------------------
    #DECK PART
    #-------------------------------------------------------------------------------
    @@semi = ["♥","♦","♣","♠"]
    @@cards = ["A","2","3","4","5","6","7","J","Q","K"]
    @@randomMazzo = []
    @draft = nil
    
    def pbMazzoACaso
      @@semi.each do |suit|
      @@cards.each do |numero|
        @@randomMazzo.push suit+numero
      end
    end
    pbMischia
    end
    
    def pbMischia
    @@randomMazzo.shuffle!
    end
    def pbPesca
    @draft = @@randomMazzo.last
    @@randomMazzo.pop
    contrario=@@randomMazzo.reverse
    contrario.push @draft
    @@randomMazzo = contrario.reverse
    end
    end
    Attached Images
    File Type: png Esempio.png‎ (32.8 KB, 11 views) (Save to Dropbox)
    Reply With Quote
      #2   Link to this post, but load the entire thread.  
    Old 1 Week Ago (3:01 AM).
    mgriffin's Avatar
    mgriffin mgriffin is online now
     
    Join Date: Apr 2014
    Posts: 260
    Very cool!


    A few small comments:
    Code:
      elsif (@index == "♥J" or @index == "♦J" or @index == "♣J" or @index == "♣J")
        return 8
      elsif (@index == "♥Q" or @index == "♦Q" or @index == "♣Q" or @index == "♣Q")
        return 9
    I think this is saying that jack and queen are worth 8 and 9, but I think they're both supposed to be 10 (like king).

    Code:
    	@@cards.each do |numero|
    	@@randomMazzo.push @@semi[0]+numero
    	end
    
    	@@cards.each do |numero|
    	@@randomMazzo.push @@semi[1]+numero
    	end
    
    	@@cards.each do |numero|
    	@@randomMazzo.push @@semi[2]+numero
    	end
    
    	@@cards.each do |numero|
    	@@randomMazzo.push @@semi[3]+numero
    	end
    You could write this as two loops, one over the suits and one over the numbers, e.g.:
    Code:
    @@semi.each do |suit| # Sorry, don't know the Italian!
      @@cards.each do |numero|
        @@randomMazzo.push suit+numero
      end
    end
    I don't know if it exists in Essentials, but you could use sort_by! to simplify pbMischia:
    Code:
    def pbMischia
    @@randomMazzo.sort_by! {rand}
    end
    Or better yet, just use shuffle!.

    Finally in your code that converts cards to values you could remove the suit before the if/elses so that you don't have to check for "♥X" or "♦X" or "♣X" or "♣X". Something like this:
    Code:
    def pbValueBJ
      numero=@index[1..-1]
      if numero=="A"
        ...
      elsif numero=="2"
        ...
      ... # etc
    end
    Reply With Quote
    Reply

    Quick Reply

    Join the conversation!

    Create an account to post a reply in this thread, participate in other discussions, and more!

    Create a PokéCommunity Account
    Ad Content
    Thread Tools

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -8. The time now is 1:24 PM.