Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

giving one freebie a day

Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
03-28-2009 02:07
Hi

is there a snippet to add to 'giveinventory' scripts that stops people taking more than one free gift a day

its nice to give away things like you guys give away your time and skillz here :) ;)

but i find it annoying when people take advantage of your generosity and take say 10 of something - is there a way to control this so they click one time in 24 hrs they get a gift

and a thank you then if they try again they get a message saying sorry you have already received this gift

i am sure this would be very popular in sl for freebie people
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
03-28-2009 02:54
It is easy to limit it to one a day if that is it.
If it is one a day per avatar it gets a little more tricky: you have to register each avatar, that had one and keep the registration for 24 hours
Here is a script for the simple case:
CODE

default
{
touch_start(integer n)
{
integer i;
list items = [];
integer x = llGetInventoryNumber(INVENTORY_ALL);
do {
string name = llGetInventoryName(INVENTORY_ALL, x);
if (name != llGetScriptName()) items += [name];
} while (--x >= 0);
for( i=0; i<n; i++) llGiveInventoryList(llDetectedKey(i), llGetObjectName(), items);
state closed;
}
}

state closed
{
state_entry()
{
llSetTimerEvent( 86400.0 );
}

timer()
{
llSetTimerEvent( 0.0 );
state default;
}
}
Happy Scripting:)
_____________________
From Studio Dora
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-28-2009 09:31
and here's the more complex case
CODE

float gFltTimeoutPeriod = 86400; //-- 1 day in seconds
float gFltCleanupRate = 3600; //-- 1 hour in seconds
integer gIntMaxStorage = 160;

list gLstAvatars;
list gLstTimeout;
integer gIntIndex;

default{
state_entry(){
llSetTimerEvent( gFltCleanupRate );
gIntMaxStorage -= 1;
}

touch_start( integer vIntTouched ){
@Loop;{
list vLstTest = (list)llDetectedKey( --vIntTouched );

if (!~llListFindList( gLstAvatars, vLstTest )){
gLstAvatars = vLstTest
+ llList2List( (gLstAvatars = []) + gLstAvatars, 0, gIntMaxStorage );
gLstTimeout = (list)(llGetTime() + gFltTimeoutPeriod)
+ llList2List( (gLstTimeout = []) + gLstTimeout, 0, gIntMaxStorage );
//-- do other stuff --//
}
}if (vIntTouched) jump Loop;
}

timer(){
if (gIntIndex = llGetListLength( gLstTimeout )){
float vFltNow = llGetTime();

@Loop;
if (llList2Float( gLstTimeout, --gIntIndex ) < vFltNow){
if (gIntIndex){
jump Loop;
}else{
gLstAvatars = [];
gLstTimeout = [];
}
}
gLstAvatars = llList2List( (gLstAvatars = []) + gLstAvatars, 0, gIntIndex );
gLstTimeout = llList2List( (gLstTimeout = []) + gLstTimeout, 0, gIntIndex );
}
}
}

this is a pre-mono script that I just pulled from my av's inventory today to archive. you can probably change gIntMaxStorage to a much bigger number if it'll compile in mono.... the memory optimization hacks (lis=[])+ aren't needed in mono, but shouldn't hurt it much. (note you still need to add the give function, this is just a limit on touches per av, per time period)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
03-28-2009 10:31
I was wondering about the more complex case. It's lazy, I know, but why not just clear the list every 24 hours?

Limiting it to gift per av in a 24 hour period, as opposed to making each av wait 24 hours for the next gift, amounts to much the same thing, and is probably a bit more convenient for most people.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-28-2009 10:50
From: Innula Zenovka
I was wondering about the more complex case. It's lazy, I know, but why not just clear the list every 24 hours?

Limiting it to gift per av in a 24 hour period, as opposed to making each av wait 24 hours for the next gift, amounts to much the same thing, and is probably a bit more convenient for most people.

well if you clear the list every 24hrs, then the person who showed up just before the clearing gets a second shot right after (presuming you just wipe the list completely) or the person that showed up just after has to wait an extra day (presuming you do a holdover list)

doing it hourly (which can be configured for different frequencies) means at worse 25 hours wait, and at best 24, regardless when they clicked.

it was set up for multi-purpose use, and mostly as concept, in practice, tracking av's and clearing the list / period is probably just as effective in most cases.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
03-29-2009 01:14
thanks thats great and looks good

i particularly like the

---
and here's the more complex case
CODE

float gFltTimeoutPeriod = 86400; //-- 1 day in seconds
float gFltCleanupRate = 3600; //-- 1 hour in seconds
integer gIntMaxStorage = 160; .....
---
version


where in that could i have a message that says - "sorry you have already received your gift"

as it would have to check if that particular av had already received it rather than just a generic message as that would appear on every click

also i am interested in this for particular days only

like for example if i want to give away a free gift on a rez day or summit but not the days before or the days after - could be a lot of fun :)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-29-2009 01:48
From: Junglejim Jonson
thanks thats great and looks good

i particularly like the

---
and here's the more complex case
CODE

float gFltTimeoutPeriod = 86400; //-- 1 day in seconds
float gFltCleanupRate = 3600; //-- 1 hour in seconds
integer gIntMaxStorage = 160; .....
---
version


where in that could i have a message that says - "sorry you have already received your gift"

as it would have to check if that particular av had already received it rather than just a generic message as that would appear on every click

also i am interested in this for particular days only

like for example if i want to give away a free gift on a rez day or summit but not the days before or the days after - could be a lot of fun :)

you can use the simplified clear list every x hours, and still use the customized messages

for the "special days" you'd need to get the current month/day and compare it to your special day. there's a few examples of day of the week/month/year scripts on the forums if you search
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
03-29-2009 03:24
thanks i just was not sure where to put the - "you already have one" in the list


where would i put the 'say line' on the more complex script above so its only said to the person who has already had one and not to everybody who clicks it

thanks :)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-29-2009 03:55
the simplified example would look more like
CODE

list gLstGiftees;

default{
state_entry(){
llSetTimerEvent( 24 * 60 * 60 );
}

touch_start( integer vIntTouchers ){
string vStrName
Do{
vKeyAv = llDetectedName( --vIntTouchers );
if (~llListFindList( gLstGiftees, (list)vKeyAv){
llInstantMessage( vKeyAv, "You got one already today" );
}else{
gLstGiftees += (list)vKeyAv;
//-- give stuff away
}
}while (vIntTouchers);
}

timer(){
gLstGiftees = [];
}
}

in my previous example you'd just add an else to the "if (~" statment in the touch event to handle your scolding message, line before the jump statment
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Junglejim Jonson
Registered User
Join date: 4 Feb 2008
Posts: 52
03-30-2009 00:43
this one doesnt compile

syntax error on the Do line :)

touch_start( integer vIntTouchers ){
string vStrName
<<<>>>Do{



i tried putting in the warning line in the more complex script as you suggested but it triggers when they do the first click - unless i have missed something

so they get the 'you have one already' message on the first click and then on clicks after ideally i want the message only if they have had one - so not on the first click :)))
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-30-2009 05:21
missing semicolon after vStrName on the line before 'Do' (which may need to be 'do' )

this would be why I have a typo warning in my sig
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -