conditionals and inventory (Achaea)

Post Reply
Felix
Posts: 8
Joined: Fri Mar 29, 2013 3:58 pm

conditionals and inventory (Achaea)

Post by Felix »

I would appreciate your expertise in learning about conditionals in Mudlet. Specifically, I'd like to be able to code a little thing that would check my inventory for various kinds of corpses that Talus likes (sheep, lions, crocodiles, etc.) and IF such a corpse is found, THEN send "give sheep to Talus" or "give lion to Talus" or whatever. Is that something manageable? Knowing something about conditionals would help me understand Mudlet, as well as decreasing the wear and tear on my typing fingers.

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: conditionals and inventory (Achaea)

Post by Jor'Mox »

Well, I would think it wouldn't be that complicated. Capture your inventory and store it in a table. And since you care about corpses in particular, maybe have a special table just for corpses.

Then, when you need to give someone a certain corpse, you can check if such a corpse exists by keyword. Like this:
Code: [show] | [select all] lua
if corpse_table["lion"] then 
send("give lion to Talus")
corpse_table["lion"] = false
end

Felix
Posts: 8
Joined: Fri Mar 29, 2013 3:58 pm

Re: conditionals and inventory (Achaea)

Post by Felix »

Thank you very much, Jor'Mox.

User avatar
kevutian
Posts: 217
Joined: Fri Aug 20, 2010 8:18 pm
Location: United Kingdom
Contact:

Re: conditionals and inventory (Achaea)

Post by kevutian »

If your game supports GMCP:
Code: [show] | [select all] lua
function hasItem(name, num)
	if not gmcp or not gmcp.Char or not gmcp.Char.Items or not gmcp.Char.Items.List then return false end
	for _, item in ipairs(gmcp.Char.Items.List.items) do
		if name and item.name:find(name) then return true end
		if num and item.id == tostring(num) then return true end
	end

	return false
end
:)

Post Reply