Jump to content

gummy gumball machine


irihapeti
 Share

You are about to reply to a thread that has been inactive for 3261 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

i post this a while ago over the street and I been meaning to do here. So I do now

i tidy up the flow a bit so is not quite the same as that other one. but anyways

+

a gumball machine is a bit different from a slot machine. Meaning that the result of each pull/spin/turn is dependent on what has previously been paid out. Unlike a slot machine where each pull/turn/spin is independent of the previous

basically a gumball machine will empty when a player keeps playing it. The outcome being that when a person plays to the end then they will get everything in it guaranteed. Unlike a slot machine for which there is no same guarantee

for a gumball machine player then it isnt: Will I win a rare? It is: How long will it take me to  win the rare (and how much will that cost me)

+

about clocker defend

clocking is when a person watches others playing a machine. If they put heaps into a machine and not win the rare/jackpot/etc and give up then the watcher/clocker swoops

this script defends against this by resetting itself when each new person plays. Each person then has the same probability as every other person of winning the rare

+

the other thing this gumball machine does is never pay out the same prize twice in a row. A person who plays only two turns/spins is guaranteed to not get the same prize both time. Which people like. Not getting the same

 

// example gummy gumball machine
// version 0.3
// Public Domain January 2015 irihapeti
//
// will give out all the gummys in the machine contents
// in some "random" order and then refill itself
// so that a player wont get 2 gummmys the same in a row
// and if they keep playing will get all the common gummys in
// best case: not less than gbM-1 turns [exactly 1 of each common
//  gummmy] and worst case: not greater than 2*gbM-3 turns
//
// for rares
//   if gbC = 3 and gbM = 5 (which incl. the rare) then rare is
//   guarantee to be given 1 in each set of 13. 3 * 4 + 1
//   altho from a players pov they more likely to play bc can get at
//   least 1 of each common in max 7 turns. 3 + 4 
//   if gbC = 4 and gbM = 5 then is still 7 for the commons. and now
//    4 * 4 + 1 = 17 for rare
//   the shortest period for rare is: 2
//   the longest period is: 1 + (gbM-1) * gbC * gbC
//   e.g: if gbM = 4 and gbC = 2 then 3 * 2 * 2 + 1 = 13 
//         | x123 123 | 123 123x |  where x = rare
//   gbM = 3. gbC = 2. 2 * 2 * 2 + 1 = 9
//         | x12 12 | 12 12x |
         
// usage: reset script after loading the gummys in machine
//        give permission for refunds
//        then just pay to play
 
// change these to whichever
integer gbP = 1;      // L$ price to play gummy gumball
integer gbC = 3;      // number of rounds in which 1 only rare will be given
string  gbN = "rare"; // name of the rare gummy
 
// internals
list    gbL;  // index list of gummys currently in play
list    gbW;  // listcopy of gummys in machine excluding rare
integer gbG;  // this gummy to give
integer gbI;  // indice of this gummy to give
integer gbJ;  // indice of this round
integer gbK;  // indice of rare round
integer gbM;  // total number of gummys in machine
integer gbQ;  // number of gummys for this round
integer gbR;  // indice of the rare gummy
key     gbY;  // key of last player

gbS() // shuffle n pick
{
    if ((++gbI) == gbQ)  // then shuffle
    { 
        if ((++gbJ) == gbC) // rounds exhausted so pick new rare round
        {
            gbK = (integer)llFrand(gbC);
            gbJ = 0;    
        }             

        integer n = llList2Integer(gbL, gbQ-1); // save last item of old list
        
	gbL = gbW;                              // get copy of commons
        if (gbJ == gbK) gbL += [gbR];           // add in rare if rare round  
        gbL = llListRandomize(gbL, 1);          // shuffle
        
	gbQ = llGetListLength(gbL);             // save length of new list
        integer m = llList2Integer(gbL, 0);     // get 1st item of new list    

        if (n == m)  // 1st of new list is same as last of old list so swap it to a later place
        {
            n = 1 + (integer)llFrand(gbQ - 1);
            gbL = [llList2Integer(gbL, n)] + llDeleteSubList(llListReplaceList(gbL, [m], n, n), 0, 0);
        }
        
	gbI = 0;  // reset the list index
    }
    
    // next gummy in list
    gbG = llList2Integer(gbL, gbI);
}

gbA()  // reset machine
{
   gbL = gbW;
   gbQ = gbM;
   gbI = gbQ-1;
   gbJ = gbC-1;    
   gbS();
}    

default
{
   state_entry()
   {
      // set machine

      gbM = llGetInventoryNumber(INVENTORY_OBJECT);
      if (gbM == 0)
      {
         llOwnerSay("is no gummys in machine");
         return;
      }

      // get gummys into list. mark the rare
      gbR = -1;
      gbW = [];
      integer i;
      for (i = 0; i < gbM; i++)
      {
         if (llGetInventoryName(INVENTORY_OBJECT, i) == gbN) 
            gbR = i;
         else
            gbW += [i];        
      }    
      if (gbR == -1)
      {
         llOwnerSay("hmm! cant find the rare: " + gbN 
            + ". check your typing ok");
         return;
      }
       
      // for refunding if SL bork
      llRequestPermissions(llGetOwner(), PERMISSION_DEBIT); 
    }
     
    run_time_permissions(integer perm)
    {
        if(perm & PERMISSION_DEBIT)
            state play;
    }
}
 
state play
{
   state_entry()
   { 
      llSetPayPrice(PAY_HIDE, [gbP, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
      llOwnerSay("gummy gumball is set to play. woohoo!");
   }

   money(key id, integer amount)
   {     
      if (amount != gbP) // shouldnt happen this but might if SL bork. is money so
      {
        if (amount > 0)
        { 
	   llGiveMoney(id, amount);
           llWhisper(0, "eep! you paid the wrong amount. "
              + "so we refund your L$" + (string)amount + " ok");
	}
        // if amount < 0 then is a serious SL serverside error like totally

        return;
      }

      // clocker defend. reset everytime is a new player
      if (id != gbY)
      {
         gbY = id;
         gbA();
      }
          
      // all good. so give gummy     
      llGiveInventory(id, llGetInventoryName(INVENTORY_OBJECT, gbG));
                
      if (gbG == gbR)  // then rare given. add bling here as you like
      {
         llWhisper(0, "woohoo! you got a rare gummy \\o/");
      }
      else // common given
      {
         llWhisper(0, "enjoy your gummy ok (:");
      }

      gbS();  // prep for next play
   }
}  

 

 

 

 

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3261 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...