Mayumi_H

Display the number of login users.lsl

Apr 7th, 2020
454
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //フローティングテキストに現在のログインユーザー数を表示する
  2. //
  3. key request_id;
  4. string NumberFormat(string numberString){
  5.     string output;
  6.     integer x = 0;
  7.     integer numberStringLength = llStringLength(numberString);
  8.     integer z = (numberStringLength + 2) % 3;
  9.  
  10.     for(;x < numberStringLength; ++x)
  11.     {
  12.         output += llGetSubString(numberString, x, x);
  13.         if ((x % 3) == z && x != (numberStringLength - 1))
  14.             output += ",";
  15.     }
  16.  
  17.     return output;
  18. }
  19.  
  20. get_HTTP(){
  21.     //HTTPでデータ取得(何故だかhttps指定だとエラーになる)
  22.     request_id = llHTTPRequest("http://secondlife.com/httprequest/homepage.php",[],"");
  23. }
  24.  
  25. default{
  26.     on_rez(integer i){
  27.         llResetScript();
  28.     }
  29.  
  30.     state_entry(){
  31.         llSetText("", <1.0, 1.0, 1.0>, 1.0);
  32.         get_HTTP();
  33.         llSetTimerEvent(180.0);//feed更新が3分間隔なので180秒で回す
  34.     }
  35.  
  36.     timer(){
  37.         get_HTTP();
  38.     }
  39.  
  40.     http_response(key id, integer status, list metadata, string body){
  41.         if(id == request_id){
  42.             if(status == 200){
  43.                 //正常だったら改行コードで分離してLISTに格納(ascii文字のみのためエンコード不要)
  44.                 list feed_LIST = llParseString2List(body,["\n"],[]);
  45.                 //データがあれば取得
  46.                 integer idx;
  47.                 string text;
  48.                 //全ユーザー数
  49.                 idx = llListFindList(feed_LIST, ["signups"]);
  50.                 if(~idx) text += "Total Users : " + NumberFormat(llList2String(feed_LIST,idx + 1)) + "\n";
  51.                 //現在のログインユーザー数
  52.                 idx = llListFindList(feed_LIST, ["inworld"]);
  53.                 if(~idx) text += "Online Users : " + NumberFormat(llList2String(feed_LIST,idx + 1)) + "\n";
  54.                 //現在の1US$ と L$の為替レート(小数付きの数字をそのまま出力)
  55.                 idx = llListFindList(feed_LIST, ["exchange_rate"]);
  56.                 if(~idx) text += "1 US$ = " + llList2String(feed_LIST,idx + 1) + " L$\n";
  57.  
  58.                 llSetText(text, <1.0,1.0,1.0>, 1.0);
  59.             }else{
  60.              //   llSay(0,"error code = " + (string)status);
  61.             }
  62.         }
  63.     }
  64. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×