Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Pet RPG- Leveling Script

Parapsycho Wallace
Registered User
Join date: 7 Jan 2005
Posts: 4
07-06-2007 05:39
Hi everyone.

I'm in the process of developing a game in SL. The basic idea is that you will have a pet that gains experience (via a timer) whenever it is placed in-world. The pet would gain 'levels', like in most RPGs, and be able to attack other pets with varying chances of sucess. Here's what I have so far:

CODE

integer sec = 1;
integer counter = 0;
integer min = 0;
integer level = 1;


default
{
state_entry()
{
//Activate Timer when "Pet" is released
llSetTimerEvent(sec);
}

touch_start(integer total_number)
{
llSay(0, "Pet Paused.");
//llSetTimerEvent(0); Temporarily disabled.
}
timer()
{
counter = counter + sec;
min = counter / 60;
level = counter / 100;
llSetText("Your pet has " + (string)counter + " XP and is " + (string)min + " minutes old. \n Your Pet is level " + (string)level, <1.0, 1.0, 1.0>, 1.0);
}
}


As you can see, for every hundred seconds the pet is in the world, it gains a level. How would I make it so that the time requirement increases with each level? For example, level 1 takes 50 points, level 2 takes 100, then 200, 400, and so on.

Help would be greatly appreciated, and if you want to help with this project, please IM me.

I'm sure I'll have more questions as time goes on.

Thanks,
Parapsycho
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
07-06-2007 06:20
There are several approaches you could take.

If the levels arent a simple straightforward progression (or doubling) or points, then maybe create a list where each entry defines a level requirement:

list levels = [100,200,400,750,1000,1500];
integer len = llGetListLenght(levels);

So thats 6 levels worth. Then you could write a function to loop through the list seeing if their points are sufficient. Maybe something like:

integer levelcheck(list levels, integer counter)
{
integer x;

for (x = 0; x < len; x++)
{
if (counter < llList2Integer(levels, x)) return x;
}
return 0; // shouldnt happen;
}


I didnt test the above, so ymmv.

Or, if things get really complicated from level to level, maybe just have a new state for each level, check to see when that level's counter requirements are met, and change to the next state (assuming there arent too many levels. i