Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need some help with a prim counting script

Dakota Callahan
Feisty Irish Lass
Join date: 21 Jul 2004
Posts: 783
04-03-2007 21:30
I'm trying to create an object that my renters can click on to tell them how many prims they're using (so they aren't always IM'ing me or my partner). The information in the various wikis is pretty sparse, and in some cases contradictory, so I'm hoping someone here might have a clue how to make this work.

CODE

// Parcel Prim Counter
// created by Dakota Callahan
// v.1.0 - 070317 - initial release

default
{
state_entry()
{
}

touch_start(integer total_number)
{
integer i;

llSay( 0, "Touched." );

key toucher = llDetectedKey( 0 );

list primList = llGetParcelPrimOwners( llGetPos() );

integer len = llGetListLength( primList );

if( len > 0 )
{

for( i = 0; i < len; i += 2 )
{
if( toucher == llList2Key( primList, i ) )
{
if( llList2Integer( primList, i + 1 ) > 0 )
{
llSay( 0, llKey2Name( llList2Key( primList, i ) ) + " you have " +
llList2String( primList, i + 1 ) + " prims in use on this parcel." );
}
else
{
llSay( 0, llKey2Name( llList2Key( primList, i ) ) +
" you have no prims on this parcel." );
}
}
}
}
}
}


Now this works just fine when I touch it, or when anyone else does. But it stops working after a while for reasons I can't understand. I've tried making the object group owned, deeding it to the group, even giving a copy to each renter, works fine for a while and then just stops.

Any comments or suggestions gratefully accepted before I start pulling out my prim hair :)
_____________________
Life is a Carnival

"...
every broken teleport makes a baby hippo cry." - Altruima Linden

"We're all pro wrestlers in the ring of Second Life." - Torley Linden

Dakota Callahan Designs
Callahans Isle (2,128, 502)

Epilort Byrne
Registered User
Join date: 6 Jul 2004
Posts: 30
04-03-2007 21:42
Have a look at this page .
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
04-04-2007 00:58
Instead of looping through the list you may want to use llListFindList to look for the UUID.

This will be much faster than the loop and put less strain on the sim.


Always try to use built-in functions instead of your own code. It WILL be much faster. And MUCH easier as well ^^
Flater Baxter
Registered User
Join date: 23 May 2007
Posts: 48
09-22-2007 06:00
key toucher;
integer z;
integer k;
list primList;

default
{
state_entry()
{
}

touch_start(integer total_number)
{


//llSay( 0, "Touched." );
for(z=0;z<total_number;z++)
toucher = llDetectedKey( z );

primList = llGetParcelPrimOwners( llGetPos() );

integer len = llGetListLength( primList );

if( len > 0 )
{
k = llListFindList(primList,[toucher]);
if (k != -1){


llSay( 0, llKey2Name( llList2Key( primList, k ) ) + " you have " +
llList2String( primList, k + 1 ) + " prims in use on this parcel." );
}
else
{
llSay( 0, llKey2Name( llList2Key( primList, k ) ) +
" you have no prims on this parcel." );
}
}
}
}
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
09-22-2007 06:44
From: Dakota Callahan
Now this works just fine when I touch it, or when anyone else does. But it stops working after a while for reasons I can't understand. I've tried making the object group owned, deeding it to the group, even giving a copy to each renter, works fine for a while and then just stops.

Any comments or suggestions gratefully accepted before I start pulling out my prim hair :)
There's some mystique about llGetParcelPrimOwners(). For non-group-owned land, I think the land owner must be in-world (or in-sim?) for the function to work. For group-owned land, you've tried what has always seemed to work for me: deeding the scripted object to group--but others have reported less success (see ); perhaps my alts just never waited long enough for it to fail.
Flater Baxter
Registered User
Join date: 23 May 2007
Posts: 48
09-22-2007 08:14
On wiki it say's:

The object must be owned by the land owner or if the land is owned by a group then it must be deeded to the group or owned by a group officer (or similar rank).

but if it fails when the object is not deeded to group(group owened parcel)
when the owner is not online... is some cases it wil make this function useless.

can we then scan for objects, using a sensor ... i made a little script ... but ofcourse it's not doing what i want it to do... This is the first time i used a sensor, never needed one b4.

it scans for objects of a owner .. makes a list of it, and counts the prims.

it does 3 scans, SCRIPTED, ACTIVE and PASSIVE,


a scanner scans 16 objects per scan ... my scan result gave me 30 objects, Not good enough..so that means its scanning the same objects ..
if this this true then is there away to exclude objects from the scan, or must the scanner move around, or is what i want not possible?

Thanks

===================================
===================================
key object;
key detail;
key owner;
list objects;
key toucher;
integer nr;
integer primcount;
integer prims=1;
integer handle3;
integer mchan;
list menu =["COUNT","OBJECTS"];
integer time = 0;

check()
{
nr = llGetListLength(objects);
integer a;
primcount = 0;
integer obcount = 0;
for(a=0;a<nr;a++){
obcount = llGetObjectPrimCount(llList2String(objects,a));
primcount = primcount +obcount;

}
}

say()
{
nr = llGetListLength(objects);
integer a;
string tempname2;
integer tempcount;
primcount = 0;
integer obcount = 0;
for(a=0;a<nr;a++){
tempname2 = llKey2Name(llList2String(objects,a));
tempcount =llGetObjectPrimCount(llList2String(objects,a));
llSay(0,"Object: "+tempname2+" prims: "+(string)tempcount);

}



}


default
{
state_entry()
{


}

touch_start(integer total_number)
{
integer x;
for(x=0;x<total_number;x++){
toucher = llDetectedKey(x);
llListenRemove(handle3);
mchan = llFloor(llFrand(9999.1000));
handle3=llListen(mchan,"",toucher,"";);
llDialog(toucher,"MENU",menu,mchan);

}


}

sensor(integer total_number)
{
integer i;
for (i = 0; i < total_number; i++)
{
object = llDetectedKey(i);
detail =llGetOwnerKey(object);
if(detail == toucher)
{
if( llListFindList(objects,[object])== -1) objects =(objects = [])+objects+[object];
}

}
}
listen(integer channel, string name, key id, string message) {
if (message == "COUNT";) {
llSay(0,"Scanning";);
objects=[];llSensorRepeat("", NULL_KEY, PASSIVE, 96.0, PI,.1);
llSetTimerEvent(5);}
if (message == "OBJECTS";){
say();

}

}
timer()
{
time += 1;
if (time==1) {
llSensorRemove();
llSensorRepeat("", NULL_KEY, ACTIVE, 96.0, PI,.1);
}
if (time==2) {llSensorRemove();llSensorRepeat("", NULL_KEY, SCRIPTED, 96.0, PI,.1);}
if (time==3) {llSensorRemove();
check();
llSay(0,"You got "+(string)nr+" objects";);
llSay(0,"You got "+(string)primcount+" prims";);
llSetTimerEvent(0);
time=0;
}


}

}
===================================
===================================