Flexible Aliases

Post Reply
ixokai
Posts: 63
Joined: Fri Dec 25, 2009 7:43 am

Flexible Aliases

Post by ixokai »

So, I haven't mudded in-- ten thousand years. But I got an email about Midkemia Online, and I'm a Feist fan, so.. Woo.

In the old days when I mudded, I had no real need for macros, but the complexity of the command system on this game, I felt I needed to.

After utterly failing to get anything to work in CMud, I tried Mudlet, and have had a lot of success and have a basic macro system in place which seems to work well.

I was wondering if there was a better way to do it, or if I was making things too complicated :)

To start with, I have a prompt trigger which matches on:

Code: Select all

(\d+)h, +(\d+)e, +(\d+)f (.*)(A: (.*))*-
It executes the following:

Code: Select all

status = { 
	health = tonumber(matches[2]), 
	endurance = tonumber(matches[3]),
	faith = tonumber(matches[4]),
	flags = matches[5],
	balance = true,
	equilibrium = true
}

if string.find(status.flags, "x") ~= nil then
	status.equilibrium = true
else
	status.equilibrium = false
end

if string.find(status.flags, "b") ~= nil then
	status.balance = true
else
	status.balance = false
end
Then I have some boiler-plate functions which are meant to execute certain actions. The first is meant for positive buffs that can target myself-or-a-party-member.

It's basically:

Code: Select all

function get_target2(command, input)
	target = ""
	if matches[1] == command then
		target = "self"
	else
		target = input
	end

	return target
end

function do_buff_prayer(command, input, faith_cost, self_action, other_action)
	target = get_target2(command, input)

	if not status.balance then
		echo("You do not yet have balance.")
	else
		if not status.equilibrium then
				echo("You do not yet have equilibrium.")
		else
			if faith_cost > 0 and status.faith < faith_cost then
				echo("Insufficient faith.")
			else
				if target == "self" then
					self_action()
				else
					other_action(target)
				end
			end
		end
	end
end
An example of this feature is my heal macro, which has a pattern of:

Code: Select all

^h( (.*))*$
And body:

Code: Select all

do_buff_prayer("h", matches[3], 30, 
	function()
		send("pray for healing")
	end,
	function(target)
		send("pray for healing of "..target)
	end
) 
For offensive spells, the boiler-plate is:

Code: Select all

saved_target = ""

function get_target(command, input)
	target = ""
	if matches[1] == command then
		if saved_target ~= "" then
			target = saved_target
		else
 			target = ""
		end
	else
		target = input
	end
	
	return target
end

function do_targeted_prayer(command, input, faith_cost, balance, equilibrium, action)
	target = get_target(command, input)
	if target == "" then
		echo("Target required.")
	else
		if balance and not status.balance then
			echo("You do not yet have balance.")
		else
			if equilibrium and not status.equilibrium then
				echo("You do not yet have equilibrium.")
			else
				if faith_cost > 0 and status.faith < faith_cost then
					echo("Insufficient faith.")
				else
					action(target)
				end
			end
		end
	end
end
There's an additional trigger which saves a particular target into "saved_target" of course.

An example command is a pattern of:

Code: Select all

^f( (.*))*$
And body:

Code: Select all

do_targeted_prayer("f", matches[3], 0, true, false, 
	function(target)
		send("smite "..target.." with fury")
	end
) 
The theory of all of these commands is that they all have an optional argument, and if not given it does the smart thing. For buffs, it targets myself. For attacks, it targets my saved target-- or reports an error if not. I also wanted to put the endurance/balance/faith checks in my code instead of letting the server handle it, since the prompts hit often during combat so the client should have a very up-to-date report of what my resources and status are.

Thoughts? Is there a better way to approach these problems?

Thanks in advance.

User avatar
Vadi
Posts: 4867
Joined: Sat Mar 14, 2009 3:13 pm

Re: Flexible Aliases

Post by Vadi »

Woah, certainly an engineering approach to things. Looks solid though, but can be simplified.

For prompts flags, you can make use of mudlet filters to capture the status. See heikos demo or the achaea GUI for implementation.

For aliases, see a topic I posted on the flexible aliases - people posted good lua one liners there.

Post Reply