Jump to content

Need a little fix (HP Hud scripting)


Walter Fanwood
 Share

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

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

Recommended Posts

I tried lately to make a easy HP HUD for a fight system its based on

 

the problem is anyhow i made somewhere a misstake i guess with the >/< stuff

 

here the script i use, its normaly a easy texture based HUD, the textures are not missing or something but it will not change anything (texture wise):

 

key owner;
vector defaultcolor = <0,1,0>;
integer HP;


default
{
    state_entry()
    {
        owner = llGetOwner();
        llListen(-156535255,"","","");
    }
    
    attach(key id)
    {
        llResetScript();
    }

    listen(integer chan, string name, key id, string msg)
    {
        list temp = llCSV2List(msg);
        if((llList2Key(temp,0) == owner) && (llList2String(temp,1) == "UPDATE"))
        {
string HP = llList2String(temp,2);
        }    
        if((llList2Key(temp,0) == owner) && (llList2String(temp,1) == "UPDATE"))
{ 
           if(HP = 0)
    {
    llSetTexture("HP00",ALL_SIDES); 
    }
    
              if(HP >= 0)
    {
        if(HP <= 9)
        {
    llSetTexture("HP01",ALL_SIDES); 
}
}
     if(HP >= 10)
    {
        if(HP <= 19)
        {
    llSetTexture("HP02",ALL_SIDES); 
}
}
    
     if(HP >= 20)
    {
        if(HP <= 29)
        {
    llSetTexture("HP03",ALL_SIDES); 
}
}    
    
      if(HP >= 30)
    {
        if(HP <= 39)
        {
    llSetTexture("HP04",ALL_SIDES); 
}
}  
 
     if(HP >= 40)
    {
        if(HP <= 49)
        {
    llSetTexture("HP05",ALL_SIDES); 
}
}   
 
      if(HP >= 50)
    {
        if(HP <= 59)
        {
    llSetTexture("HP06",ALL_SIDES); 
}
}  
 
       if(HP >= 60)
    {
        if(HP <= 69)
        {
    llSetTexture("HP07",ALL_SIDES); 
}
}  
 
        if(HP >= 70)
    {
        if(HP <= 79)
        {
    llSetTexture("HP08",ALL_SIDES); 
}
} 
 
        if(HP >= 80)
    {
        if(HP <= 89)
        {
    llSetTexture("HP09",ALL_SIDES); 
}
}

        if(HP >= 90)
    {
        if(HP <= 101)
        {
    llSetTexture("HP10",ALL_SIDES); 
}
}
    }
    }
}

Can maybe someone fix it for me? would be nice coz i kinda freaked out. I guess that </> stuff kinda blowed my mind ^^;

 

before someone ask, the orignal its based on, its just a hover text HUD which looks like this (and yea this one actually works)

key owner;
vector defaultcolor = <0,1,0>;


default
{
    state_entry()
    {
        owner = llGetOwner();
        llListen(-156535255,"","","");
        llSetText("Turn on your Spy Meter to show status",<1,1,1>,1.0);
    }
    
    attach(key id)
    {
        llResetScript();
    }

    listen(integer chan, string name, key id, string msg)
    {
        list temp = llCSV2List(msg);
        if((llList2Key(temp,0) == owner) && (llList2String(temp,1) == "UPDATE"))
        {
            llSetText("Spy Status\n"+llList2String(temp,2)+" HP / "+llList2String(temp,3)+" AP",defaultcolor,1.0);
        }
    }
}

Link to comment
Share on other sites

Firstly you're mixing up strings and integers by declaring HP as a string and then checking if 'HP == 0' instead of 'HP =="0"'.
Secondly you don't need the second 'if((llList2Key(temp,0) == owner) && (llList2String(temp,1) == "UPDATE")) {'

Thirdly, I think this works as well:

key owner;list textures = ["HP00", "HP01", "HP02", "HP03", "HP04", "HP05", "HP06", "HP07", "HP08", "HP09", "HP10"];default {    state_entry() {        owner = llGetOwner();        llListen(-156535255,"","","");    }        attach(key id) {        llResetScript();    }    listen(integer chan, string name, key id, string msg) {        list temp = llCSV2List(msg);        if((llList2Key(temp,0) == owner) && (llList2String(temp,1) == "UPDATE")) {            integer HP = llAbs((integer)(llList2String(temp,2)));            integer index = llFloor(HP/10) + 1;            if (index <= llGetListLength(textures) - 1) {                llSetTexture(llList2String(textures, index), ALL_SIDES);            }        }    }} 
Link to comment
Share on other sites

I tried yours but its anyhow not working, meaning there is a error with the list.

 

Anyways i fixed the "==" thing (thanks again!) and deleted some stuff so i made it working like this now

 

key owner;vector defaultcolor = <0,1,0>;integer HP = 100;default{    state_entry()    {        owner = llGetOwner();        llListen(-156535255,"","","");    }        attach(key id)    {        HP = 100;        llSetTexture("HP00",ALL_SIDES);        llResetScript();    }    listen(integer chan, string name, key id, string msg)    {        list temp = llCSV2List(msg);        if((llList2Key(temp,0) == owner) && (llList2String(temp,1) == "UPDATE"))        {HP = (integer)llList2Integer(temp,2);        }               if(HP == 0)    {    llSetTexture("HP00",ALL_SIDES);     }                  if(HP >= 1)    {        if(HP <= 10)        {    llSetTexture("HP01",ALL_SIDES); }}     if(HP >= 11)    {        if(HP <= 20)        {    llSetTexture("HP02",ALL_SIDES); }}         if(HP >= 21)    {        if(HP <=30)        {    llSetTexture("HP03",ALL_SIDES); }}              if(HP >= 31)    {        if(HP <= 40)        {    llSetTexture("HP04",ALL_SIDES); }}        if(HP >= 41)    {        if(HP <= 50)        {    llSetTexture("HP05",ALL_SIDES); }}          if(HP >= 51)    {        if(HP <= 60)        {    llSetTexture("HP06",ALL_SIDES); }}          if(HP >= 61)    {        if(HP <= 70)        {    llSetTexture("HP07",ALL_SIDES); }}           if(HP >= 71)    {        if(HP <= 80)        {    llSetTexture("HP08",ALL_SIDES); }}          if(HP >= 81)    {        if(HP <= 90)        {    llSetTexture("HP09",ALL_SIDES); }}        if(HP >= 91)    {        if(HP <= 100)        {    llSetTexture("HP10",ALL_SIDES); }}    }}
Link to comment
Share on other sites

Another thing you might want to change are some of the "if" statements. When the script has to check the same variable on different conditions, it's better to use "else if" on any but the first one. Otherwise the script will check any following statement on a previous passed one. You can also combine conditions by using the && (logical AND) operator and make your code more readable.

Anyway it can be confusing if there are various condition checks for different variables or parameters like in your script and it also needs a return case after the very first "if". Espacially as the HP value may hold data by a previous update call and would process then although it's not supposed to. It won't result in a bug but consumes unnecessary script resources. 

Also your attach event doesn't makes sense. The script sets the HP variable to 100 but resets the script 2 lines later. When the script resets, the HP variable will initialize with 100 . The HP variable seems to get its value only by the update call anyway. That line and the global HP variable can get deleted without worry just like "defaultcolor" if you want to use textures instead of the float text.

 

key owner;default{    state_entry()    {        owner = llGetOwner();        llListen(-156535255,"","","");
llSetTexture("HP00",ALL_SIDES); } attach(key id) {
if(id) // only continues on attach. no need to reset on detach
{ llResetScript();
} } listen(integer chan, string name, key id, string msg) { list temp = llCSV2List(msg); integer HP;
// kinda security check if owner matchs and item needs to update if((llList2Key(temp,0) == owner) && (llList2String(temp,1) == "UPDATE")) { HP = (integer)llList2Integer(temp,2); } // if previous statement failed because its conditions didn't match, script better returns here else return; // first statement seems passed. script can continue with validatin HP if(HP == 0) { llSetTexture("HP00",ALL_SIDES); } else if(HP >= 1 && HP <= 10) { llSetTexture("HP01",ALL_SIDES); } else if(HP >= 11 && HP <= 20) { llSetTexture("HP02",ALL_SIDES); } else if(HP >= 21 && HP <= 30) { llSetTexture("HP03",ALL_SIDES); } else if(HP >= 31 && HP <= 40) { llSetTexture("HP04",ALL_SIDES); } else if(HP >= 41 && HP <= 50) { llSetTexture("HP05",ALL_SIDES); } else if(HP >= 51 && HP <= 60) { llSetTexture("HP06",ALL_SIDES); } else if(HP >= 61 && HP <= 70) { llSetTexture("HP07",ALL_SIDES); } else if(HP >= 71 && HP <= 80) { llSetTexture("HP08",ALL_SIDES); } else if(HP >= 81 && HP <= 90) { llSetTexture("HP09",ALL_SIDES); } else if(HP >= 91 && HP <= 100) { llSetTexture("HP10",ALL_SIDES); } // if none of the previous statements passed, something seems to went wrong.
// especially on development it's nice to know about such cases else { llOwnerSay("Something went wrong! HP above 100 or below 0 somehow"); } }}

 

 

Link to comment
Share on other sites

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