Jump to content

Texture off set based on percentage?


oOPussInBootsOo
 Share

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

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

Recommended Posts

Hey people, I'm making a little rpg system and keeping things pretty simple on the hud part. What I want to do is use a texture "not hover text" health bar. I want to make a texture offset based on hp. I'm a bit lost on how I would off set my texture on the stander 0 to 100 hp stats. Any help on this matter would be nice. Also looking to use "llSetLinkPrimitiveParamsFast" for lower scripts, so I don't have to place a script in every bar on hud. 

Link to comment
Share on other sites

I have made a texture it's half alpha, what I want to do is slide the texture to show say 50% hp 37% hp (IE offset the texture based on hp from 0 to 100). yeah old school gamer and I love to see UIs and not hover text lol. I have added a photo of my hud to show you the idea of what I want to do.

demo.png

Edited by oOPussInBootsOo
type o
Link to comment
Share on other sites

good, you have the half texture already. There's a little math involved.

If the split in the texture is vertical, you'll want to scale and offset the texture horizontally, and if the split is horizontal.....

so the scale would just be half

the offset would be the percentage as a decimal, divided in half, then subtract 0.25.

here's an example script using a black/white texture with the split being vertical. You could use the same texture on either side and change the color accordingly as well as flip the texture by giving it a negative scale

integer health = 100;
default
{
    touch(integer total_number)
    {
        if(health > 0)
        health--;
        float healthperc = (float)health/100.0;
        float offset = (healthperc*.5)-0.25;
        llSetLinkPrimitiveParamsFast(LINK_THIS,
        [PRIM_TEXTURE,0,"blackwhitehalf",<-0.5,1.0,0.0>,<offset,0.0,0.0>,0.0,
        PRIM_TEXT,(string)((integer)(healthperc*100))+"%",<0.0,1.0,0.0>,1.0]);
    }
}

 

 

Edited by Ruthven Willenov
  • Like 1
Link to comment
Share on other sites

12 minutes ago, Ruthven Willenov said:

integer health = 100;
default
{
    touch(integer total_number)
    {
        if(health > 0)
        health--;
        float healthperc = (float)health/100;
        float offset = (healthperc*.5)-0.25;
        llSetLinkPrimitiveParamsFast(LINK_THIS,
        [PRIM_TEXTURE,0,"blackwhitehalf",<0.5,1,0>,<offset,0,0>,0,
        PRIM_TEXT,(string)((integer)(healthperc*100))+"%",<0,1,0>,1]);
    }
}

 

 

Wish you would use floats and not integers where there should be floats. The server has to convert them.

Edited by steph Arnott
  • Like 1
Link to comment
Share on other sites

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