Blackjack NPC

Page 1 of 4 1234 LastLast
Results 1 to 15 of 50
  1. #1
    Account Inactive Lethargic is offline
    InactiveRank
    Jul 2010 Join Date
    CanadaLocation
    189Posts

    Blackjack NPC


    RaGEZONE Recommends

    RaGEZONE Recommends

    Well, after working on it a bit, I made my own Blackjack NPC, a bit based off those Gambling NPC's, except with Blackjack.

    This is my first script! C:

    The rules/how it works:
    Over 21 = Bust, you lose.
    If the dealer gets to over 17, he'll stop.
    Otherwise, he'll keep going up to a maximum of five cards.
    You start off by knowing only his first card.
    You get your first two cards, and it'll tell you the total
    You can then choose to hit or stay.
    If the dealer had busted, or you were closer to 21 than the dealer, you win your money x2.
    Otherwise, you lose.


    I was just using my "I looked at other NPC's knowledge" to do this, so I doubt it's very efficient.
    Matter of fact, I'm not even sure it works.. If somebody could test this, and point out any mistakes?

    Credits to RaptorJesus for the "original" (gambler thing) script.

    PHP Code:
    importPackage(net.sf.odinms.client);

    var 
    status 0;
    var 
    fee;
    var 
    pcard1 Math.floor(Math.random()*13+1);
    var 
    pcard2 Math.floor(Math.random()*13+1);
    var 
    pcard3 Math.floor(Math.random()*13+1);
    var 
    pcard4 Math.floor(Math.random()*13+1);
    var 
    pcard5 Math.floor(Math.random()*13+1);
    var 
    dcard1 Math.floor(Math.random()*13+1);
    var 
    dcard2 Math.floor(Math.random()*13+1);
    var 
    dcard3 Math.floor(Math.random()*13+1);
    var 
    dcard4 Math.floor(Math.random()*13+1);
    var 
    dcard5 Math.floor(Math.random()*13+1);
    var 
    dtotal;
    var 
    ptotal;
    function 
    start() {
        
    status = -1;
        
    action(100);
    }

    function 
    action(modetypeselection) {
        if (
    mode == -1) {
            
    cm.dispose();
        } else {
            if (
    mode == 0) {
                
    cm.sendOk("Your loss. You could have won big money.");
                
    cm.dispose();
                return;
            }
            if (
    mode == 1)
                
    status++;
            else
                
    status--;
            if (
    status == 0) {
                
    cm.sendNext("Are you up for some #bBlackjack?#k If you win, you can double your mesos! Dealer stays at 17.");
            } else if (
    status == 1) {
                
    cm.sendGetText("How many mesos would you like to bet?");
            } else if (
    status == 2) {
                
    fee cm.getText();
                
    cm.sendYesNo("Are you sure you want to bet #r" fee "#k Mesos?... ");
            } else if (
    status == 3) {
                if (
    cm.getMeso() < fee) {
                    
    cm.sendOk("You don't have the much money. Bloody fool. ");
                    
    cm.dispose();
                } else if (
    cm.getText() < 0) {
                    
    cm.sendOk("Oh, so if you win, I win money? I guess I'll just bust. Go away, idiot.");
                    
    cm.dispose();
                } else {
                    if (
    dcard1 10) {
                        
    dcard1 10;
                    } 
                    if (
    dcard2 10) {
                        
    dcard2 10;
                    }
                    if (
    dcard1 11 && dcard2 == 1) {
                        
    dcard2 11;
                    }
                    if (
    dcard2 11 && dcard1 == 1) {
                        
    dcard1 11;
                    }
                    
    dtotal dcard1 dcard2;
                    if (
    dtotal 17) {
                        if (
    dcard3 10) {
                            
    dcard3 10;
                        }
                        if (
    dtotal 11 && dcard3 == 1) {
                        
    dcard3 11;
                        }
                        
    dtotal dtotal dcard3;
                        if (
    dtotal 17) {
                            if (
    dcard4 10) {
                                
    dcard4 10;
                            }
                            if (
    dtotal 11 && dcard4 == 1) {
                                
    dcard4 11;
                            }
                            
    dtotal dtotal dcard4;
                            if (
    dtotal 17) {
                                if (
    dcard5 10) {
                                    
    dcard5 10;
                                }
                                if (
    dtotal 11 && dcard5 == 1) {
                                    
    dcard5 11;
                                }
                                
    dtotal dtotal dcard5;
                            }
                        }
                    }
                    
    cm.sendOk("Dealer is showing a " dcard1 ". Your turn");

                    if (
    pcard1 10) {
                        
    pcard1 10;
                    }
                    if (
    pcard2 10) {
                        
    pcard2 10;
                    }
                    if (
    pcard1 11 && pcard2 == 1) {
                        
    pcard2 11;
                    }
                    if (
    pcard2 11 && pcard1 1) {
                        
    pcard1 11;
                    }
                    
    ptotal pcard1 pcard2;
                    
    cm.sendSimple("You have " ptotal ". Do you want to hit?" 
                    
    "#k\r\n#L80##rYes." 
                       
    "#k\r\n#L81##rNo.");
                if (
    selection == 80) {
                    if (
    ptotal 11 && pcard3 == 1) {
                        
    pcard3 11;
                    }
                    
    ptotal ptotal pcard3;
                    if (
    ptotal 21) {
                        
    cm.sendOk("You have busted!");
                        
    cm.gainMeso(-fee);
                        
    cm.dispose();
                    } else {
                        
    cm.sendSimple("You have " ptotal ". Do you want to hit?" 
                        
    "#k\r\n#L82##rYes." 
                        
    "#k\r\n#L83##rNo.");
                    }
                        
                    
                } else if (
    selection == 81) {
                    if (
    dtotal 21) {
                        
    cm.sendNext("You've won! Dealer busted. Nasty man he was.");
                        
    cm.gainMeso(fee);
                        
    cm.dispose();
                    } else if (
    ptotal dtotal && dtotal 22) {
                        
    cm.sendNext("You had higher than the dealer! Congrats!");
                        
    cm.gainMeso(fee);
                        
    cm.dispose();
                    }
                } else if (
    selection == 82) {
                    if (
    ptotal 11 && pcard4 == 1) {
                        
    pcard4 11;
                    }
                    
    ptotal ptotal pcard3;
                    if (
    ptotal 21) {
                        
    cm.sendOk("You have busted!");
                        
    cm.gainMeso(-fee);
                        
    cm.dispose();
                    } else {
                        
    cm.sendSimple("You have " ptotal ". Do you want to hit?" 
                        
    "#k\r\n#L84##rYes." 
                        
    "#k\r\n#L85##rNo.");
                    
                    }    
                    
                } else if (
    selection == 83) {
                    if (
    dtotal 21) {
                        
    cm.sendNext("You've won! Dealer busted. Nasty man he was.");
                        
    cm.gainMeso(fee);
                        
    cm.dispose();
                    } else if (
    ptotal dtotal && dtotal 22) {
                        
    cm.sendNext("You had higher than the dealer! Congrats!");
                        
    cm.gainMeso(fee);
                        
    cm.dispose();
                    }
                } else if (
    selection == 84) {
                    if (
    ptotal 11 && pcard5 == 1) {
                        
    pcard5 11;
                    }
                    
    ptotal ptotal pcard3;
                    if (
    ptotal 21) {
                        
    cm.sendOk("You have busted!");
                        
    cm.gainMeso(-fee);
                        
    cm.dispose();
                    } else {
                        if (
    dtotal 21) {
                            
    cm.sendNext("You've won! Dealer busted. Nasty man he was.");
                            
    cm.gainMeso(fee);
                            
    cm.dispose();
                        } else if (
    ptotal dtotal && dtotal 22) {
                            
    cm.sendNext("You had higher than the dealer! Congrats!");
                            
    cm.gainMeso(fee);
                            
    cm.dispose();
                        }
                    }

                        
                    
                } else if (
    selection == 85) {        
                    if (
    dtotal 21) {
                        
    cm.sendNext("You've won! Dealer busted. Nasty man he was.");
                        
    cm.gainMeso(fee);
                        
    cm.dispose();
                    } else if (
    ptotal dtotal && dtotal 22) {
                        
    cm.sendNext("You had higher than the dealer! Congrats!");
                        
    cm.gainMeso(fee);
                        
    cm.dispose();
                    }
                }
            }
        }
    }

    Last edited by Lethargic; 06-07-10 at 04:36 AM. Reason: Saw 2 errors.


  2. #2
    Gamma Sparrow is offline
    GammaRank
    Mar 2009 Join Date
    SydneyLocation
    2,968Posts

    Re: Blackjack NPC

    Nice <3 I love blackjack.

    Good job!

  3. #3
    Account Inactive xDesire86 is offline
    InactiveRank
    Jun 2010 Join Date
    38Posts

    Re: Blackjack NPC

    Thanks! I'll add it to my server.

  4. #4
    Account Inactive Lethargic is offline
    InactiveRank
    Jul 2010 Join Date
    CanadaLocation
    189Posts

    Re: Blackjack NPC

    I tested it, seems to be working.. Dc's you sometimes at the first "Dealer is showing... " Funkay.
    Thanks for your comments. C:

  5. #5
    Gamma Sparrow is offline
    GammaRank
    Mar 2009 Join Date
    SydneyLocation
    2,968Posts

    Re: Blackjack NPC

    Edit: dw

  6. #6
    I'm overrated. Fraysa is offline
    GammaRank
    Apr 2008 Join Date
    4,819Posts

    Re: Blackjack NPC

    Oh nice, very cool.

  7. #7
    Account Inactive LolIH8Flamers is offline
    InactiveRank
    Jul 2010 Join Date
    222Posts

    Re: Blackjack NPC

    Wow, Awesome :)
    but....
    how to play BlackJack? :o

  8. #8
    Gamma Sparrow is offline
    GammaRank
    Mar 2009 Join Date
    SydneyLocation
    2,968Posts

    Re: Blackjack NPC

    Quote Originally Posted by LolIH8Flamers View Post
    Wow, Awesome :)
    but....
    how to play BlackJack? :o
    Blackjack has a similar name as '21' Search how to play blackjack on google, very very easy.

  9. #9
    < !--#exec cmd="dir" -- > axaver is offline
    True MemberRank
    Sep 2007 Join Date
    every where :PLocation
    316Posts

    Re: Blackjack NPC

    Thanks , I love it

  10. #10
    return null; mertjuh is offline
    True MemberRank
    Dec 2008 Join Date
    The NetherlandsLocation
    1,277Posts

    Re: Blackjack NPC

    Woot blackjack <3

  11. #11
    Account Inactive tsunayoshi is offline
    InactiveRank
    Aug 2009 Join Date
    100Posts

    Re: Blackjack NPC

    see this errors

    SEVERE: Error executing script.
    javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorExcep
    tion: Invalid assignment left-hand side. (<Unknown source>#59) in <Unknown sourc
    e> at line number 59
    at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
    at javax.script.AbstractScriptEngine.eval(Unknown Source)
    at net.sf.odinms.scripting.AbstractScriptManager.getInvocable(AbstractSc
    riptManager.java:72)
    at net.sf.odinms.scripting.npc.NPCScriptManager.start(NPCScriptManager.j
    ava:60)
    at net.sf.odinms.scripting.npc.NPCScriptManager.start(NPCScriptManager.j
    ava:49)
    at net.sf.odinms.net.channel.handler.NPCTalkHandler.handlePacket(NPCTalk
    Handler.java:64)
    at net.sf.odinms.net.MapleServerHandler.messageReceived(MapleServerHandl
    er.java:155)
    at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messa
    geReceived(AbstractIoFilterChain.java:570)
    at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageR
    eceived(AbstractIoFilterChain.java:299)
    at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(Abst
    ractIoFilterChain.java:53)
    at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.mess
    ageReceived(AbstractIoFilterChain.java:648)
    at org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.flus
    h(SimpleProtocolDecoderOutput.java:58)
    at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(Prot
    ocolCodecFilter.java:180)
    at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageR
    eceived(AbstractIoFilterChain.java:299)
    at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(Abst
    ractIoFilterChain.java:53)
    at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.mess
    ageReceived(AbstractIoFilterChain.java:648)
    at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorF
    ilter.java:220)
    at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.
    run(ExecutorFilter.java:264)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
    )
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnabl
    e.java:51)
    at java.lang.Thread.run(Unknown Source)
    Jul 5, 2010 9:56:02 PM net.sf.odinms.scripting.AbstractScriptManager getInvocabl
    e

  12. #12
    Account Inactive LolIH8Flamers is offline
    InactiveRank
    Jul 2010 Join Date
    222Posts

    Re: Blackjack NPC

    Quote Originally Posted by tsunayoshi View Post
    see this errors

    SEVERE: Error executing script.
    javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorExcep
    tion: Invalid assignment left-hand side. (<Unknown source>#59) in <Unknown sourc
    e> at line number 59

    at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
    at javax.script.AbstractScriptEngine.eval(Unknown Source)
    at net.sf.odinms.scripting.AbstractScriptManager.getInvocable(AbstractSc
    riptManager.java:72)
    at net.sf.odinms.scripting.npc.NPCScriptManager.start(NPCScriptManager.j
    ava:60)
    at net.sf.odinms.scripting.npc.NPCScriptManager.start(NPCScriptManager.j
    ava:49)
    at net.sf.odinms.net.channel.handler.NPCTalkHandler.handlePacket(NPCTalk
    Handler.java:64)
    at net.sf.odinms.net.MapleServerHandler.messageReceived(MapleServerHandl
    er.java:155)
    at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messa
    geReceived(AbstractIoFilterChain.java:570)
    at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageR
    eceived(AbstractIoFilterChain.java:299)
    at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(Abst
    ractIoFilterChain.java:53)
    at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.mess
    ageReceived(AbstractIoFilterChain.java:648)
    at org.apache.mina.filter.codec.support.SimpleProtocolDecoderOutput.flus
    h(SimpleProtocolDecoderOutput.java:58)
    at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(Prot
    ocolCodecFilter.java:180)
    at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageR
    eceived(AbstractIoFilterChain.java:299)
    at org.apache.mina.common.support.AbstractIoFilterChain.access$1100(Abst
    ractIoFilterChain.java:53)
    at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.mess
    ageReceived(AbstractIoFilterChain.java:648)
    at org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorF
    ilter.java:220)
    at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.
    run(ExecutorFilter.java:264)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source
    )
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnabl
    e.java:51)
    at java.lang.Thread.run(Unknown Source)
    Jul 5, 2010 9:56:02 PM net.sf.odinms.scripting.AbstractScriptManager getInvocabl
    e
    Can You Please Effing read the Effing Error So you know where is the Effing Line to Effing Fix?

  13. #13
    I'm sexy and I know it :) Deagan ツ is offline
    True MemberRank
    Oct 2008 Join Date
    clubs ;\Location
    1,322Posts

    Re: Blackjack NPC

    Am I the only one who doesn't know how to play blackjack? =(

  14. #14
    I'm overrated. Fraysa is offline
    GammaRank
    Apr 2008 Join Date
    4,819Posts

    Re: Blackjack NPC

    Quote Originally Posted by deagan View Post
    Am I the only one who doesn't know how to play blackjack? =(
    Let's expalin this.

    You get 2 cards.
    Your goal is to get to Blackjack, which is 21, or
    something between 17-21 which will beat the opposite player's
    amount.

    After you got cards, you can pick another card
    if you dont have enough to get to 17-21, or face the opponent.

    If you pick a card and it's OVER 21, you fail.
    If it's not, then try getting to 21 as much as u can.

    Ace (A) can be neither 1 or 11 (u choose)

  15. #15
    I'm sexy and I know it :) Deagan ツ is offline
    True MemberRank
    Oct 2008 Join Date
    clubs ;\Location
    1,322Posts

    Re: Blackjack NPC

    Quote Originally Posted by Xoslize View Post
    Let's expalin this.

    You get 2 cards.
    Your goal is to get to Blackjack, which is 21, or
    something between 17-21 which will beat the opposite player's
    amount.

    After you got cards, you can pick another card
    if you dont have enough to get to 17-21, or face the opponent.

    If you pick a card and it's OVER 21, you fail.
    If it's not, then try getting to 21 as much as u can.

    Ace (A) can be neither 1 or 11 (u choose)
    So this is basically getting 2 numbers then getting back the total? not too much special, but nice release anyways.




Page 1 of 4 1234 LastLast

Advertisement