Jump to content
  • 0

i need help for a vote system split money for 3 winners in percentage 20% 30% 50%


Daffy Proto
 Share

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

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

Question

hi i have a vote system script (contest board) and i need some help how to split in 3 different rates for 20% 30% 50% money percentage in 3 winners (1st,2nd,3rd place)...i allready have a script but works for only one winner (CalculateWinner(integer prize)....

any ideas how to change that?

//contestants hnaddling scripts

// link messages -----------------
integer DISPLAY_STRING = 204000; 
integer VOTING_TYPE = 301;
integer STATE_CONTEST = 400;
integer STATE_WAITING = 401;
integer STATE_CLOSED = 402;
integer STATE_WAITING_PERMS = 403;

integer ADD_CONTESTANT = 501;
integer SET_COMMAND_CHANNEL = 160;
integer NEW_VOTE_MESSAGE = 200;
integer ADD_VOTE_MESSAGE = 210;
integer REMOVE_CONTESTANT = 502;
integer VOTE_FOR_CONTESTANT = 503;
integer MANAGE_CONTESTANT = 505;
integer CONTESTANT_ADDED = 511;
integer CONTESTANT_REMOVED = 512;
integer CONTESTANT_WAS_VOTED = 513;
integer RENDER_BOARD = 601;
integer ANNOUNCE_WINNER = 602;
integer WINNER_ANNOUNCED = 603;
integer SHOW_STATS = 604;
integer PERMS_GRANTED = 620;
integer NEW_STATS = 630;
integer SEND_STAT = 631;
integer SHOW_STAT = 632;

// -------------------------------

integer COMMAND_CHANNEL = 0;

list CONTESTANT_KEY = [];
list CONTESTANT_NAME = [];
list CONTESTANT_VOTE = [];

integer MAX_CONTESTANTS = 0;
integer NEW_PAGE_NEEDED=FALSE;
key TO_BE_REMOVED = NULL_KEY;
string TO_BE_REMOVED_NAME = "";

integer COMMAND_HANDLE=0; 

ShowContestStats()
{
integer i;


llMessageLinked(LINK_THIS,NEW_STATS,"\nCONTEST STATISTICS======================================\nContestants:"+(string)(CONTESTANT_KEY!=[])+"\n",NULL_KEY);

for(i=0;i<(CONTESTANT_KEY!=[]);i++)
{
llMessageLinked(LINK_THIS,SEND_STAT,llList2String(CONTESTANT_NAME,i) + " has " + llList2String(CONTESTANT_VOTE,i) + " votes\n",NULL_KEY);
}
llMessageLinked(LINK_THIS,SHOW_STAT,"",NULL_KEY);
} 

CalculateWinner(integer prize)
{
integer i;
integer votes;
integer max=-1;
list UUID=[];

for(i=0;i<(CONTESTANT_VOTE!=[]);i++)
{
votes=llList2Integer(CONTESTANT_VOTE,i);
if(votes>0 && votes > max)
{
// new high score
max = votes;
// wipe the UUID list
UUID=[];
UUID+=llList2Key(CONTESTANT_KEY,i); 
}
else if(votes==max)
{
// a tied lead
// add this person to the winner list
UUID+=llList2Key(CONTESTANT_KEY,i); 
}
} 

if((UUID!=[])==0)
{
llSay(0,"There were no votes placed, a winner cannot be announced!");
return; 
}


llSay(0,"Congratulations!!!");
if((UUID!=[])>1)
{
integer split = prize / (UUID!=[]); 
llSay(0,"There are " + (string)(UUID!=[]) + " winners, that win " + (string)split + "L$ each!");
integer j;
for(j=0;j<(UUID!=[]);j++)
{
llShout(0,llKey2Name(llList2Key(UUID,j)) + " is a winner!");
llGiveMoney(llList2Key(UUID,j),split); 
}
}else{
llShout(0,llKey2Name(llList2Key(UUID,0)) + " is the winner!");
llGiveMoney(llList2Key(UUID,0),prize); 
} 
llMessageLinked(LINK_THIS,WINNER_ANNOUNCED,"",NULL_KEY); 
}

integer AddContestant(string contestantName, key contestantID)
{
// is contestant already enetered?
if(llListFindList(CONTESTANT_KEY,[contestantID])!=-1)
{
llSay(0,contestantName + ", you are already entered into this contest!");
return FALSE; 
}
// max reached already?
if(MAX_CONTESTANTS>0 && (CONTESTANT_KEY!=[])==MAX_CONTESTANTS)
{
llSay(0,"Sorry " + contestantName + ", the maximum allowed number of contestants has been reached. You cannot enter."); 
return FALSE; 
} 
// New page needed?
if((CONTESTANT_KEY!=[])>0 && (CONTESTANT_KEY!=[]) % 5 ==0)
{
NEW_PAGE_NEEDED=TRUE;
}else{
NEW_PAGE_NEEDED=FALSE;
} 
CONTESTANT_KEY += contestantID;
CONTESTANT_NAME += llGetSubString(contestantName,0,19); 
CONTESTANT_VOTE += 0;
return TRUE; 
}

integer RemoveContestant()
{
// string name;
integer index;
index=llListFindList(CONTESTANT_KEY,[TO_BE_REMOVED]);
// name=llList2String(CONTESTANT_NAME,index);
if(index!=-1)
{
// remove contestant from the lists
CONTESTANT_KEY = llDeleteSubList(CONTESTANT_KEY,index,index);
CONTESTANT_NAME = llDeleteSubList(CONTESTANT_NAME,index,index);
CONTESTANT_VOTE = llDeleteSubList(CONTESTANT_VOTE,index,index);
llSay(0,"Contestant " + TO_BE_REMOVED_NAME + " has been removed from the contest.");
TO_BE_REMOVED=NULL_KEY;
return TRUE;
}
else
{
TO_BE_REMOVED=NULL_KEY;
llSay(0,"Contestant " + TO_BE_REMOVED_NAME + " was not found, check the name spelling again."); 
return FALSE;

}

}

integer VoteForContestant(key voterID, key contestantID)
{
// find the position in the contestant key list
// and increase the value in the vote list at that position.
integer index = llListFindList(CONTESTANT_KEY,[contestantID]);
if(index!=-1) 
{
integer value = llList2Integer(CONTESTANT_VOTE,index);
value++;
// replace the updated value into the list
CONTESTANT_VOTE = llListReplaceList(CONTESTANT_VOTE,[value],index,index);
llInstantMessage(voterID,"Thankyou, your vote for " + llKey2Name(contestantID) + " was registered.");
}
return TRUE;
}

default
{
state_entry()
{
}

link_message(integer sender_num, integer num, string str, key id)
{


if(num==SET_COMMAND_CHANNEL)
COMMAND_CHANNEL=(integer)str;
if(num==STATE_CONTEST)
state contest;
if(num==STATE_WAITING)
{
// str has been set as an integer value where the value is the maximum number of entrants allowed.
MAX_CONTESTANTS = (integer) str;
state waiting;
}
if(num==STATE_CLOSED)
state closed;
if(num==STATE_WAITING_PERMS)
{
state waiting_perms; 
}
}

on_rez(integer param) {
llResetScript();
}

changed(integer change) {
if (change & CHANGED_INVENTORY) {
llResetScript(); 
}
}
}

state waiting_perms
{
state_entry()
{
if (llGetPermissions() & PERMISSION_DEBIT)
llMessageLinked(LINK_THIS,PERMS_GRANTED,"",NULL_KEY);
else
{
llOwnerSay("Requesting owner debit permissions...");
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
} 
} 

run_time_permissions(integer perm) {
if (perm & PERMISSION_DEBIT) {
// We got permission to pay, start up
llMessageLinked(LINK_THIS,PERMS_GRANTED,"",NULL_KEY);
}else{
llOwnerSay("*** You must grant debit permissions for this device to work ***");
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT); 
}
} 

link_message(integer sender_num, integer num, string str, key id)
{
if(num==STATE_WAITING)
{
// str has been set as an integer value where the value is the maximum number of entrants allowed.
MAX_CONTESTANTS = (integer) str;
state waiting;
}
}

on_rez(integer param) {
llResetScript();
}

changed(integer change) {
if (change & CHANGED_INVENTORY) {
llResetScript(); 
}
}
}

state waiting
{
state_entry()
{
TO_BE_REMOVED=NULL_KEY;
CONTESTANT_KEY = [];
CONTESTANT_NAME = [];
CONTESTANT_VOTE = [];

llSay(0,"Contestant functions ready.");
}

link_message(integer sender_num, integer num, string str, key id)
{
if(num==STATE_CONTEST)
state contest;
if(num==STATE_CLOSED)
state closed;
if(num==SET_COMMAND_CHANNEL)
COMMAND_CHANNEL=(integer)str;
}

on_rez(integer param) {
llResetScript();
}

changed(integer change) {
if (change & CHANGED_INVENTORY) {
llResetScript(); 
}
}
}

state contest
{
state_entry()
{

}

link_message(integer sender_num, integer num, string str, key id)
{
if(num==STATE_WAITING)
state waiting;
if(num==STATE_CLOSED)
state closed;

if(num==ADD_CONTESTANT)
{
if(AddContestant(str,id))
llMessageLinked(LINK_THIS,CONTESTANT_ADDED,(string)NEW_PAGE_NEEDED,id); 
}


// sent from the main script when the host clicks on a contestant name
if(num==MANAGE_CONTESTANT)
{
// str=HOST ID, id=CONTESTANT ID
// popup a dialog for the host with options:
// Remove contestant
// Vote for contestant

// get the name from the ID of the contestant:
integer index = llListFindList(CONTESTANT_KEY,[id]);
TO_BE_REMOVED_NAME = llList2String(CONTESTANT_NAME,index);
TO_BE_REMOVED=id;
COMMAND_HANDLE = llListen(COMMAND_CHANNEL,"",llGetObjectDesc(),"");
llDialog((key)str,"Manage Contestant " + TO_BE_REMOVED_NAME,["REMOVE","VOTE FOR"],COMMAND_CHANNEL);
}

// sent from the Voters script...
if(num==VOTE_FOR_CONTESTANT)
{
if(VoteForContestant(str,id))
llMessageLinked(LINK_THIS,CONTESTANT_WAS_VOTED,str,id);


}


// str contains the page number to render
if(num==RENDER_BOARD)
{
integer CURPAGE = (integer)str;
integer i;
for(i=0;i<5 ;i++)
{
if(i<(CONTESTANT_KEY!=[]))
{
// set the text for this row
llMessageLinked(LINK_THIS,DISPLAY_STRING,llList2String(CONTESTANT_NAME,i+(CURPAGE*5)),(string)(i+2));
// set the UUID of the contestant for this row
llMessageLinked(LINK_SET,201+i,"",llList2Key(CONTESTANT_KEY,i+(CURPAGE*5)));
}
else
{
llMessageLinked(LINK_THIS,DISPLAY_STRING,"",(string)(i+2));
// set the UUID of the contestant for this row
llMessageLinked(LINK_SET,201+i,"",NULL_KEY);
}
}
} 

if(num==ANNOUNCE_WINNER)
{
// str = integer value of prize
if((CONTESTANT_KEY!=[])>0)
{

CalculateWinner((integer)str);
}
else
{
llSay(0,"There are no contestants, a winner cannot be announced.");
} 
}

if(num==SHOW_STATS)
{
ShowContestStats();
}
} 

// COMMANDS FROM DIALOG CONTROL PANEL
listen(integer channel, string name, key id, string message)
{
llListenRemove(COMMAND_HANDLE);
if(message=="REMOVE")
{
if(RemoveContestant())
{
// back to main script
llMessageLinked(LINK_THIS,CONTESTANT_REMOVED,(string)(CONTESTANT_KEY!=[]),NULL_KEY); 
}
}
else if(message=="VOTE FOR")
{
// dispatch off to voting script
llMessageLinked(LINK_THIS,ADD_VOTE_MESSAGE,llGetObjectDesc(),TO_BE_REMOVED); 
} 
}

on_rez(integer param) {
llResetScript();
}

changed(integer change) {
if (change & CHANGED_INVENTORY) {
llResetScript(); 
}
}
}

state closed
{

state_entry()
{

}

link_message(integer sender_num, integer num, string str, key id)
{
if(num==STATE_CONTEST)
state contest;
if(num==STATE_WAITING)
state waiting;
}

on_rez(integer param) {
llResetScript();
}

changed(integer change) {
if (change & CHANGED_INVENTORY) {
llResetScript(); 
}
}
}

 

 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Questions like this belong in the LSL Scripting forum, not in Answers.  If you had posted it there, however, I would have pointed you to a script in the LSL Scripting Library that you should be able to borrow from for your needs >>> http://community.secondlife.com/t5/LSL-Library/Split-Payment-Vendor/td-p/722093 .  As you read through that thread, you'll find that several people have offered suggested variations on the original script.  Some of those may give you ideas.  If you have other scripting questions as you move along in the project, I suggest asking them in the LSL Scripting forum.

Good luck! :smileywink:

 

  • Like 1
Link to comment
Share on other sites

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