Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Multi-variable Alias

Multi-variable Alias

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Terry   USA  (87 posts)  Bio
Date Mon 25 Aug 2008 09:26 PM (UTC)

Amended on Mon 25 Aug 2008 09:27 PM (UTC) by Terry

Message
I was making a plugin to automate botting in Legends of the Jedi. However, there is an alias that I'd really like for it to have two variables in it. Unfortunately, I don't know how to do this. I was wondering if someone else would be able to help out. (It's set to save_state.)
<!--  Triggers  -->
<triggers>
  <trigger
   enabled="y"
   match="You may now bot again."
   name="bot"
   send_to="12"
   sequence="100"
  >
  <send>Send("afk")
botSession = botSession + 1
if bottxt == "" or bottxt == nil then
 Note("You have nothing to bot.)
else
 Send("bot start")
 Send(bottxt)
end -- if</send>
  </trigger>
</triggers>

<!--  Aliases  -->
<aliases>
  <alias
   match="^(d|n)bot( .*?)?$"
   enabled="y"
   group="bot"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>EnableTrigger ("bot", false)
if "%2" == "" then
  arg = "stop"
else
  arg = "cancel"
end -- if
Send ("bot ", arg)</send>
  </alias>
  <alias
   match="^(e|y)bot( )?(.*?)?$"
   enabled="y"
   group="bot"
   variable="bottxt" <!-- I also want `botSessions' here. -->
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>if "%3" == nil then
 if bottxt == nil then
  Note("What is it you want to bot?")
  return
 end -- if
else
 bottxt = "%3"
end -- if
Send ("bot start")
EnableTrigger ("bot", true)
Note ("Botting is now automated.")
Send (bottxt)</send>
  </alias>
  <alias
   match="cbot"
   enabled="y"
   group="bot"
   send_to="12"
   sequence="100"
  >
  <send>Note("You are currently botting: ", bottxt)
if botSessions == 1 then
 Note("You have been botting for 1 session.")
else
 Note("You have been botting for ", botSessions, " sessions.")
end -- if</send>
  </alias>
</aliases>

<!--  Variables  -->
<variables>
  <variable name="bottxt"></variable>
  <!-- botSession variable for ^(e|y)bot( )?(.*?)?$ -->
  <variable name="botSession"></variable>
</variables>
</muclient>

Any help would be greatly appreciated. :)
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 25 Aug 2008 11:40 PM (UTC)
Message
I wouldn't use the <variable> stuff - that is not saved when you serialize things.

You are better off using SetVariable to set a variable (and thus you can set as many as you want) - if you do that they will be saved and restored.

Another approach is to "serialize" all your Lua variables - see this thread:

http://www.gammon.com.au/forum/?id=4960


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Terry   USA  (87 posts)  Bio
Date Reply #2 on Tue 26 Aug 2008 01:35 AM (UTC)

Amended on Tue 26 Aug 2008 01:56 AM (UTC) by Terry

Message
Variables set by SetVariable() can just be queried like any other variable, right? Or would I need to use GetPluginVariable() each time?
Perhaps this should go under a different topic, but would this plugin work if serialized? It increments a variable to decide which to do next, but also increments classes. As you'll see, the table structure is: skills[class][skill]. I was just wondering if this could be serialized and be able to be incremented. If so, how?
<!--  Aliases  -->
<aliases>
  <alias
   match="rstart"
   enabled="y"
   sequence="100"
   send_to="12"
  >
  <send>Send("research ", skills[0][0])
EnableTriggerGroup("research", true)</send>
  </alias>
</aliases>

<!--  Triggers  -->
<triggers>
  <trigger
   enabled="n"
   group="research"
   match="^You\'re not ready to learn that yet\, Sorry\.\.\.\.$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>class = class + 1
skill = 0
if class == 9 then
 Send("afk")
 EnableTriggerGroup("research", false)
 return
elseif skills[class][skill] == nil then
 
end -- if
Send("research ", skills[class][0])</send>
  </trigger>
  <trigger
   enabled="n"
   group="research"
   match="^You can\'t learn (any more )?about that (from books\!|in books\. Go find a teacher\.)$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>if skill == table.getn(skills[class]) then
 class = class + 1
 if skills[class] == nil then
  Send("afk")
  return
 end -- if
 skill = -1
end -- if
skill = skill + 1
Send("research ", skills[class][skill])</send>
  </trigger>
  <trigger
   enabled="n"
   group="research"
   match="^You (study for hours on end\, but fail to gather any knowledge|finish your studies and feel much more skilled)\.$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Send("research ", skills[class][skill])</send>
  </trigger>
</triggers>

<!--  Script  -->
<script>
<![CDATA[
class = 0
skill = 0

skills = {
 -- Combat
 [0] = {
  [ 0] = "grenades",
  [ 1] = "scan",
  [ 2] = "vibro-blades",
  [ 3] = "force pikes",
  [ 4] = "bowcasters",
 },
 -- Piloting
 [1] = {
  [ 0] = "navigation",
  [ 1] = "ship systems",
  [ 2] = "small spacecraft",
  [ 3] = "weapon systems",
  [ 4] = "dock",
 },
 -- Engineering
 [2] = {
  [ 0] = "gather",
  [ 1] = "makecontainer",
  [ 2] = "makecanteen",
  [ 3] = "makecircuit",
  [ 4] = "makeflashlight",
 },
 -- Diplomacy
 [3] = {
   [0] = "smalltalk",
   [1] = "bribe",
   [2] = "setleader",
   [3] = "propaganda",
   [4] = "broadcast",
 },
 -- Leadership
 [4] = {
  [0] = "teach",
  [1] = "jail",
  [2] = "call",
  [3] = "torture",
 },
 -- Espionage
 [5] = {
  [ 0] = "duplicate",
  [ 1] = "swipe",
  [ 2] = "tail",
  [ 3] = "conceal",
  [ 4] = "sabotage",
 },
 -- Slicer
 [6] = {
  [ 0] = "showplanet",
  [ 1] = "showclan",
  [ 2] = "lookup",
  [ 3] = "remodulate",
  [ 4] = "short",
 },
 -- Medical
 [7] = {
  [ 0] = "aid",
  [ 1] = "first aid",
  [ 2] = "diagnose",
  [ 3] = "makemedpac",
  [ 4] = "revive",
 },
 -- Science
 [8] = {
  [ 0] = "ponder",
  [ 1] = "advanced electronic",
  [ 2] = "chemistry",
  [ 3] = "construction",
  [ 4] = "data",
 },
}
]]>
</script>
(Because of the length of the table, I cut it down to just 5 parts when I copied it over to here, though it is CERTAINLY longer. ;P) What I have been trying to do before, but have been unable, is make another table like below that would hold the progress of the different classes, and then start where they left off next time.
researched = {
 [0] = 0,
 [1] = 0,
-- etc
}
The plugin would just change researched[class] to `skill' each time "^You can\'t learn (any more )?about that (from books\!|in books\. Go find a teacher\.)$" was matched.
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #3 on Tue 26 Aug 2008 03:19 AM (UTC)
Message
Inside a plugin, GetVariable and SetVariable get and set that plugin's variables.

Quote:

What I have been trying to do before, but have been unable, is make another table like below that would hold the progress of the different classes ...


In what way have you been unable to do it?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


14,257 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.