Jump to content

Vote Script Help?.


Cardinia
 Share

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

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

Recommended Posts

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 prim
string 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 voted
list 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

 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:

  • Like 1
Link to comment
Share on other sites

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


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

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