Jump to content

question about a percentage decrease and increase system.


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

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

Recommended Posts

Hello, I'm not much good at scripting but I've been making a very simple interactive pet, it has sounds on touch and you can pet it and change it's name but i was wondering since i can't find it anywhere i have looked would a percentage system such as a hunger bar that decreases over time and a menu button that increases the percentage be a lot of work, i have looked everywhere for a percentage based script and pet script but I've only come across breedables which are to much for what i want, don't want people to pay for food only role play, thanks a lot I'm a big noob :)

Link to post
Share on other sites

You can calculate hunger like this:

integer nProcent = (integer)((nHunger/100)*100);

Increase value simply by after say a touch or defined time interval:

nHunger++;

if (nHunger>100)

nHunger= 0;

Display value or build a string by adding for example " โ–Œ" using llSetText() with a for loop

for (i=0; i<=nProcent, i++)

str+="โ–Œ";

Now we would get a string with 100 chars, which is a little overkill - limit it to say 10 chars, so each char represent 10%. Divide nProcent with 10 and be sure to cast the value an integer before using it in for loop.

Link to post
Share on other sites

when our hunger bar is a maximum of 10 bars wide (10% per bar)

and 'hunger' is some integer value in [0..9] and 10 bars is really hungry:

string bar = llGetSubString("โ–Œโ–Œโ–Œโ–Œโ–Œโ–Œโ–Œโ–Œโ–Œโ–Œ", 0, hunger);

going the other way, where 10 bars is not hungry and 1 bar is really hungry:

string bar = llGetSubString("โ–Œโ–Œโ–Œโ–Œโ–Œโ–Œโ–Œโ–Œโ–Œโ–Œ", 0, 9 - hunger);

Link to post
Share on other sites

You can also use a primย to indicate percentage... a bar-scale with a cube, or a pie-chart with a cylinder:

// Bar Scale - Slice a BOX from 1.0 to 0.02

float hunger = 1.0; // 1.0 is 100% of 1
timer() {
	hunger -= 0.01;
	llSetPrimitiveParamsFast([PRIM_SLICE, <0.0, hunger, 0.0>]);
}

// Pie Chart - Cut a CYLINDER from 1.0 to 0.02

float hunger = 1.0; // 1.0 is 100% of 1
timer() {
	hunger -= 0.01;
	llSetPrimitiveParamsFast([PRIM_TYPE, PRIM_TYPE_CYLINDER, PRIM_HOLE_DEFAULT, <0.0, hunger, 0.0>, 0.0, ZERO_VECTOR, ZERO_VECTOR, ZERO_VECTOR]);
}

ย 

Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 81 days.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...