Jump to content

Random Rezzer Game


Surprised Cerise
 Share

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

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

Recommended Posts

Hello, im actually using this free script and i want to modify it so, if some person reaches xx points an event should trigger, just like "you got 10 points".

but i cant figure out which variables i have to "if" for

 

// :CATEGORY:Games
// :NAME:Random Rezzer Game
// :AUTHOR:Anonymous
// :CREATED:2013-09-06
// :EDITED:2013-09-18 15:39:00
// :ID:675
// :NUM:918
// :REV:1
// :WORLD:Second Life
// :DESCRIPTION:
// random game
// :CODE:

integer GIVE = TRUE; // if TRUE, give them a random prize

integer channel = -1234321; // some random integer rto talk with
integer maxCount = 100;  // Only keep the 100 top scores so we do not run out of RAM
list scores;// a list of scores (integers like 1,1,23, and avatar names. Wr number is first so we can sort on it for high scores.

default
{
    on_rez(integer start_param)
    {
        llResetScript();    // when you rez it, we have to start a listener
    }
    
    state_entry()
    {
        llListen(channel,"","","");    // listen on our secret channel for things that are touched.
    }

    listen(integer channel, string name, key id, string message)
    {

        list stuff = llParseString2List(message,["^"],[]); // look in message for aviName^aviKey
        string aviName = llList2String(stuff,0);         // get the name
        key aviKey = (key) llList2String(stuff,1);    // get the key
        llSay(0, "Prim " + name +  " caught by : " + aviName);

        // lets see of this person is in the list of people already played
        integer index = llListFindList(scores,[aviName]);  // get the number of the position of the name, the score is one less than this
        if (index  == -1)
        {
            // Nope, so we add them to the list
            scores += 1;    // they have one object;
            scores += aviName;
            llOwnerSay("Welcome, " + aviName + " .  This you your first time to play, so just keep watching for and clicking the objects and have fun");
        }
        else
        {
            // yes, they have played before, get their old score
            integer oldscore = llList2Integer(scores,index-1);
            oldscore++;        // add an object to the old score
            scores = llListReplaceList(scores,[oldscore],index-1, index-1);    // save it back in the score list
        }

        if (GIVE)
        {
            integer PrizeNum = llGetInventoryNumber(INVENTORY_OBJECT);    // get how many items are in this prim
            integer whichOne = llCeil(llFrand(PrizeNum)) -1 ;  //pick a prize, randomly
            llGiveInventory(aviKey, llGetInventoryName(INVENTORY_OBJECT,whichOne));
        }

        

        scores = llListSort(scores,2,FALSE); //sort from largest num to lowest

        scores = llDeleteSubList(scores, maxCount, maxCount+1); // delete the smallest score so we never get bigger than maxCount

        string scoreText;    // We need to calculate the highest scores for display
        integer i ;
        integer stop = 10;    // show top 10 scores
        if (llGetListLength(scores) < 10)    // is the list bigger than 10 yet?
        {
            stop = llGetListLength(scores);
        }

        // print out the top 10 scores, or fewer
        for (i = 0; i < stop; i+= 2)
        {
            scoreText += llList2String(scores,i+1) + " : " + (string) llList2String(scores, i) + "\n";
        }
        llSetText(scoreText,<1,1,1>,1.0);
        llOwnerSay(scoreText);


    }// end listen
}    // end default

what would be the proper way to ask if someone has xx points?

like 

 if (llDetectedKey(0) / points = 10)
        {
do blabla
        }
Link to comment
Share on other sites

Since the variable that contains the player's current score is oldscore, all you're asking is 

if (oldscore%10 == 0)
{
    do whatever
}

Do that right after you increment oldscore in the listen event.  That way, each time the player's score is evenly divisible by 10, whatever happens.  If you expect a player to stop playing when she has 10 points (that is, she'll never play again), you could just write

if (oldscore == 10)
{
    do whatever
}

If you do that, you might as well remove the player's record from the scores list while you're at it.

Link to comment
Share on other sites

thank you rolig,  that works insíde of the listener event,

 

if (oldscore == 2)
{
llInstantMessage(aviKey,"you score is "+ (string) oldscore +" ");

}

 

is it possible to make it work like this within an touch event? when i try its telling me the variables ar not defined

 

    touch_start(integer total_number)
    {
llInstantMessage(aviKey,"you score is "+ (string) oldscore +" ");
    }

= error

 

Link to comment
Share on other sites

As written, no.  Your variable, oldscore, is only defined in the local contact of the listen event, so it is not available in any other event. You would have to define it instead as a global integer, the same way that your variables, channel and maxcount, are.

Link to comment
Share on other sites

On 12/3/2022 at 10:47 PM, Surprised Cerise said:
integer maxCount = 100;  // Only keep the 100 top scores so we do not run out of RAM

Sounds like a good candidate to use Linkset Data 😉

The benefit, in addition to greater space, is data persistence as the high-score list if stored in LSD can survive script resets.

Though if you actually need the highscores reset you'd have to call llLinksetDataReset() somewhere...

Link to comment
Share on other sites

43 minutes ago, primerib1 said:

The benefit, in addition to greater space,

Since the list needs to be brought into script-memory in order to be sorted, using linkset data doesn't actually save much if any script memory usage, unless there's more than one (appreciably sized) list being swapped out.

ETA: If you implemented the list as a separate key-value for each item in the list, that would/could actually save script memory, but it would be inefficient and cumbersome.

Edited by Quistess Alpha
  • Like 1
Link to comment
Share on other sites

18 minutes ago, Quistess Alpha said:

Since the list needs to be brought into script-memory in order to be sorted, using linkset data doesn't actually save much if any script memory usage, unless there's more than one (appreciably sized) list being swapped out.

Ah, you're right. Forgot about that.

Link to comment
Share on other sites

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