Jump to content

Collision Counter?


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

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

Recommended Posts

Hellos, would any one happen to know what I should be looking at to create this sort of thing. Im trying to make an object that when collided with keeps track of who hit it and how many times and then displays a top 3 or 5 or whatever above it of those with the highest count. I dont know what this would be called and ive turned up pretty much nothing in my search. I do know its possible to store a collection of avatars upto 500 (welcome mats) and that they can remove the oldest entry to make more room. How they do it, that I dont know...

Any help would be appreciated. Thank you for taking the time to read my post.

Link to comment
Share on other sites

Start with any standard visitor counter.  You'll want to use a collision_start event as the trigger rather than a sensor, but the mechanism is the same.  The rest of it is basiucally a matter of maintaining a list of visitors, checking each time someone on the visitor list trips the detector again, and maintaining a separate list of those repeat visitors and their counts.  When your visitor list gets too long, start removing the oldest entry each time a new one is added -- perhaps preserving repeaters.

Link to comment
Share on other sites

hehe sounds easy enough but that is a good bit above my scripting skills, so far ive managed to clip this together. Still has some extra bits of code that arnt needed but its no worry at the moment. It detects unique avatar collisions and adds it to the count BUT it doesnt add anymore to the total if they try again. Now to figure out how to get it to keep count for each avatar seperately and display their total. Woooooo complicated stuff >.<

 

// Global variables
list visitor_list;

// Functions
integer isNameOnList( string name )
{
    integer len = llGetListLength( visitor_list );
    integer i;
    for( i = 0; i < len; i++ )
    {
        if( llList2String(visitor_list, i) == name )
        {
            return TRUE;
        }
    }
    return FALSE;
}
 
// States
default
{
    state_entry()
    {
        llSay(0, "Visitor List Maker started...");
        llSay(0, "The owner can say 'help' for instructions.");
        llListen(0, "", llGetOwner(), "");
    }  
    collision_start(integer number_detected)
    {
        integer i;
        for( i = 0; i < number_detected; i++ )
        {
            if( llDetectedKey( i ) != llGetOwner() )
            {
                string detected_name = llDetectedName( i );
                if( isNameOnList( detected_name ) == FALSE )
                {
                    visitor_list += detected_name;
                }
                {
                llSetText((string)(++i),<1.0,1.0,1.0>,1.0);
               }
            }
        }    
    }
    
    listen( integer channel, string name, key id, string message )
    {
        if( id != llGetOwner() )
        {
            return;
        }
        
        if( message == "help" )
        {
            llSay( 0, "This object records the names of everyone who" );
            //llSay( 0, "comes within "+ (string)range + " meters." );
            llSay( 0, "Commands the owner can say:" );
            llSay( 0, "'help'  - Shows these instructions." );
            llSay( 0, "'say list'   - Says the names of all visitors on the list.");
            llSay( 0, "'reset list' - Removes all the names from the list." );
        }
        else
        if( message == "say list" )
        {
            llSay( 0, "Visitor List:" );
            integer len = llGetListLength( visitor_list );
            integer i;
            for( i = 0; i < len; i++ )
            {
                llSay( 0, llList2String(visitor_list, i) );
            }
            llSay( 0, "Total = " + (string)len );
        }
        else
        if( message == "reset list" )
        {
            visitor_list = llDeleteSubList(visitor_list, 0, llGetListLength(visitor_list));
            llSay( 0, "Done resetting.");
        }
    }        
}

Link to comment
Share on other sites

Not a bad start at all.  Now, you have a way to add visitors to the visitor_list if they are new.  To get on with the next part of your project, you need to figure out what to do with visitors who are not new ---  the repeaters.  As you collect them, you'll need to find a way to keep track of how many times each one has repeated.  I'd suggest familiarizing yourself with strided lists and with the function llListReplaceList. If you choose not to use a strided list, you can accomplish the same thing with a pair of non-strided lists: one for UUIDs or names and the other for your counts.

Incidentally, you don't need to use that somewhat cumbersome IsNameOnList function.  Basically, all it is asking can be summed up in the single call

if ( ~llListFindList(visitor_list,[llDetectedKey(i)]) )  or, if you want to see if the avatar is NOT on the list

if ( !~llListFindList(visitor_list,[llDetectedKey(i)]) )

Link to comment
Share on other sites

Does this look better or worse? I removed what I thought was redundant but ended up with it no longer working, compiles but does nothing >.< Im not sure if the code above it is doing the same thing its doing or not. Maybe I shouldnt try this early in the morning or late at night...

 

list visitor_list;

default
{
    state_entry()
    {
    }  
    collision_start(integer number_detected)
    {
        integer i;
        for( i = 0; i < number_detected; i++ )
        {
            if( llDetectedKey( i ) != llGetOwner() )
            {
                string detected_name = llDetectedName( i );
                }
            if ( ~llListFindList(visitor_list,[llDetectedKey(i)]) )  //or, if you want to see if the avatar is NOT on the list
            if ( !~llListFindList(visitor_list,[llDetectedKey(i)]) )
                {
                llSetText((string)(++i),<1.0,1.0,1.0>,1.0);
               }
            }
        }    
    }

Link to comment
Share on other sites

OK, time to step back and think this through.  Map out the logic of what you're trying to do and take a good look at what you wrote to see if it makes sense.  Don't get blinded by syntax.  Just pay attention to logic.  In particular, why would you include both if tests, and exactly what are you tryting to accomplish with them? If .... then what?

Link to comment
Share on other sites

Don't give up yet.  This is not a difficult challenge, but you do need to have a clear idea of what you are trying to do.  Map it out on paper so that you see it in steps and know where you have to have the script make decisions.  Then work on one part of the problem at a time.  You already have the basic skeleton done, so that it works as a greeter.  Aside from polishing syntax, the only real logical challenge is figuring out how to identify and save information about repeaters.  When you have a logical plan, look at the two hints I suggested earlier.

Link to comment
Share on other sites

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