Cardinia Posted February 19, 2013 Share Posted February 19, 2013 Can anyone help me change this so an avatar may vote once per day please?. And say they must wait 24 hours to vote again if they try clicking the prim again?. string g_THANKS_MSG = "Thanks for voting";// this will be in the hover text over the primstring g_HOVER_TEXT = "Click here& Vote for me!"; // -- dont need to edit anything below here probably unless you want to change// how the message is delivered when someone votes. see: touch_start --integer g_VOTES = 0;// list of avis that votedlist g_VOTERS; // ------------------------------------------------------------------------update(){ llSetText( g_HOVER_TEXT + "\n" + (string)g_VOTES + " votes", <1,1,1>, 1.0 );} // ------------------------------------------------------------------------integer addVote( key id ){ // check memory and purge the list if we are getting full if( llGetFreeMemory() < 1000 ) { g_VOTERS = []; } // make sure they have not voted already if( llListFindList( g_VOTERS, [id] ) == -1 ) { g_VOTES++; g_VOTERS = (g_VOTERS=[]) + g_VOTERS + [id]; update(); return TRUE; } return FALSE;} // -------------------------------------------------------------------------default{ // -------------------------------------------------------------------- state_entry() { update(); } // -------------------------------------------------------------------- touch_start(integer total_number) { integer i; for( i = 0; i < total_number; i++ ) { if( addVote( llDetectedKey(i))) { if( g_THANKS_MSG != "" ) { // uncomment one and only one of these next 3 lines //llWhisper( 0, g_THANKS_MESSAGE ); //llSay( 0, g_THANKS_MSG ); llInstantMessage( llDetectedKey(i), g_THANKS_MSG ); } } } }} Link to comment Share on other sites More sharing options...
Darkie Minotaur Posted February 19, 2013 Share Posted February 19, 2013 Do you want the voters to be able to vote once a day (let's say, one ava votes on Monday at 10 p.m., then they should be able to vote again on Tuesday at 0:01 a.m.) or 24 hours after they have voted? About how many people do think would vote? Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 19, 2013 Share Posted February 19, 2013 All you need is a way to record the time when each person voted, and a way to remove voters from the list when they have been on it more than 24 hours. It should work to just make these changes ... list g_VOTERS;list gTimes;// ------------------------------------------------------------------------update(){ integer too_old = llGetUnixTime() - 86400; // This is the time exactly 24 hours ago integer i; for(i=llGetListLength(gTimes);i>=0;--i) { if (llList2Integer(gTimes,i) < too_old) //Has this person been on the list more than 1 day? { g_VOTERS = llDeleteSubList(g_VOTERS,i,i); //Remove person gTimes = llDeleteSubList(gTimes,i,i); //Remove time } } }// ------------------------------------------------------------------------addVote( key id ){ // check memory and purge the list if we are getting full // This is not really necessary, though unless you have LOADS of people each day if( llGetFreeMemory() < 1000 ) { g_VOTERS = []; } update(); // make sure they have not voted already if( llListFindList( g_VOTERS, [id] ) == -1 ) { g_VOTES++; g_VOTERS = (g_VOTERS=[]) + g_VOTERS + [id]; gTimes += [llGetUnixTime()]; llSetText( g_HOVER_TEXT + "\n" + (string)g_VOTES + " votes", <1,1,1>, 1.0 ); }} Leave the rest of the sctript alone unless you want to streamline it by removing some other unnecessary bits. EDIT: Updated, as suggested by Ron :smileywink: 1 Link to comment Share on other sites More sharing options...
Ron Khondji Posted February 19, 2013 Share Posted February 19, 2013 What would happen if I vote today, then nobody else for the next 24+ hours and then me again? In other words; it would be better to 'update()' the gVOTERS list before checking if somebody is in there. Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 19, 2013 Share Posted February 19, 2013 Good point. Updated above ^^. Link to comment Share on other sites More sharing options...
Ela Talaj Posted February 20, 2013 Share Posted February 20, 2013 There is no need to purge the list Rolig, make a circular buffer. Basically, we need to store the user id and a unix time integer so we could audit every hour or so. A circular list (buffer) could store up to 500 unique users given these conditions. Link to comment Share on other sites More sharing options...
Cardinia Posted February 20, 2013 Author Share Posted February 20, 2013 Is this compiled together already as I do not know how to script. Also by reading it I did not notice it would tell the person voting that they must wait 24 hours to vote again if they tried voting twice. Could someone please put that all together so I may copy n paste it into sl. Thank you all for your help and suggestions!. Link to comment Share on other sites More sharing options...
Rolig Loon Posted February 20, 2013 Share Posted February 20, 2013 Ela Talaj wrote: There is no need to purge the list Rolig, make a circular buffer. Basically, we need to store the user id and a unix time integer so we could audit every hour or so. A circular list (buffer) could store up to 500 unique users given these conditions. That's true. I was being lazy, though, and trying to show the OP how to get a workable result by adding no more than a few lines to the existing script. As I noted, there are other streamlining steps she should take too. We're not in the business of creating new freebie scripts on demand in this forum, though, so something has to be left for the visiting scripter to do. Link to comment Share on other sites More sharing options...
Recommended Posts
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