Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //const of width of hp bar
- float maxhpP = 0.344;
- //variables
- string url;
- string http_request_id ;
- key uuid;string fname;string lname;
- //variables ending in P = link/prim number
- integer hydrationP = -1;
- integer foodP = -1;
- integer fitnessP = -1;
- integer hygeneP = -1;
- integer hpP = -1;
- integer ageP = -1;
- //change hp prim size.z to percentage
- adjustHP(float amount) {
- list tmp = llGetLinkPrimitiveParams(hpP, [PRIM_SIZE]);
- vector size = llList2Vector(tmp, 0);
- size.z = maxhpP * (amount/100);
- llSetLinkPrimitiveParams(hpP, [PRIM_SIZE, size]);
- }
- //adjust circle prims
- adjustAttribute(integer attribute, float amount) {
- list tmp = llGetLinkPrimitiveParams(attribute, [PRIM_TYPE]);
- vector v = llList2Vector(tmp, 2);
- v.y = amount/100;
- tmp = llListReplaceList(tmp, [v], 2, 2);
- feedback(llDumpList2String(tmp, " " ));
- llSetLinkPrimitiveParams(attribute, [PRIM_TYPE, tmp]);
- }
- //outputs to user
- feedback(string out) {
- llOwnerSay(out);
- }
- //to index the prims
- index() {
- integer i = 0;
- integer max = llGetNumberOfPrims();
- //linear loop to go through all the prims
- for(i = 0; i <= max; i++) {
- if(llGetLinkName(i) == "hydration") hydrationP = i;
- if(llGetLinkName(i) == "food") foodP = i;
- if(llGetLinkName(i) == "fitness") fitnessP = i;
- if(llGetLinkName(i) == "hygene") hygeneP = i;
- if(llGetLinkName(i) == "HP") hpP = i;
- if(llGetLinkName(i) == "age") ageP = i;
- //checks if all indexes are set and exits function when met
- if((hydrationP != -1) && (foodP != -1) && (fitnessP != -1) && (hygeneP != -1) && (hpP != -1) && (ageP != -1)) return;
- }
- }
- //on heartbeat
- heartbeat() {
- if(llGetAttached() != 0) request("?UUID=" + uuid + "&first=" + fname + "&last=" + lname);
- }
- //update hud on http response
- http_response_handle(string body) {
- //need to do something with age
- //csv :: (0)age, (1)exercise, (2)health, (3)hydration, (4)hygene, (5)nutrition
- list tmp = llParseString2List(body, ",","");
- adjustAttribute(fitnessP, llList2Float(tmp, 1));
- adjustHP(llList2Float(tmp, 2));
- adjustAttribute(hydrationP, llList2Float(tmp, 3));
- adjustAttribute(hygeneP, llList2Float(tmp, 4));
- adjustAttribute(foodP,llList2Float(tmp, 5));
- //for messages coming from server
- if(llGetListLength(tmp) > 5) feedback(llList2String(tmp, 6));
- }
- //for handeling requests
- request(string data) {
- http_request_id = llHTTPRequest(url + data, [HTTP_METHOD, "GET", HTTP_MIMETYPE, "text/plain;charset=utf-8"], "");
- }
- //when the script initiates
- startup() {
- //index prims
- index();
- //get user
- uuid = llGetOwner();
- fname = llKey2Name(uuid);
- list tmp = llParseString2List(fname, " ", "");
- fname = llList2String(tmp, 0);
- lname = llList2String(tmp, 1);
- //get url
- url = osGetGridLoginURI();
- tmp = llParseString2List(url, ":", "");
- url = llList2String(tmp, 0) + llList2String(tmp, 1);
- //llSetTimerEvent(60);
- }
- default
- {
- state_entry() {
- startup();
- //adjustAttribute(hygeneP, 75);
- //adjustHP(100);
- }
- http_response(key request_id, integer status, list metadata, string body)
- {
- if (request_id == http_request_id && status == 200)
- {
- http_response_handle(body);
- }
- }
- timer() {
- heartbeat();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement