Second Life Copybot
Single Item Vendor with countdown timer - Printable Version

+- Second Life Copybot (https://secondlifecopybot.com)
+-- Forum: SECOND LIFE PRODUCTS (https://secondlifecopybot.com/forum-1.html)
+--- Forum: SCRIPTS (https://secondlifecopybot.com/forum-1022.html)
+---- Forum: SCRIPTS (https://secondlifecopybot.com/forum-8.html)
+----- Forum: Business Scripts (https://secondlifecopybot.com/forum-44.html)
+----- Thread: Single Item Vendor with countdown timer (/thread-637.html)



Single Item Vendor with countdown timer - steadymobbin - 02-18-2013

PHP Code:
// Items that can be updated/changed for each vendor
//-----------------------------------------------------
string StartTime "2012-7-14 12:58:00";
string EndTime   "2012-7-14 12:59:00";
integer Price    50;
string Prefix    "Limited Time Sale Item!";
string Starting  "This Sale Starts In";
string Ending    "This Sale Expires In";
string Expired   "This Sale Has Expired";
//-----------------------------------------------------

integer start;
integer expires;

integer MakeUNIXTimeinteger yearinteger monthinteger dayinteger hourinteger minuteinteger secondinteger GMToffsetinteger DST )
{
    list 
month_days = [ 0315990120151181212243273304334 ];    
    
integer time = ( year 1970 ) * 31536000;
    
time += ( day llList2Integermonth_daysmonth ) - ) * 86400;
    
time += ( hour GMToffset ) * 3600 minute 60 second;
    if ( 
DST == TRUE )
    {
        
time += -3600;
    }
    if ( 
year 1972 )
    {
        
integer past_leap_years = (integer)( ( year 1969 ) / );
        
time += past_leap_years 86400;
    }
    if ( 
year == && month )
    {
        
time += 86400;
    }
    return 
time;
}

default
{
    
state_entry()
    {
        
llSetText("Initilizing..\nWaiting for Debit Permissions from owner",<1.0,1.0,1.0>,1.0);
        
llSetPayPrice(PAY_HIDE, [PAY_HIDE ,PAY_HIDEPAY_HIDEPAY_HIDE]);
        
llRequestPermissions(llGetOwner(), PERMISSION_DEBIT);
    }
    
run_time_permissions(integer perm)
    {
        if(
perm PERMISSION_DEBIT)
            
state init;
    }
    
    
changed(integer change)
    {
        if (
change CHANGED_INVENTORY)
            
llResetScript();
    }
    
    
on_rez(integer startup_param)
    {
        
llResetScript();
    }
}
    

state init
{
    
state_entry()
    {
        if (
llGetInventoryName(INVENTORY_TEXTURE,0) != "")
            
llSetTexture(llGetInventoryName(INVENTORY_TEXTURE,0),ALL_SIDES);
        
llSetText("Initilized...",<1.0,1.0,1.0>,1.0);
        list 
templist llParseString2List(StartTime,["-"," ",":"],[]);
        
start MakeUNIXTime(llList2Integer(templist,0), llList2Integer(templist,1), llList2Integer(templist,2), llList2Integer(templist,3), llList2Integer(templist,4),llList2Integer(templist,5), -8TRUE );
        
templist llParseString2List(EndTime,["-"," ",":"],[]);
        
expires MakeUNIXTime(llList2Integer(templist,0), llList2Integer(templist,1), llList2Integer(templist,2), llList2Integer(templist,3), llList2Integer(templist,4),llList2Integer(templist,5), -8TRUE );
        
llSetTimerEvent1.0 );
    }
    
    
timer()
    {
        if (
llGetUnixTime() >= start)
        {
            
state started;
        }
        else
        {
            
integer seconds start llGetUnixTime();
            if( 
seconds )
            {
                
integer days seconds 86400;
                
integer hours = ( seconds - ( days 86400 ) ) / 3600;
                
integer minutes = ( seconds - ( days 86400 ) - ( hours 3600 ) ) / 60;
                
seconds = ( seconds - ( days 86400 ) - ( hours 3600 ) - ( minutes 60 ) );
                
string s1 " days, ";
                if( 
days == )
                {
                    
s1 " day, ";
                }
                
string s2 " hours, ";
                if ( 
hours == )
                {
                    
s2 " hour, ";
                }
                
string s3 " minutes, and ";
                if ( 
minutes == )
                {
                    
s3 " minute, and ";
                }
                
string s4 " seconds left";
                if ( 
seconds == )
                {
                    
s4 " second left";
                }
                
llSetText(Prefix "\n" llGetInventoryName(INVENTORY_OBJECT,0) + " - $" + (string)Price "L\n" Starting "\n" + (string)days s1 + (string)hours s2 + (string)minutes s3 + (string)seconds s4, <1.0,1.0,1.0>, 1.0 );
            }
        }
    }

    
changed(integer change)
    {
        if (
change CHANGED_INVENTORY)
            
llResetScript();
    }
    
    
on_rez(integer startup_param)
    {
        
llResetScript();
    }
}

state started
{
    
state_entry()
    {
        
llSetPayPrice(PAY_HIDE, [Price ,PAY_HIDEPAY_HIDEPAY_HIDE]);
        
llSetTimerEvent1.0 );
    }
    
    
timer()
    {
        
integer seconds expires llGetUnixTime();
        if( 
seconds )
        {
            
integer days seconds 86400;
            
integer hours = ( seconds - ( days 86400 ) ) / 3600;
            
integer minutes = ( seconds - ( days 86400 ) - ( hours 3600 ) ) / 60;
            
seconds = ( seconds - ( days 86400 ) - ( hours 3600 ) - ( minutes 60 ) );
            
string s1 " days, ";
            if( 
days == )
            {
                
s1 " day, ";
            }
            
string s2 " hours, ";
            if ( 
hours == )
            {
                
s2 " hour, ";
            }
            
string s3 " minutes, and ";
            if ( 
minutes == )
            {
                
s3 " minute, and ";
            }
            
string s4 " seconds left";
            if ( 
seconds == )
            {
                
s4 " second left";
            }
            
llSetText(Prefix "\n" llGetInventoryName(INVENTORY_OBJECT,0) + " - $" + (string)Price "L\n" +  Ending "\n" + (string)days s1 + (string)hours s2 + (string)minutes s3 + (string)seconds s4, <1.0,1.0,1.0>, 1.0 );
        }
        else
        {
            
state expired;
        }
    }

    
money(key idinteger amount)
    {
         if(
amount != Price)
         {
            
llGiveMoney(idamount);
            
llInstantMessage(id"The amount you paid: " + (string) amount "L$ , The correct price: " + (string)Price);
        }
        else
        {
            
llGiveInventory(idllGetInventoryName(INVENTORY_OBJECT,0));

        }
    }

    
changed(integer change)
    {
        if (
change CHANGED_INVENTORY)
            
llResetScript();
    }
    
    
on_rez(integer startup_param)
    {
        
llResetScript();
    }
}
            
state expired
{
    
state_entry()
    {
        
llSetPayPrice(PAY_HIDE, [PAY_HIDE ,PAY_HIDEPAY_HIDEPAY_HIDE]);
        
llSetText(Prefix "\n" llGetInventoryName(INVENTORY_OBJECT,0) + " - $" + (string)Price "L\n" Expired, <1.0,1.0,1.0>, 1.0 );
    }

    
changed(integer change)
    {
        if (
change CHANGED_INVENTORY)
            
llResetScript();
    }
    
    
on_rez(integer startup_param)
    {
        
llResetScript();
    }