GMCP Item Tracker

Share your scripts and packages with other Mudlet users.
Post Reply
Phoenix
Posts: 92
Joined: Tue Feb 15, 2011 3:23 am

GMCP Item Tracker

Post by Phoenix »

This GMCP Item Tracker takes care of all the item tracking. In order to not get messed up with other functions modifying GMCP.Item information, this tracker uses all of its own tables as well as a manual deep-copy of the gmcp tables into its own tables.

This was programmed for Achaea, and follows the GMCP standards as implemented there. If another MUD has something modified slightly from the standards, or interprets the standards differently, it should only require minor modification. Please feel free to re-post 'realm specific' mods of this here.

Variables:
room_items : A table of all the items in the room, updated with every item entered into the room

inv_items : A table of all the items in your inventory, updated with every item acquired. NOTE: In Achaea, the 'secret' ability hides the acquisition message, even in GMCP - these items will not show until this table is updated, which should happen any time the inventory is checked.

wield_items : A table of the left and right wielded items. If an item is a two-hand wield, it will be in both left -and- right portions of this table. For instance, wield_items.left.id would be the ID of the item wielded in your left hand. This updates on the inventory list message, update messages, and remove messages.

phoenix.items["1234_items"] : A table of the contents of container 1234, automatically generated.

*NEW!*
Events:

Wield Event - this event fires after the wield table is fully updated.
phoenix done with wield - passes an argument of what happened during wield updating. This argument is an explanatory argument, in case you need to trigger off 'unwield', for instance.

Tracking Event - These events fire only after the scripts are done running, and room_item and inv_items have been fully updated.

phoenix items add - passes an argument of 'location', for where the item was added to.
phoenix items remove - passes an argument of 'location', for where the item was removed from.
phoenix items list - passes an argument of 'location', for which location we received a list of.
phoenix items update - passes an argument of 'location', for where the item updated was located.
Attachments
Phoenix GMCP Items.zip
Updated 07/04/2014 for Achaea's current GMCP implementation. Minor mods may be required for other MUDs.
(1.87 KiB) Downloaded 1353 times

Siduri
Posts: 9
Joined: Wed Jun 26, 2013 7:12 pm

Re: GMCP Item Tracker

Post by Siduri »

Hello!
First off, I want to say that your script works wonderfully well.
I only have one issue, and that's because it seems to send five "ql" commands on login, and it's very spammy.
I think it's caused by not catching info, and retrying until gmcp becomes responsive.

Is it possible? Or would anything else cause it?

EulersIdentity
Posts: 27
Joined: Fri Jun 26, 2015 8:52 am

Re: GMCP Item Tracker

Post by EulersIdentity »

I was dreading going through and fixing all the spaghetti code I wrote when I was figuring out how GMCP works. This saved me a lot of work. Here's a few convenience functions (for Achaea) I've been using with it in case they are helpful to anyone else.
Code: [show] | [select all] lua

karmaItems = {
	"a mortar and pestle",
	[[a book titled "Moonie's Riddle" by Neville "Moonie" Carnivalis]],
	"the Mask of the Beast",
	"a fetish charm",
	"the Book of Wyrdling Secrets",
	[[a book titled "Seven Rays" by Madam Bagaska]]
}
-- gives all items in array karmaItems to whatever is passed as the argument
-- target 'self' or nil to echo karma items held
function giveKarma(who)
	local flagFound = false
	for i,kitem in ipairs(karmaItems) do
		for k,v in pairs(inv_items) do
			if v.name:find(kitem) then
				if who == "self" or who == nil then
					flagFound = true
					cecho("<purple>  !  " .. v.id..": " .. v.name .. "\n")
				else
					send("give " .. v.id .. " to " .. who, false)
				end
			end--if
 		end--for
	end--for
	if not flagFound then
		cecho("<purple>  !  Not holding karmic items  !\n")
	end
end

-- throw away useless things gotten from pickpocketting denizens
function junk ()
  for k,v in pairs(inv_items) do
    if v.name == "a plain grey handkerchief" then
      send("give "..v.id.." to humgii", false)
    end
	if v.name == "a simple oaken pipe" then
		send("give "..v.id.." to humgii", false)
	end
	if v.name == "an oaken vial" then
		send("give "..v.id" to humgii", false)
	end
  end
end

-- echoes inventory without any vials
function iiNoVial ()
	for i,v in ipairs(inv_items) do
		if not string.find(v.name, "vial") then
			tabInsert(v.id,0)
			tabInsert(v.name, 8)
			echo("\n")
		end --if
	end -- for
end --iiNoVial

The last one relies the wundersys function wsys.doadd() function to work. It can be replaced by longer timers, balance triggers, or any other function that sends commands when the character has balance/eq. It gives all of the things in your inventory with the string stuff in their name to npc. It's good for single items as well as multiples, especially when you need to give a denizen a specific book, note, etc. and you have other items of that type in your inventory.
Code: [show] | [select all] lua
-- meant for giving items to npc's
-- drops selfishness, gives all items with "stuff" in their name to "npc"
-- then raises selfishness
-- usage: questGive("cyclops","creamy white goat") will give the cyclops all creamy white goats
--            in your inventory

function questGive(npc,stuff)
	local flagFound = false
	for k,v in pairs(inv_items) do
		if v.name:find(stuff) then
			flagFound = true
			tempTimer(.8,[[send("give ]]..v.id..[[ to ]]..npc..[[")]] )
		end--if
	end --for
	for ii,vv in ipairs(gmcp.Char.Defences.List) do
		if vv.name == "selfishness" and flagFound then
			wsys.doadd("generosity")
			tempTimer(1,[[wsys.doadd("selfishness")]])
			tempTimer(.9,[[wsys.doadd("put gold in pack")]])
		end--if
	end-- for
end --questGive

Post Reply