Jump to content

How can I script this?


Yamil Dagger
 Share

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

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

Recommended Posts

I'm working on a script right now and I've hit a wall. I'm out of ideas on how this can be done... I have a list which is setup by a number then a key, number, key, number...etc

The number is how many chances or 'entries' they have and the key is the person's key. How can I pick a random person/key from the list giving the people with higher entries a better chance of winning? It's kinda similar to the lottery. I can't simply list repeat keys because people can buy 100+ entries so how can this be done?

Link to comment
Share on other sites

  1. Keep a total of the number of entries everyone has.
  2. Pick a random number up to this total.
  3. Scan through the list totalling 'entries so far'.
  4. Stop at the person who makes the total >= your random number.

IE: assume a list of [5, abcd, 10, efgh, 3, ijkl] - can't be bothered to type convincing keys but you get the point - Total entries is 18 (5 + 10 + 3).

Random number 2.  First entry total (0 + 5) > 2 so player 1 wins.

Random number 12.  First entry total (0 + 5) < 2.  Second entry total (0 + 5 + 10) > 12 so player 2 wins.

Random number 17.  ... Third entry total (0 + 5 + 10 + 3) > 17 so player 3 wins.

Since the random numbers you pick have an equal theoretical spread they are more likely to fall within the totals for people with more entries. [ETA: in this case 1 - 5 would pick the first player, 6 - 15 the second and 16 - 18 the third].

(You could also have a parallel list with the 'totals so far' so you don't have to calculate them each time.  Whether the extra list and list-handling is worth it is arguable though).

Link to comment
Share on other sites

make a new list from all the numbers in your main list using

http://wiki.secondlife.com/wiki/LlList2ListStrided

then sort the new list from lowest to highest using

http://wiki.secondlife.com/wiki/LlListSort

then divide the list length (-1) by 2 to get a half way point.

ex: your list length is 12 (-1 = 11).....halfway is 5

    random number between 0-11 is the index for the list.

(remember to subtract 1 from the list length..a list of 12 is indexed 0-11)

if your random number is greater than the halfway point...give the prize,

if not, roll a second time and give the prize to who ever wins?

this would make lower numbers have to roll twice?

 whatever index is used for the winning pick, get the value at

that index in your new list and compare it to the mainlist using

 llListFindList( mainlist, [winning number])  and get the key

associated with that number...

Link to comment
Share on other sites

Thought I should point out that gaming is illegal under US law, by which LL is bound, so which binds SL too.  It is therefore not legal to run lotteries or other gaming operations even if you're not in the USA nor a US citizen.  The FBI doesn't love you.  Read LL's gaming policy and consult your legal advisors.

To soften the blow I typed up this, which is the selection function.  You'll still need something that adds/removes people and their entries and maintains the TotalEntries count;

 

list Players;		// Strided 2: No. entries, Player UUIDinteger TotalEntries;default{	touch_end(integer HowMany){		if((llDetectedKey(0) == llGetOwner()) && (TotalEntries > 0)){			integer EntriesSoFar;			integer Index = -2;			integer Random = (integer) (llFrand((float) TotalEntries) + 1);			string Winner;			while(Random > EntriesSoFar){				EntriesSoFar += llList2Integer(Players, Index);				Index += 2;			}			Winner = llKey2Name(llList2Key(Players, --Index));			if("" == Winner){				Winner = "not here";			}			llSay(0, "The winner is " + Winner);		}	}}

 

Link to comment
Share on other sites

Thank for all the answers. Regarding US laws, I know them. I said this script is SIMILAR to the lottery, as in it's NOT the lottery. This is a very extremely small portion of the script I'm making and I simply used the 'lottery' idea to help clarify things.

 

Thanks again to everybody.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3935 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...