Someone help me with a very simple script?

Brinson
Posts: 15
Joined: Wed Nov 25, 2009 5:19 am

Someone help me with a very simple script?

Post by Brinson »

I need a script that when it sees a number in a certain range at a certain place in a line, it executes the roll command. The user needs to be able to set this variable. I know nothing of lua, but from my reading the guides I would think I'd want to use a for...but don't know how to do ranges in for statements in lua.

Maybe something like...

for roll = [1..$target]
send("Roll")
echo("Rolling")
else
break
end

But I know that's not right...can someone help me?

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

Re: Someone help me with a very simple script?

Post by Vadi »


User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Someone help me with a very simple script?

Post by Heiko »

If you want help you to provide more details on the exact MUD output and what you want to do in which cases and which variables you want to set and how you'd like them to be set i.e. automatically (trigger/system variables) or by user interaction (alias/button).

Brinson
Posts: 15
Joined: Wed Nov 25, 2009 5:19 am

Re: Someone help me with a very simple script?

Post by Brinson »

I'm going to watch both videos and start trying to write one, but I'll post here while I do.

My line is: [45] Cmds: help, end, roll, add, rem>

I need if 45 is below the variable set by the user, then the script executed the "roll" command. Eventually, I'd like it to tally how many times it has executed the roll command, and what the highest value of [X] that has been achieved is. But the first and most basic thing is to.

1. Have a way for the user to set the variable.
2. Make it so the mud executed roll when it is less than the variable.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Someone help me with a very simple script?

Post by Heiko »

1. trigger that parses the number in your line: "[45] Cmds: help, end, roll, add, rem>"
trigger pattern: \[(\d+)\] Cmds: .*roll.*>
pattern type regex
script:

Code: Select all

local rMax = maxRolls or 0
local t = target or "no target defined"
local r = tonumber( matches[2] )
if r < rMax then
    send("roll" .. t )
end
2. alias to set the variable maxRolls interactively
alias pattern:^maxRolls (\d+)
script:

Code: Select all

maxRolls = tonumber( matches[2] )
echo("setting variable maxRolls=" .. maxRolls .. " OK\n")
3. alias to see the current value of maxRolls:
alias pattern:^maxRolls show"
script:

Code: Select all

echo("The current value of maxRolls=" .. maxRolls .."\n")
4. triggers or aliases to define your variable "target" that is being used in your roll script

That's it.

Brinson
Posts: 15
Joined: Wed Nov 25, 2009 5:19 am

Re: Someone help me with a very simple script?

Post by Brinson »

The aliases seem to work fine, but the trigger doesn't.

Not positive I'm entering it right, so I've included a screenshot. In the back is the pattern I'm trying to match.

http://img121.imageshack.us/img121/1070 ... shotrn.png

It seems to me the trigger isn't matching. It just isn't doing anything.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Someone help me with a very simple script?

Post by Heiko »

remove the space from the beginning of your pattern :D

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

Re: Someone help me with a very simple script?

Post by Vadi »

Also enable anti-aliasing in the main display tab of settings to make fonts look nicer.

Brinson
Posts: 15
Joined: Wed Nov 25, 2009 5:19 am

Re: Someone help me with a very simple script?

Post by Brinson »

Okay, so...I changed it up a bit.

Code: Select all

local rMax = maxRolls or 0
local r = tonumber( matches[2] )
rHigh = rHigh or 0

if r > rHigh then
rHigh = r
end

if r < rMax then
rTot = rTot + 1 or 0
    send("roll")
	 echo("You have rolled ".. rTot .." times with a highest roll of "..rHigh..",")
end
It works fine...I had it working...but then I restarted my client, and now it won't work at all...any idea why?

I'm guessing something to do with variables?

Brinson
Posts: 15
Joined: Wed Nov 25, 2009 5:19 am

Re: Someone help me with a very simple script?

Post by Brinson »

No one have any idea why the script would stop working upon restart of the client?

Post Reply