Getting environment name from ATCP

Posted by Deiwos on Thu 28 Oct 2010 11:54 AM — 5 posts, 17,787 views.

#0
I have made myself a harvesting script, but at the moment I have to set an environment variable by checking Survey in order for the script to know what herbs to harvest.

What I am hoping for is to know if there's any way to put a SetVariable somewhere in the ATCP_NJG/ATCP_Mapper plugins to update the variable I made with the environmentname data stored for each room as I move around. Or, alternatively, some way for the script itself to automatically find out rather than using this variable.

What I've tried is checking 'environmentname' under 'function get_room (uid)' in ATCP_mapper.xml (with a Send(world.Note(environmentname))), but that seems to.. return a large list of environment names rather than just that of the room I'm in, and after scanning back and forth through the file I don't understand it enough to know where I'd place a SetVariable.
USA #1
Inside the ATCP_NJG plugin is an example of how to make use of it:

function OnPluginBroadcast (msg, id, name, text)
  if id == "85f72d0e263d75df7bde6f00" then
  
    if msg == 1 then
      do_ATCP_vitals (text)      -- eg. "H:496/496 M:412/412 E:1380/1380 W:960/960 NL:89/100 "
                                 --      health    mana      endurance   willpower experience
    elseif msg == 2 then
      do_ATCP_room_brief (text)  -- eg. "Continuing on the Parade of Zarathustra"
    elseif msg == 3 then
      do_ATCP_room_exit (text)   -- eg. "n,s"
    elseif msg == 4 then
      do_ATCP_room_number (text) -- eg. "401"
    elseif msg == 5 then
      do_ATCP_room_full_exits (text) -- eg. "ne(8564),w(8428)"
    elseif msg == 6 then
      do_ATCP_room_environment (text) -- eg. "Urban"
    elseif msg == 7 then
      do_ATCP_room_coordinates (text) -- eg. "38,3,1,0"
    elseif msg == 8 then
      do_ATCP_room_info (text)        -- eg. "shop,postoffice"
    end -- if   
 
  end -- if ATCP message
end

Whenever the ATCP plugin receives a message, it broadcasts it. Plugins with an OnPluginBroadcast hook (like the one above) will get called with the data. As you can see above, "msg" will be 6 when it's a Room.Environment message, and "text" will contain the data from that message.

To use this, you can create your own plugin for your harvesting actions, and add this hook into the script. If all you want is the environment, you can do this:
function OnPluginBroadcast (msg, id, name, text)
  if id == "85f72d0e263d75df7bde6f00" then
    if msg == 6 then -- Room.Environment
      -- code to handle the environment here
    end
  end -- if ATCP message
end
Australia Forum Administrator #2
Twisol said:

Inside the ATCP_NJG plugin is an example of how to make use of it ...


Just to clarify, that is indeed inside the ATCP_NJG plugin as commented-out code (near the start). It is an example of what you add to other plugins.

The ATCP_NJG plugin actually detects the incoming telnet messages from the MUD and broadcasts them. So Twisol is correct, inside your own plugin you put the code he suggested to receive that broadcast.

#3
I'm sorry, but I'm very confused now. I did what was said and tried making a plugin in the plugin wizard with this:

function OnPluginBroadcast (msg, id, name, text)
   if id == "85f72d0e263d75df7bde6f00" then
     if msg == 6 then -- Room.Environment      
        do_ATCP_room_environment (text)
        SetVariable("enviro", text)
     end
  end -- if ATCP message
end


But I get the error:
Quote:
Function/Sub: OnPluginBroadcast called by Plugin EnvironmentGrabber
Reason: Executing plugin EnvironmentGrabber sub OnPluginBroadcast
[string "Plugin"]:155: attempt to call global 'do_ATCP_room_environment' (a nil value)


Sorry, I just don't understand enough to know how to get the information into a variable.
Australia Forum Administrator #4
Leave out this line:


do_ATCP_room_environment (text)


That is trying to call a function called "do_ATCP_room_environment" which it sounds like you haven't written.

The line you had afterwards (SetVariable) will set the variable for you.

However if you wanted to immediately react to an environment message then you could write a function. For example:


function do_ATCP_room_environment (text)
  print ("Now in environment", text)
end


Of course, this would probably spam you with such messages. Another way would be to notify you if the environment changes, eg.



function do_ATCP_room_environment (text)
  if text ~= old_environment then
    print ("Now in environment", text)
    old_environment = text
  end -- if environment changed
end