Advertisement
kopilo

LuL - Health HUD

Jan 14th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //const of width of hp bar
  2. float maxhpP = 0.344;
  3. //variables
  4. string url;
  5. string http_request_id ;
  6. key uuid;string fname;string lname;
  7. //variables ending in P = link/prim number
  8. integer hydrationP = -1;
  9. integer foodP = -1;
  10. integer fitnessP = -1;
  11. integer hygeneP = -1;
  12. integer hpP = -1;
  13. integer ageP = -1;
  14.  
  15. //change hp prim size.z to percentage
  16. adjustHP(float amount) {
  17.     list tmp = llGetLinkPrimitiveParams(hpP, [PRIM_SIZE]);
  18.     vector size = llList2Vector(tmp, 0);
  19.     size.z = maxhpP * (amount/100);
  20.     llSetLinkPrimitiveParams(hpP, [PRIM_SIZE, size]);
  21. }
  22. //adjust circle prims
  23. adjustAttribute(integer attribute, float amount) {
  24.     list tmp = llGetLinkPrimitiveParams(attribute, [PRIM_TYPE]);
  25.     vector v = llList2Vector(tmp, 2);
  26.     v.y = amount/100;
  27.     tmp = llListReplaceList(tmp, [v], 2, 2);
  28.     feedback(llDumpList2String(tmp, " " ));
  29.     llSetLinkPrimitiveParams(attribute, [PRIM_TYPE, tmp]);
  30. }
  31.  
  32. //outputs to user
  33. feedback(string out) {
  34.     llOwnerSay(out);
  35. }
  36.  
  37. //to index the prims
  38. index() {
  39.     integer i = 0;
  40.     integer max = llGetNumberOfPrims();
  41.     //linear loop to go through all the prims
  42.     for(i = 0; i <= max; i++) {
  43.         if(llGetLinkName(i) == "hydration") hydrationP = i;
  44.         if(llGetLinkName(i) == "food") foodP = i;
  45.         if(llGetLinkName(i) == "fitness") fitnessP = i;
  46.         if(llGetLinkName(i) == "hygene") hygeneP = i;
  47.         if(llGetLinkName(i) == "HP") hpP = i;
  48.         if(llGetLinkName(i) == "age") ageP = i;
  49.         //checks if all indexes are set and exits function when met
  50.         if((hydrationP != -1) && (foodP != -1) && (fitnessP != -1) && (hygeneP != -1) && (hpP != -1) && (ageP != -1)) return;
  51.     }
  52. }
  53.  
  54. //on heartbeat
  55. heartbeat() {
  56.     if(llGetAttached() != 0) request("?UUID=" + uuid + "&first=" + fname + "&last=" + lname);
  57. }
  58.  
  59. //update hud on http response
  60. http_response_handle(string body) {
  61.     //need to do something with age
  62.     //csv :: (0)age, (1)exercise, (2)health, (3)hydration, (4)hygene, (5)nutrition
  63.     list tmp = llParseString2List(body, ",","");
  64.     adjustAttribute(fitnessP, llList2Float(tmp, 1));
  65.     adjustHP(llList2Float(tmp, 2));
  66.     adjustAttribute(hydrationP, llList2Float(tmp, 3));
  67.     adjustAttribute(hygeneP, llList2Float(tmp, 4));
  68.     adjustAttribute(foodP,llList2Float(tmp, 5));
  69.     //for messages coming from server
  70.     if(llGetListLength(tmp) > 5) feedback(llList2String(tmp, 6));
  71. }
  72.  
  73. //for handeling requests
  74. request(string data) {
  75.     http_request_id = llHTTPRequest(url + data, [HTTP_METHOD, "GET", HTTP_MIMETYPE, "text/plain;charset=utf-8"], "");
  76. }
  77.  
  78. //when the script initiates
  79. startup() {
  80.     //index prims
  81.     index();
  82.     //get user
  83.     uuid = llGetOwner();
  84.     fname = llKey2Name(uuid);
  85.     list tmp = llParseString2List(fname, " ", "");
  86.     fname = llList2String(tmp, 0);
  87.     lname = llList2String(tmp, 1);
  88.     //get url
  89.     url = osGetGridLoginURI();
  90.     tmp = llParseString2List(url, ":", "");
  91.     url = llList2String(tmp, 0) + llList2String(tmp, 1);
  92.     //llSetTimerEvent(60);
  93. }
  94.  
  95. default
  96. {
  97.     state_entry() {
  98.         startup();
  99.         //adjustAttribute(hygeneP, 75);
  100.         //adjustHP(100);
  101.     }
  102.     http_response(key request_id, integer status, list metadata, string body)
  103.     {
  104.         if (request_id == http_request_id && status == 200)
  105.         {
  106.             http_response_handle(body);
  107.         }
  108.     }
  109.     timer() {
  110.         heartbeat();
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement