Advertisement
Shinobiace

Fish Pond + Sensor

Oct 26th, 2020
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. integer out  = FALSE;
  3. integer rod_equip = FALSE;
  4.  
  5. key rod_owner;    // 3. Since you are passing messages over several events we need to store the rod owner key in a global variable.
  6.  
  7. //time 15 seconds delay for it to be visible
  8.  
  9. integer lchan;
  10.  
  11.  
  12. list agent_list = [];
  13. integer allowfish;
  14. string this_agent_name;
  15. default
  16. {
  17.      state_entry()
  18.     {
  19.         llListen(-11223,"Fishing Rod","","");
  20.     }
  21.     touch_start(integer total_number)
  22.     {
  23.         agent_list = [];
  24.         llSensor("", NULL_KEY, AGENT, 12, PI);
  25.     }
  26.     //sensor for those in-range to allow fishing
  27.     sensor (integer num_detected)
  28.     {
  29.         agent_list = agent_list + llDetectedKey(0);
  30.         agent_list = agent_list + llDetectedKey(1);
  31.         agent_list = agent_list + llDetectedKey(2);
  32.         agent_list = agent_list + llDetectedKey(3);
  33.         agent_list = agent_list + llDetectedKey(4);
  34.         agent_list = agent_list + llDetectedKey(5);
  35.         agent_list = agent_list + llDetectedKey(6);
  36.         agent_list = agent_list + llDetectedKey(7);
  37.         agent_list = agent_list + llDetectedKey(8);
  38.         agent_list = agent_list + llDetectedKey(9);
  39.         agent_list = agent_list + llDetectedKey(10);
  40.         agent_list = agent_list + llDetectedKey(11);
  41.         agent_list = agent_list + llDetectedKey(12);
  42.         agent_list = agent_list + llDetectedKey(13);
  43.         agent_list = agent_list + llDetectedKey(14);
  44.         agent_list = agent_list + llDetectedKey(15);
  45.         agent_list = agent_list + llDetectedKey(16);
  46.         agent_list = agent_list + llDetectedKey(17);
  47.         agent_list = agent_list + llDetectedKey(18);
  48.         agent_list = agent_list + llDetectedKey(19);
  49.         agent_list = agent_list + llDetectedKey(20);
  50.         agent_list = agent_list + llDetectedKey(21);
  51.         integer i =0;
  52.         for(i=0;i<llGetListLength(agent_list); i=i+1)
  53.         {
  54.             key this = (key)llList2String(agent_list,i);
  55.             string name = llKey2Name(this);
  56.             llSay(0,"Key List: "+(string)(i+1)+" belong to " +name);
  57.             string  this_agent_name = llDetectedName(i);
  58.             //llSay(0, "list: " + (string)agent_list);
  59.         }
  60.  
  61.     }
  62.    
  63.    
  64.    
  65.    
  66.     //listen for fishing rod is equip
  67.     listen(integer channel, string what, key who, string msg)
  68.     {        
  69.  
  70.     list tmp = llParseString2List(msg,["_"],[]);   // 4. We parse the message sent from the rod to the pond. The message will be split into elements in a list at the separator.  
  71.    
  72.     string cmd = llList2String(tmp,0); // 5. The value to the left of the separator will become the first element in the list.  i,e "Equip".   Note that list elements begin at 0.
  73.    
  74.     string val = llList2String(tmp,1); // 6. The value to the right of the separator will become the second element in the list.    i,e The rod owner key.
  75.             key rodid = (key)val;
  76.             integer agent = llListFindList( agent_list,[rodid]);
  77.             string aagent = llGetUsername((key)agent);
  78.             string rodowner =llGetUsername( rodid);
  79.             llSay(0, "aggent username: " + aagent);
  80.             llSay(0, "rodowner username: " + rodowner);
  81.             if(aagent == rodowner)
  82.             {
  83.                 allowfish = TRUE;
  84.             }
  85.             else
  86.             {
  87.                 allowfish = FALSE;
  88.             }
  89.            
  90.             if(cmd=="Equip" ) // 7. Note this changes to if(cmd=="Equip" ) because we are checking the parsed message.
  91.             {
  92.                
  93.                rod_equip = TRUE;
  94.                rod_owner = (key)val;  // 8. We need to store this in the global variable container so we can send it on to the spawner.
  95.                 llSay(0,llKey2Name(rod_owner)+" equipped a rod");
  96.                return;
  97.             }
  98.             else
  99.             {            
  100.                 rod_equip = FALSE;
  101.                 return;
  102.             }
  103.  
  104.  
  105.                        
  106.     }
  107.    
  108.     touch_end(integer total_number)
  109.     {
  110.    
  111.    
  112.     lchan = ((integer)("0x"+llGetSubString((string)llDetectedKey(0),-8,-1)) - 723) | 0x8000000;
  113.         //ask for the fishing rod  
  114.              
  115.         llSay(-11223,"CheckRod");  
  116.         out = !out;      
  117.        
  118.        
  119.         if(out == TRUE && rod_equip == TRUE)
  120.         {
  121.             llOwnerSay("Toggle off");      
  122.             llSay(lchan,"off");          
  123.             return;
  124.         }
  125.        
  126.         else if(out == FALSE && rod_equip == TRUE)
  127.         {
  128.             llOwnerSay("Toggle On");
  129.             llSay(lchan,"on");  //9. We send the message on to the spawners and whichever spawner with an owner key that matches the rod owner key will spawn fish.
  130.             return;
  131.         }                                  
  132.     }
  133.          
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement