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 ➜ General ➜ zmud script -> lua scripting

zmud script -> lua scripting

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


Posted by Brianz19   (11 posts)  Bio
Date Tue 26 Sep 2006 12:38 AM (UTC)
Message
#TRIGGER {By what name do you wish to be known?} {#var charged 0;#var clumsycharge 0;#var totalcharge 0;#var totalstabs 0;#var stabland 0;#var stabclumsy 0;#var missbash 0;#var totalbash 0;#var landbash 0;#ECho totalchargecount set on @totalcharge.;#echo clumsycharge set at @clumsycharge.;#echo charged set at @charged.;#echo stabland set at @stabland;#echo stabclumsy set at @stabclumsy;#echo totalstabs set at @totalstabs;#echo landbash set at @landbash;#echo totalbash set at @totalbash;#echo missbash set at @missbash}
#Class {Clumsylog}
#var missbash {0}
#var landbash {0}
#var totalbash {0}
#var stabpercentage {0}
#TRIGGER {Your bash at %1 sprawling!} {#MATH landbash @landbash+1;#math totalbash @landbash+@missbash;#math bashpercentage (@landbash*100 / @totalbash);#Echo This session you've landed @landbash out of @totalbash bashes (@bashpercentage~% landed)}
#TRIGGER {As %1 your bash, you topple over and fall to the ground!} {#math missbash @missbash+1;#math totalbash @landbash+@missbash;#math bashpercentage (@landbash*100 / @totalbash);#Echo This session you've missed @missbash out of @totalbash bashes (@bashpercentage~% landed)}
#class 0

someone that plays my mud made this script for checkin out %s on landing certain things like stabs/charges/bashes. was wondering if anyone could convert this zmud script (i think) to work with mushclient?
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #1 on Tue 26 Sep 2006 02:27 PM (UTC)

Amended on Tue 26 Sep 2006 02:33 PM (UTC) by Onoitsu2

Message
for one i see a typo on the word stabpercentage, should have been bashpercentage, and here is a plugin made in LUA that does the same things, plus a little more...

Quote:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Tuesday, September 26, 2006, 8:07 AM -->
<!-- MuClient version 3.74 -->

<!-- Plugin "Bash_Count" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Bash_Count"
   author="Onoitsu2"
   purpose="Aardwolf Character Remote Control"
   id="ef7b51a530d14a60ff921054"
   language="Lua"
   save_state="y"
   date_written="2006-9-26 7:05:07"
   requires="3.74"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Bash_Count Plugin LUA
bashcount      - displays current sucessful bashes, missed bashes, total bashes attempted, and percentage landed
bashcount help - displays this help file
]]>
</description>

</plugin>

<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="^By what name do you wish to be known\?$"
   regexp="y"
   script="bashreset"
   send_to="12"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="^Your bash at (.*?) sprawling\!$"
   regexp="y"
   script="landbash"
   send_to="12"
   sequence="100"
  >
  </trigger>
  <trigger
   enabled="y"
   match="^As (.*?) your bash\, you topple over and fall to the ground\!$"
   regexp="y"
   script="missbash"
   send_to="12"
   sequence="100"
  >
  </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   match="^bashcount$"
   enabled="y"
   group="bashcount"
   regexp="y"
   script="bashreport"
   send_to="12"
   omit_from_output="y"
   ignore_case="y"
   sequence="100"
  >
  </alias>
</aliases>


<!--  Plugin help  -->

<aliases>
  <alias
   ignore_case="y"
   script="OnHelp"
   match="bashcount help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
function bashreport(sName,sLine,wildcards)
Note("This session you've landed " .. GetVariable("landbash") .. " out of " .. GetVariable("totalbash") .. " bashes (" .. GetVariable("bashpercentage") .. "% landed)")
Note("This session you've missed " .. GetVariable("missbash") .. " out of " .. GetVariable("totalbash") .. " bashes (" .. 100 - tonumber(GetVariable("bashpercentage")) .. "% missed)")
end -- bashreport

function bashreset(sName,sLine,wildcards)
SetVariable("landbash",0)
SetVariable("missbash",0)
SetVariable("totalbash",0)
SetVariable("bashpercentage",0)
SaveState()
end -- bashreset

function landbash(sName,sLine,wildcards)
local landedbashes
local totalbashes
landedbashes = tonumber(GetVariable("landbash")) + 1
totalbashes = tonumber(GetVariable("totalbash")) + 1
SetVariable("lansbash",landedbashes)
SetVariable("totalbash",totalbashes)
Note("This session you've landed " .. GetVariable("landbash") .. " out of " .. GetVariable("totalbash") .. " bashes (" .. GetVariable("bashpercentage") .. "% landed)")
end -- landbash

function missbash(sName,sLine,wildcards)
local missedbashes
local totalbashes
missedbashes = tonumber(GetVariable("missbash")) + 1
totalbashes = tonumber(GetVariable("totalbash")) + 1
SetVariable("missbash",missedbashes)
SetVariable("totalbash",totalbashes)
Note("This session you've missed " .. GetVariable("missbash") .. " out of " .. GetVariable("totalbash") .. " bashes (" .. GetVariable("bashpercentage") .. "% landed)")
end -- missbash

function OnPluginInstall()
OnHelp()
if GetVariable("landbash") == nil then
SetVariable("landbash",0)
end -- if
if GetVariable("missbash") == nil then
SetVariable("missbash",0)
end -- if
if GetVariable("totalbash") == nil then
SetVariable("totalbash",0)
end -- if
if GetVariable("bashpercentage") == nil then
SetVariable("bashpercentage",0)
end -- if
SaveState()
end

function OnHelp ()
  world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end
]]>
</script> 

</muclient>


I know this could have been done a little simpler, with using inside trigger processing, and leaving out the help, and onplugininstall, but I have a standard plugin layout in all the plugins I create, they all typically use out of the trigger or alias functions, even if it is something simple like showing 2 notes, so I can easily replace it just by replacing the desired function.

Laterzzz,
Onoitsu2
Top

Posted by Brianz19   (11 posts)  Bio
Date Reply #2 on Wed 27 Sep 2006 03:55 AM (UTC)
Message
i did that, but when i hit bashes it counts as a miss..
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #3 on Wed 27 Sep 2006 08:26 AM (UTC)
Message
I had a typo within it


function landbash(sName,sLine,wildcards)
local landedbashes
local totalbashes
landedbashes = tonumber(GetVariable("landbash")) + 1
totalbashes = tonumber(GetVariable("totalbash")) + 1
====SetVariable("lansbash",landedbashes)
SetVariable("totalbash",totalbashes)
Note("This session you've landed " .. GetVariable("landbash") .. " out of " .. GetVariable("totalbash") .. " bashes (" .. GetVariable("bashpercentage") .. "% landed)")
end -- landbash


the line beginning with the equal siigns should be...
SetVariable("landbash",landedbashes)

I had an S in place of the D in the first "land"

That will fix the problem I believe.

Laterzzz,
Onoitsu2
Top

Posted by Vallick   USA  (14 posts)  Bio
Date Reply #4 on Wed 29 Nov 2006 11:20 PM (UTC)
Message
Ive got to say thats a really nice script/idea there. I notice thats really close to jscript (right?) I think when I get further down the road I might modifie for arctic.


Nice programming.

Vallick Arc'Haven,
Member of the Solamnic Knighthood,
Krynn, Anaslon
(longuriel@yahoo.com)
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #5 on Thu 30 Nov 2006 03:21 AM (UTC)

Amended on Thu 30 Nov 2006 03:23 AM (UTC) by Nick Gammon

Message
It's Lua, but easy enough to understand if you know other programming languages, and easy to learn anyway. :)

Onoitsu2, you can save yourself a bit of typing by using the "var" idea, where you can replace:


landedbashes = tonumber(GetVariable("landbash")) + 1


by:


landedbashes = tonumber(var.landbash) + 1


Similarly, replace:


SetVariable("landbash",landedbashes)


by:


var.landbash = landedbashes



You can automate that entire process by using the internal Notepad's Search -> Global Replace dialog, in 2 steps (one for getting a variable, and one for setting it):


Find pattern: GetVariable%s*%(%s*"([%a%d_]+)"%s*%)
Replacement:  var.%1

Find pattern: SetVariable%s*%(%s*"([%a%d_]+)"%s*,(.*)%)
Replacement: var.%1 = %2


For example, after running those 2 replacements, one of your functions now looks like this:


require "var" -- pull in the "var" code

function missbash(sName,sLine,wildcards)
local missedbashes
local totalbashes
missedbashes = tonumber(var.missbash) + 1
totalbashes = tonumber(var.totalbash) + 1
var.missbash = missedbashes
var.totalbash = totalbashes
Note("This session you've missed " .. var.missbash .. " out of " .. var.totalbash .. " bashes (" .. var.bashpercentage .. "% landed)")
end -- missbash


- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #6 on Thu 30 Nov 2006 03:28 AM (UTC)
Message
You can also save a bit of typing, as Lua automatically coerces strings into numbers where required, eg.


missedbashes = tonumber(var.missbash) + 1


... can become:


missedbashes = var.missbash + 1


Having got that far, you can eliminate the local variables altogether:


function missbash(sName,sLine,wildcards)
var.missbash = var.missbash + 1
var.totalbash = var.totalbash + 1
Note("This session you've missed " .. var.missbash .. " out of " .. var.totalbash .. " bashes (" .. var.bashpercentage .. "% landed)")
end -- missbash


Thus you have just saved a lot of typing. :)

- Nick Gammon

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

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #7 on Sat 02 Dec 2006 06:23 AM (UTC)
Message
I am using 3.74 still, and somewhat do not wish to upgrade and use all of those additional libraries, as MANY of my plugin users, use versions 3.74 - 3.78, typically at least, probably 3 of the 20 or so constantly get the latest version of MC.

But thanks for the tip, if I can ever convince ALL of the users of my plugins to upgrade then I will change my methods. But that is probably not going to happen, cause they were lucky to have been able to install the version used at all, due to several using it in their workplaces, and others from college campuses, which do not allow installer programs to be run via 3rd party software.

Laterzzz,
Onoitsu2
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #8 on Sat 02 Dec 2006 07:36 AM (UTC)
Message
Disclaimer: I haven't been fully following this conversation. However, I'm not sure how Nick's suggestion is dependent on a version of MUSHclient. It's just a basic rephrasing of the Lua code, and doesn't use new libraries. Why would it require an upgrade?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Nick Gammon   Australia  (23,120 posts)  Bio   Forum Administrator
Date Reply #9 on Sat 02 Dec 2006 08:10 AM (UTC)
Message
You are right, that technique has always been available. The later versions make it easy to put into a separate file, but by incorporating a short function into your existing scripts you can use it in all of them. See this post for a description of the original idea:

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

- 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.


29,034 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.