Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Please explain!

Man Clave
Registered User
Join date: 30 Jan 2007
Posts: 22
03-10-2007 21:53
I saw a free blackjack table, and i can't undestand the code, and dont know what language they use in the code.

I need someone to explain these whole code for me, i will pay 500L for the best explaination.

here is the code:

CODE

key playerkey;
string playername;
float timeout = 120.0;
integer minbet = 1;
integer maxbet = 50;
integer maxpayout = 10000;
integer amountbet = 0;
integer amountpaid = 0;

integer inplay = FALSE;
integer playerBJ = FALSE;
integer dealerBJ = FALSE;
integer player1a = FALSE;
integer player5 = FALSE;
integer dealer1a = FALSE;
integer dealer5 = FALSE;
integer bet = 0;
integer playercount = 0;
integer dealercount = 0;
integer playerscore = 0;
integer dealerscore = 0;
integer playeraces = 0;
integer dealeraces = 0;


string command;
string command1;
string command2;

parse(string bulk)
{
list chunks = llParseString2List(bulk, [" "], []);
command = llList2String(chunks, 0);
command1 = llList2String(chunks, 1);
command2 = llList2String(chunks, 2);
//command = llDeleteSubString(command, 0, prefix_length - 1);
}

reset_game()
{
llSetTimerEvent(0.0);
inplay = FALSE;
playerBJ = FALSE;
dealerBJ = FALSE;
player1a = FALSE;
player5 = FALSE;
dealer1a = FALSE;
dealer5 = FALSE;
bet = 0;
playercount = 0;
dealercount = 0;
playerscore = 0;
dealerscore = 0;
playeraces = 0;
dealeraces = 0;
}

integer card_idvalue(integer num) {
integer v;
if (num < 13) {
v = num + 2;
} else {
if (num < 26) {
v = num - 11;
} else {
if (num < 39) {
v = num - 24;
} else {
if (num < 53) {
v = num - 37;
} else {
v = 15;
}
}
}
}

return v;
}

hide_cards()
{
integer cardnum = 1;
do
{
cardnum += 1;
llMessageLinked(cardnum, 0, "Hide", "");
} while (cardnum < 11);
}

deal_card(integer cardnum)
{
integer rand_card;
rand_card = llRound(llFrand(51));
llMessageLinked(llRound(cardnum + 1), 0, "Card " + (string)rand_card, "");
if (cardnum < 6)
{
if (card_idvalue(rand_card) == 14)
{
if (cardnum == 1) {
player1a = TRUE;
}
playerscore += 11;
playeraces += 1;
}
else if (card_idvalue(rand_card) > 10) playerscore += 10;
else playerscore += card_idvalue(rand_card);

if (playerscore == 21)
{
if (cardnum == 2)
{
llWhisper(0, playername + "; Black Jack! Let's see if the dealer can get 21!");
playerBJ = TRUE;
llMessageLinked(7, 0, "Card " + (string)rand_card, "");
if (card_idvalue(rand_card) == 14)
{
dealer1a == TRUE;
dealerscore += 11;
dealeraces += 1;
}
else if (card_idvalue(rand_card) > 10) dealerscore += 10;
else dealerscore += card_idvalue(rand_card);
}
else
{
llWhisper(0, playername + "; You have " + (string)playerscore + ".");
}
dealer_play();
return;
}
else if (playerscore > 21)
{
if (playeraces > 0)
{
playeraces -= 1;
playerscore -= 10;
}
else
{
llWhisper(0, playername + "; Sorry, you busted with " + (string)playerscore + ". Better luck next time!");
reset_game();
return;
}
}
playercount += 1;
}
if (cardnum == 5)
{
llWhisper(0, playername + "; You have " + (string)playerscore + " with a 5 card trick! Let's see if the Dealer can beat that!");
player5 = TRUE;
dealer_play();
}
else if (cardnum > 1)
{
llWhisper(0, playername + "; You have " + (string)playerscore + ". 'Hit' or 'Stand'?");
}

if (cardnum == 2)
{
integer rand_card = llRound(llFrand(51));
llMessageLinked(7, 0, "Card " + (string)rand_card, "");
if (card_idvalue(rand_card) == 14)
{
dealer1a == TRUE;
dealerscore += 11;
dealeraces += 1;
}
else if (card_idvalue(rand_card) > 10) dealerscore += 10;
else dealerscore += card_idvalue(rand_card);
llMessageLinked(8, 0, "Card 53", "");
}
}

dealer_play()
{
integer cardnum = 7;
integer rand_card;

do
{
rand_card = llRound(llFrand(51));
llMessageLinked(llRound(cardnum + 1), 0, "Card " + (string)rand_card, "");
if (card_idvalue(rand_card) == 14)
{
dealerscore += 11;
dealeraces += 1;
}
else if (card_idvalue(rand_card) > 10) dealerscore += 10;
else dealerscore += card_idvalue(rand_card);
if ((dealerscore == 21) && (cardnum == 7))
{
dealerBJ = TRUE;
llWhisper(0, playername + "; Dealer has Black Jack!");
dealer_stand();
return;
}
if (dealerscore > 21)
{
if (dealeraces > 0)
{
dealeraces -= 1;
dealerscore -= 10;
}
else
{
dealer_bust();
return;
}
}

if ((dealerscore == 16) && (dealerscore > playerscore)) {
dealer_stand();
return;
}

cardnum += 1;
} while ((cardnum < 11) && (dealerscore < 17));

if (cardnum == 11)
{
dealer5 = TRUE;
llWhisper(0, playername + "; Dealer has " + (string)dealerscore + " with a 5 card trick.");
}

dealer_stand();
}

dealer_stand()
{
integer payout;
if (!dealer5) llWhisper(0, playername + "; Dealer has " + (string)dealerscore + ".");
if (player5)
{
if (dealer5)
{
if (playerscore > dealerscore)
{
payout = (bet * 2);
llWhisper(0, playername + "; You won $" + (string)payout + "!");
llGiveMoney(playerkey, payout);
amountpaid += payout;
}
else
{
llWhisper(0, playername + "; Sorry, you lost. Better luck next time!");
}
}
else
{
payout = (bet * 2);
llWhisper(0, playername + "; You won $" + (string)payout + "!");
llGiveMoney(playerkey, payout);
amountpaid += payout;
}
}
else if (dealer5)
{
if ((playerBJ) && (player1a))
{
payout = (bet * 3);
llWhisper(0, playername + "; You won $" + (string)payout + "!");
llGiveMoney(playerkey, payout);
amountpaid += payout;
}
else
{
llWhisper(0, playername + "; Sorry, you lost. Better luck next time!");
}
}
else if (playerscore > dealerscore)
{
if (playerBJ) payout = (bet * 3);
else payout = (bet * 2);
llWhisper(0, playername + "; You won $" + (string)payout + "!");
llGiveMoney(playerkey, payout);
amountpaid += payout;
}
else if (playerscore == dealerscore)
{
llGiveMoney(playerkey, bet);
amountpaid += bet;
llWhisper(0, playername + "; You tied with the Dealer! You won $" + (string)bet + "!");
}
else
{
llWhisper(0, playername + "; Sorry, you lost. Better luck next time!");
}
reset_game();
}

dealer_bust()
{
integer payout;
if (playerBJ) payout = (bet * 3);
else payout = (bet * 2);
llWhisper(0, playername + "; The Dealer busted with " + (string)dealerscore + "! You won $" + (string)payout + "!");
llGiveMoney(playerkey, payout);
amountpaid += payout;
reset_game();
}

default
{
on_rez(integer sparam)
{
llResetScript();
}

state_entry()
{
hide_cards();
llListen(0, "", "", "");
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
}

listen(integer channel, string name, key id, string message)
{
parse(message);
if ((id == playerkey) && (inplay))
{
if (llToLower(message) == "hit")
{
llSetTimerEvent(timeout);
deal_card(llRound(playercount + 1));
}
if (llToLower(message) == "stand")
{
llSetTimerEvent(timeout);
dealer_play();
}
}

if(command == "status" && command1 == "blackjack")
{
llSay(0,"Minimum Bet: " + (string)minbet);
llSay(0,"Maximum Bet: " + (string)maxbet);
llSay(0,"Max Payout: " + (string)maxpayout);
llSay(0,"Time Out: " + (string)timeout);
}

if(!inplay && id == llGetOwner())
{
if(command == "minbet")
{
if((integer)command1 <= maxbet)
{
minbet = (integer)command1;
llSay(0,"Minimum BET set to " + command1);
}
else if((integer)command1 > maxbet)
{
llSay(0,"Minimum Bet must be less than or equal to Maximum Bet");
}
}
else if(command == "maxbet")
{
if((integer)command1 >= minbet)
{
maxbet = (integer)command1;
llSay(0,"Maximum BET set to " + command1);
}
else if((integer)command1 < minbet)
{
llSay(0,"Maximum Bet must be greater than or equal to Minimum Bet");
}
}
else if(command == "maxpayout")
{
maxpayout = (integer)command1;
llSay(0,"Maximum PAYOUT set to " + command1);
}
else if(command == "timeout")
{
timeout = (float)command1;
llSay(0,"Timeout set to " + command1);
}
}
else if(inplay)
{
llSay(0,"Someone is currently playing this game. Please wait until they finish this hand to
change the settings.");
}

if(id == llGetOwner() && llToLower(message) == "reset blackjack")
{
llResetScript();
}
}

link_message(integer sender_num, integer num, string str, key id)
{
if ((id == playerkey) && (inplay))
{
if (llToLower(str) == "hit")
{
llSetTimerEvent(timeout);
deal_card(llRound(playercount + 1));
}
if (llToLower(str) == "stand")
{
llSetTimerEvent(timeout);
dealer_play();
}
}
}

money(key giver, integer amount)
{
if (inplay) {
llGiveMoney(giver, amount);
llWhisper(0, "Another game is in play.");
return;
}
else if ((amount > maxbet) || (amount < minbet))
{
llGiveMoney(giver, amount);
llWhisper(0, "Min Bet: $" + (string)minbet);
llWhisper(0, "Max Bet: $" + (string)maxbet);
return;
}
else if ((amountpaid > maxpayout) || (amountpaid == maxpayout))
{
llGiveMoney(giver, amount);
llWhisper(0, "This machine is currently down for servicing");
return;
}

amountbet += amount;

hide_cards();

playerkey = giver;
playername = llKey2Name(giver);
inplay = TRUE;
bet = amount;

llWhisper(0, "$" + (string)bet + " bet! Good luck!");

deal_card(1);
deal_card(2);

llSetTimerEvent(timeout);
}

touch_start(integer total_number)
{
if (llDetectedKey(0) == llGetOwner())
{
llWhisper(0, "Total Amount Bet: $" + (string)amountbet);
llWhisper(0, "Total Amount Paid: $" + (string)amountpaid);
}
else
{
llWhisper(0, "Black Jack! Right-Click and 'Pay' to Play!");
}
}

timer()
{
integer refund = bet;
llWhisper(0, "Black Jack has timed out. Please contact the owner for a refund.");
reset_game();
llInstantMessage(llGetOwner(), "Black Jack timed out for " + playername + " on a $" + (string)refund + " bet.");
}
}



Thanks
Jacques Groshomme
Registered User
Join date: 16 Mar 2005
Posts: 355
03-10-2007 23:53
What you want is too complicated to explain here, especially if you've never touched code before. This forum isn't meant for full tutorials but rather sharing and assistance with small code snippets.

Scripting in Second Life is through a proprietary language called LSL (Linden Scripting Language) which is loosely similar to C or JavaScript. The best documentation of the language is at www.lslwiki.net.

Also try looking at the Event schedule in-world to find some scripting classes for beginners. They should run a few times every day.
Roms Maertens
Registered User
Join date: 23 Feb 2007
Posts: 3
03-13-2007 15:47
Please consider you're asking a strong experienced programmer to give you at least a full year of programming lessons for less than 2 US $.
Rather than this, consider learning standard programming languages on your own, this is not as painfull as it seems, and in a short while, you'll be able to understand this script and make your own ones, all for free :)
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
03-13-2007 16:04
Or I'll teach you for L$16,000 per hour. I'll even give you 18 hr days of teaching if you want.

I have to be paid each hour up front though.

:)
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Dnel DaSilva
Master Xessorizer
Join date: 22 May 2005
Posts: 781
03-13-2007 16:40
Hehe Man, you are at it again eh. Really, if you want to learn, do some studying in the wiki, anyone with a coding background (or even me with a handful of university CS classes) should be able to figure out how the script works. Trying to bribe anyone with 2 bux isn't going to work.

(someone just give him a working freebie blackjack table already!)
_____________________
Xessories in Urbane, home of high quality jewelry and accessories.

Coming soon to www.xessories.net

Why accessorize when you can Xessorize?