Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- integer out = FALSE;
- integer rod_equip = FALSE;
- key rod_owner; // 3. Since you are passing messages over several events we need to store the rod owner key in a global variable.
- //time 15 seconds delay for it to be visible
- integer lchan;
- list agent_list = [];
- integer allowfish;
- string this_agent_name;
- default
- {
- state_entry()
- {
- llListen(-11223,"Fishing Rod","","");
- }
- touch_start(integer total_number)
- {
- agent_list = [];
- llSensor("", NULL_KEY, AGENT, 12, PI);
- }
- //sensor for those in-range to allow fishing
- sensor (integer num_detected)
- {
- agent_list = agent_list + llDetectedKey(0);
- agent_list = agent_list + llDetectedKey(1);
- agent_list = agent_list + llDetectedKey(2);
- agent_list = agent_list + llDetectedKey(3);
- agent_list = agent_list + llDetectedKey(4);
- agent_list = agent_list + llDetectedKey(5);
- agent_list = agent_list + llDetectedKey(6);
- agent_list = agent_list + llDetectedKey(7);
- agent_list = agent_list + llDetectedKey(8);
- agent_list = agent_list + llDetectedKey(9);
- agent_list = agent_list + llDetectedKey(10);
- agent_list = agent_list + llDetectedKey(11);
- agent_list = agent_list + llDetectedKey(12);
- agent_list = agent_list + llDetectedKey(13);
- agent_list = agent_list + llDetectedKey(14);
- agent_list = agent_list + llDetectedKey(15);
- agent_list = agent_list + llDetectedKey(16);
- agent_list = agent_list + llDetectedKey(17);
- agent_list = agent_list + llDetectedKey(18);
- agent_list = agent_list + llDetectedKey(19);
- agent_list = agent_list + llDetectedKey(20);
- agent_list = agent_list + llDetectedKey(21);
- integer i =0;
- for(i=0;i<llGetListLength(agent_list); i=i+1)
- {
- key this = (key)llList2String(agent_list,i);
- string name = llKey2Name(this);
- llSay(0,"Key List: "+(string)(i+1)+" belong to " +name);
- string this_agent_name = llDetectedName(i);
- //llSay(0, "list: " + (string)agent_list);
- }
- }
- //listen for fishing rod is equip
- listen(integer channel, string what, key who, string msg)
- {
- 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.
- 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.
- 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.
- key rodid = (key)val;
- integer agent = llListFindList( agent_list,[rodid]);
- string aagent = llGetUsername((key)agent);
- string rodowner =llGetUsername( rodid);
- llSay(0, "aggent username: " + aagent);
- llSay(0, "rodowner username: " + rodowner);
- if(aagent == rodowner)
- {
- allowfish = TRUE;
- }
- else
- {
- allowfish = FALSE;
- }
- if(cmd=="Equip" ) // 7. Note this changes to if(cmd=="Equip" ) because we are checking the parsed message.
- {
- rod_equip = TRUE;
- rod_owner = (key)val; // 8. We need to store this in the global variable container so we can send it on to the spawner.
- llSay(0,llKey2Name(rod_owner)+" equipped a rod");
- return;
- }
- else
- {
- rod_equip = FALSE;
- return;
- }
- }
- touch_end(integer total_number)
- {
- lchan = ((integer)("0x"+llGetSubString((string)llDetectedKey(0),-8,-1)) - 723) | 0x8000000;
- //ask for the fishing rod
- llSay(-11223,"CheckRod");
- out = !out;
- if(out == TRUE && rod_equip == TRUE)
- {
- llOwnerSay("Toggle off");
- llSay(lchan,"off");
- return;
- }
- else if(out == FALSE && rod_equip == TRUE)
- {
- llOwnerSay("Toggle On");
- 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.
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement