Balance and Equilibrium checker

Share your scripts and packages with other Mudlet users.
Post Reply
Mordocai
Posts: 3
Joined: Sat Dec 05, 2009 6:21 am

Balance and Equilibrium checker

Post by Mordocai »

I would like to set up a generic function that will check for balance/equilibrium then, if i don't have it, wait until it comes back and then continue with the alias/trigger/whatever that called the function. I have triggers to set variables bal and equil to 0 when i use it and 1 when it's recovered. However, if i do a simple loop that loops and does nothing until bal or equil = 1, It basically just assumes it is 1 and goes on.

I can't show what i've tried because copying from mudlet doesn't work on my system, but i was wondering if anyone could show me how to do this.

Thanks,
Mordocai

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

Re: Balance and Equilibrium checker

Post by Vadi »

Well, this is possible... but are you sure you want to go with this architecture? I can see it being messy when things start getting queued up / not finishing in time and etc.

The typical way to do this is to have your triggers set flags for the actions you'd need to do, and when you get both balance and eq back, run a check over all the flags, and do the things you need.

ie, when you fall down, you do

prone = 1

and when you get balance or eq back, you'd to this:

Code: Select all

if balance ~= true and equilibrium ~= true then return end

if prone == 1 then
    send ('stand')
end

Mordocai
Posts: 3
Joined: Sat Dec 05, 2009 6:21 am

Re: Balance and Equilibrium checker

Post by Mordocai »

So, would i have a trigger that goes off when i get my equilibrium/balance back and then checks to see what it needs to do based on variables set by other triggers? I'm sorry, fairly new to coding in general... and really new to coding for a MUD.

Mordocai
Posts: 3
Joined: Sat Dec 05, 2009 6:21 am

Re: Balance and Equilibrium checker

Post by Mordocai »

By the way, i originally came up with this because i wanted one alias that would set up all my defenses in order and not have to be run multiple times.

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

Re: Balance and Equilibrium checker

Post by Vadi »

So, would i have a trigger that goes off when i get my equilibrium/balance back and then checks to see what it needs to do based on variables set by other triggers?
Yep.
By the way, i originally came up with this because i wanted one alias that would set up all my defenses in order and not have to be run multiple times.
Well that's a nice idea, but what if you want to pause the defup? And how will the alias not defup stuff you already have? and such :)

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Balance and Equilibrium checker

Post by Iocun »

If it's really just for a defup alias and isn't supposed to keep defences up all the time, then a coroutine might be a suitable implementation for this, yes? (I'm may be wrong since I'm a total Lua noob and only learned about coroutines yesterday :P). Start with the defup, after putting up the first defence, yield and wait till you get balance or equilibrium back, then resume the coroutine, and repeat this for all defs. This would also allow you to pause it.

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

Re: Balance and Equilibrium checker

Post by Vadi »

Heh, well... having an alias that has a whole bunch of ifs and yields instead of if, elseifs would do I guess. But unfortunately Mudlet doesn't support coroutines yet, it requires some special implementations which we'll get to later.

Caled
Posts: 403
Joined: Thu Apr 09, 2009 4:45 am

Re: Balance and Equilibrium checker

Post by Caled »

Assuming this is for an IRE mud.

In your prompt trigger, capture the part of your prompt stats that tells you whether you have balance/equilibrium or not. For example, the bolded part:

[pcsdb eb]
or for Lusternia:
-ex

You want to match the eb, --, e- and -b
Use: ([eb-]{2}) in the appropriate part of your prompt trigger pattern.

In your prompt script:

Code: Select all

eqbal = matches[5] -- assuming "5" is the capture group the above matches

-- Check if time to raise onEqbal --
if eqbalcheck == 1 then
	eqbalCall()
end
In a script object:

Code: Select all

eqbalcheck = 0

function eqbalCheck()
	x=0
	if eqbal == "eb" then x=1 end
	return x
end

function eqbalCall()
	if eqbalCheck() == 1 then
		eqbalcheck = 0
		onEqbal()
	end
end

function onEqbal()
        -- here you have your commands to check for actions that require balance/eq, such as lighting pipes, ordering entities, blah blah

        -- here you have your commands to check for actions that require and use balance, like rejecting people, or putting back critical defences such as spirit bonding

        -- here you have your commands to execute actions from a queue, such as your next attack.

end

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

Re: Balance and Equilibrium checker

Post by Vadi »

another way to do it, the 'mudlet' way: http://forums.imperian.com/index.php?sh ... t&p=392581

Post Reply