Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Blackjack NPC

Newbie Spellweaver
Joined
Jul 5, 2010
Messages
46
Reaction score
15
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:
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(1, 0, 0);
}

function action(mode, type, selection) {
    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:
Custom Title Activated
Loyal Member
Joined
Mar 17, 2009
Messages
1,911
Reaction score
538
Nice <3 I love blackjack.

Good job!
 
Newbie Spellweaver
Joined
Jul 5, 2010
Messages
46
Reaction score
15
I tested it, seems to be working.. Dc's you sometimes at the first "Dealer is showing... " Funkay.
Thanks for your comments. C:
 
Newbie Spellweaver
Joined
Aug 20, 2009
Messages
82
Reaction score
0
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
 
Newbie Spellweaver
Joined
Jul 1, 2010
Messages
59
Reaction score
5
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?
 
Joined
Apr 10, 2008
Messages
4,087
Reaction score
1,264
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)
 
I'm sexy and I know it :)
Joined
Oct 21, 2008
Messages
811
Reaction score
350
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.
 
Back
Top