Difference between revisions of "User:Hsima"

From Mudlet
Jump to navigation Jump to search
(Created page with "This is an extended example of how to convert a mushclient plugin file to a mudlet script to expand on the notes in Manual:Migrating. The bits in "script" tags should wor...")
 
m
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
This is an extended example of how to convert a mushclient plugin file to a mudlet script to expand on the notes in [[Manual:Migrating]].
 
This is an extended example of how to convert a mushclient plugin file to a mudlet script to expand on the notes in [[Manual:Migrating]].
  
The bits in "script" tags should work more or less directly, at least from a lua stand point.
+
It will take a bit of refactoring as the way things work is a little different from my limited experience.
 +
A "script" in mudlet runs once (or if someone goes and clicks on it or otherwise activates it later) so they're best used for initialization and global scope function definition
  
 
<pre>
 
<pre>
Line 178: Line 179:
 
</muclient>
 
</muclient>
 
</pre>
 
</pre>
<pre>
 
  
So an equivalent mudlet script would look something like this
+
So an equivalent mudlet package file would look something like this
  
<pre>
+
<syntaxhighlight lang="xml">
 
+
<?xml version="1.0" encoding="UTF-8"?>
So an equivalent mudlet script would look something like this
+
<!DOCTYPE MudletPackage>
 
+
<MudletPackage version="1.001">
<pre>
+
<ScriptPackage>
 
+
<Script isActive="yes" isFolder="no">
if exists("Cleric Aliases", "alias") == 0 then
+
<name>Cleric Script</name>
  permGroup("Cleric aliases", "alias")
+
<packageName>Cleric3k</packageName>
end
+
<script>
if exists("Cleric Triggers", "trigger") == 0 then
+
-- General initialization, this will happen once when the client starts and if someone goes in and clicks on it for some reason
  permGroup("Cleric triggers", "trigger")
+
-- "I'd wrap that in a block not to re-initialise if already initialised, else someone is in for a nasty surprise when they open the script and all the values get reset" -- Vadi
end
+
-- So I did that.
if exists("Guild Scripts", "script") == 0 then
+
   curelimit = curelimit or .7
  permGroup("Guild Scripts", "script")
+
   heallimit = heallimit or .8
end
+
   retlimit = retlimit or .9
 
+
   lflimit = lflimit or 10
if exists("Cleric Script", "script") == 0 then
 
  permScript("Cleric Script", "Guild Scripts", [[
 
   curelimit = .9
 
   heallimit = .8
 
 
 
   retlimit = .9
 
 
 
   lflimit = 10
 
  
   nuking = true
+
   nuking = nuking or true
   autolf = true
+
   autolf = autolf or true
 
    
 
    
   mygxp = 0
+
   mygxp = mygxp or 0
   lastgxp = 0
+
   lastgxp = lastgxp or 0
   deltagxp = 0
+
   deltagxp = deltagxp or 0
  
 
   function SendNoEcho(stuff)
 
   function SendNoEcho(stuff)
Line 222: Line 214:
 
mygxp = thisGXP
 
mygxp = thisGXP
 
deltagxp = lastgxp - mygxp
 
deltagxp = lastgxp - mygxp
Note("This round gxp: ", mygxp, " Last round: ", lastgxp, " Delta: ", deltagxp)
+
echo("\nThis round gxp: " .. mygxp .. " Last round: " .. lastgxp .. " Delta: " .. deltagxp)
  end
 
 
 
  function doCorpseStuff()
 
  SendNoEcho("lifeforce corpse")
 
SendNoEcho("wrap corpse")
 
SendNoEcho("get gold from corpse")
 
SendNoEcho("eat corpse")
 
SendNoEcho("split")
 
BroadcastPlugin("1", "Something Died.")
 
 
   end
 
   end
  
]])
+
</script>
end
+
<eventHandlerList />
enableScript("Cleric Script")
+
</Script>
 
+
</ScriptPackage>
if exists("nuking", "alias") == 0 then
+
<TriggerPackage>
permAlias("nuking", "Cleric Aliases", "^nuking$", [[
+
<Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
if (nuking) then
+
<name>Cleric HP Trigger</name>
echo("Nuking disabled.")
+
<script>
nuking = false;
 
else
 
echo("Nuking enabled.")
 
nuking = true;
 
end
 
]])
 
end
 
  
if exists("nuking", "alias") == 0 then
 
permAlias("autolf", "Cleric Aliases", "^autolf$", [[
 
        if (autolf) then
 
echo("Autolf disabled.")
 
nuking = false;
 
else
 
echo("Autolf enabled.")
 
nuking = true;
 
end
 
]])
 
end
 
 
if exists("Cleric Prompt", "trigger") == 0 then
 
permRegexTrigger("Cleric Prompt", "Cleric triggers", {"^HP: (\d+)/(\d+)  Mana: (\d+)/(\d+)  Will: (\d+)/(\d+)  G2L: (\d+)"}, [[ 
 
 
curhp = tonumber(matches[2])
 
curhp = tonumber(matches[2])
 
maxhp = tonumber(matches[3])
 
maxhp = tonumber(matches[3])
Line 280: Line 242:
 
addGXP( string.match( hpstub, "%d+" ) )
 
addGXP( string.match( hpstub, "%d+" ) )
  
if (hpper &lt; heallimit) then  
+
if (hpper &lt; heallimit) then  
<!-- Switch heal for cure until glev 50 -->
+
-- Switch heal for cure until glev 50
<!--SendNoEcho("cure")-->
+
-- SendNoEcho("cure")
 
SendNoEcho("heal")
 
SendNoEcho("heal")
 
return
 
return
Line 320: Line 282:
 
return
 
return
 
end
 
end
end
+
end</script>
]])
+
<triggerType>0</triggerType>
end
+
<conditonLineDelta>0</conditonLineDelta>
 
+
<mStayOpen>0</mStayOpen>
if exists("Cleric Corpse Trigger", "trigger") == 0 then
+
<mCommand></mCommand>
permRegexTrigger("Corpse Trigger", "Cleric triggers", {"dealt the killing blow to"}, [[ doCorpseStuff() ]])
+
<packageName>Cleric3k</packageName>
end
+
<mFgColor>#ff0000</mFgColor>
</pre>
+
<mBgColor>#ffff00</mBgColor>
 +
<mSoundFile></mSoundFile>
 +
<colorTriggerFgColor>#000000</colorTriggerFgColor>
 +
<colorTriggerBgColor>#000000</colorTriggerBgColor>
 +
<regexCodeList>
 +
<string>HP: (\d+)\/(\d+)  Mana: (\d+)\/(\d+)  Will: (\d+)\/(\d+)  G2L: (.*)</string>
 +
</regexCodeList>
 +
<regexCodePropertyList>
 +
<integer>1</integer>
 +
</regexCodePropertyList>
 +
</Trigger>
 +
<Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
 +
<name>Cleric Corpse Trigger</name>
 +
<script>if (matches[2] == 'Isham') then
 +
  send("lifeforce corpse",false)
 +
  send("wrap corpse",false)
 +
  send("get gold from corpse",false)
 +
  send("eat corpse",false)
 +
  send("split",false)
 +
end</script>
 +
<triggerType>0</triggerType>
 +
<conditonLineDelta>0</conditonLineDelta>
 +
<mStayOpen>0</mStayOpen>
 +
<mCommand></mCommand>
 +
<packageName></packageName>
 +
<mFgColor>#ff0000</mFgColor>
 +
<mBgColor>#ffff00</mBgColor>
 +
<mSoundFile></mSoundFile>
 +
<colorTriggerFgColor>#000000</colorTriggerFgColor>
 +
<colorTriggerBgColor>#000000</colorTriggerBgColor>
 +
<regexCodeList>
 +
<string>(\w+) dealt the killing blow to</string>
 +
</regexCodeList>
 +
<regexCodePropertyList>
 +
<integer>1</integer>
 +
</regexCodePropertyList>
 +
</Trigger>
 +
</TriggerPackage>
 +
<KeyPackage>
 +
<KeyGroup isActive="yes" isFolder="yes">
 +
<name>Keypad</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command></command>
 +
<keyCode>-1</keyCode>
 +
<keyModifier>-1</keyModifier>
 +
<Key isActive="yes" isFolder="no">
 +
<name>keypad7</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>northwest</command>
 +
<keyCode>55</keyCode>
 +
<keyModifier>536870912</keyModifier>
 +
</Key>
 +
<Key isActive="yes" isFolder="no">
 +
<name>keypad8</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>north</command>
 +
<keyCode>56</keyCode>
 +
<keyModifier>536870912</keyModifier>
 +
</Key>
 +
<Key isActive="yes" isFolder="no">
 +
<name>keypad4</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>west</command>
 +
<keyCode>52</keyCode>
 +
<keyModifier>536870912</keyModifier>
 +
</Key>
 +
<Key isActive="yes" isFolder="no">
 +
<name>keypad9</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>northeast</command>
 +
<keyCode>57</keyCode>
 +
<keyModifier>536870912</keyModifier>
 +
</Key>
 +
<Key isActive="yes" isFolder="no">
 +
<name>keypad1</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>southwest</command>
 +
<keyCode>49</keyCode>
 +
<keyModifier>536870912</keyModifier>
 +
</Key>
 +
<Key isActive="yes" isFolder="no">
 +
<name>keypad2</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>south</command>
 +
<keyCode>50</keyCode>
 +
<keyModifier>536870912</keyModifier>
 +
</Key>
 +
<Key isActive="yes" isFolder="no">
 +
<name>keypad3</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>southeast</command>
 +
<keyCode>51</keyCode>
 +
<keyModifier>536870912</keyModifier>
 +
</Key>
 +
<Key isActive="yes" isFolder="no">
 +
<name>keypad5</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>kill zombie</command>
 +
<keyCode>53</keyCode>
 +
<keyModifier>536870912</keyModifier>
 +
</Key>
 +
<Key isActive="yes" isFolder="no">
 +
<name>keypad6</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>east</command>
 +
<keyCode>54</keyCode>
 +
<keyModifier>536870912</keyModifier>
 +
</Key>
 +
<Key isActive="yes" isFolder="no">
 +
<name>minuskeypad</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>up</command>
 +
<keyCode>-1</keyCode>
 +
<keyModifier>-1</keyModifier>
 +
</Key>
 +
<Key isActive="yes" isFolder="no">
 +
<name>pluskeypad</name>
 +
<packageName>Cleric3k</packageName>
 +
<script></script>
 +
<command>down</command>
 +
<keyCode>-1</keyCode>
 +
<keyModifier>-1</keyModifier>
 +
</Key>
 +
</KeyGroup>
 +
</KeyPackage>
 +
</MudletPackage>
 +
</syntaxhighlight>

Latest revision as of 22:58, 24 May 2020

This is an extended example of how to convert a mushclient plugin file to a mudlet script to expand on the notes in Manual:Migrating.

It will take a bit of refactoring as the way things work is a little different from my limited experience. A "script" in mudlet runs once (or if someone goes and clicks on it or otherwise activates it later) so they're best used for initialization and global scope function definition

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, October 17, 2013, 8:41 AM -->
<!-- MuClient version 4.84 -->

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

<muclient>
<plugin
   name="clericbot"
   id="b267d5e95e94e68e3c064a6f"
   language="lua"
   date_written="2013-10-17 08:41:39"
   requires="4.84"
   version="1.0"
   >

</plugin>

<script>
  curelimit = .9
  heallimit = .8

  retlimit = .9

  lflimit = 10

  nuking = true
  autolf = true
  
  mygxp = 0
  lastgxp = 0
  deltagxp = 0

  function addGXP(thisGXP)
	lastgxp = mygxp
	mygxp = thisGXP
	deltagxp = lastgxp - mygxp
	Note("This round gxp: ", mygxp, " Last round: ", lastgxp, " Delta: ", deltagxp)
  end
  
  function doCorpseStuff()
  	SendNoEcho("lifeforce corpse")
	SendNoEcho("wrap corpse")
	SendNoEcho("get gold from corpse")
	SendNoEcho("eat corpse")
	SendNoEcho("split")
	BroadcastPlugin("1", "Something Died.")
  end
</script>
<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="HP: */*  Mana: */*  Will: */*  G2L: *"
   send_to="12"
   sequence="100"
  >
  <send>
curhp = %1
maxhp = %2
hpper = curhp/maxhp

curmana = %3
maxmana = %4
manaper = curmana/maxmana

curwill = %5
maxwill = %6
willper = curwill/maxwill

hpstub = "%7"

addGXP( string.match( hpstub, "%d+" ) )

if (hpper < heallimit) then 
	<!-- Switch heal for cure until glev 50 -->
	<!--SendNoEcho("cure")-->
	SendNoEcho("heal")
	return
end

if ((hpper < curelimit) and (hpper > heallimit)) then
	SendNoEcho("cure")
	return
end

shieldup = string.find(hpstub, "DS:")
if (not shieldup) then
	SendNoEcho("divine shield")
	return
end

blessed = string.find(hpstub, "B:")
if (not blessed) then
	SendNoEcho("blessing")
	return
end

incombat = string.find(hpstub, "T:")
if (nuking and incombat and manaper > retlimit) then 
	SendNoEcho("hw")
	return
end


lfon = string.match(hpstub, '%b()')
if (lfon) then
	lfperstring = string.sub(lfon, string.find(lfon, '%d+'))
	if(autolf and tonumber(lfperstring) < 10) then
		SendNoEcho("unwrap")
		SendNoEcho("lifeforce corpse")
		lfon=false
		return
	end
end


   </send>
  </trigger>
<trigger
 enabled="y"
 match="* dealt the killing blow to *"
 send_to="12"
 sequence="100"
 >
 <send>
 doCorpseStuff()
 </send>
</trigger>

</triggers>
<aliases>
  <alias
   match="nuking"
   enabled="y"
   sequence="100"
   send_to="12"
  >
  <send>
	if (nuking) then
		Note("Nuking disabled.")
		nuking = false;
	else 
		Note("Nuking enabled.")
		nuking = true;
	end
  </send>
</alias>
  <alias
   match="autolf"
   enabled="y"
   sequence="100"
   send_to="12"
  >
  <send>
	if (autolf) then
		Note("Autolf disabled.")
		nuking = false;
	else 
		Note("Autolf enabled.")
		nuking = true;
	end
  </send>
</alias>
</aliases>

</muclient>

So an equivalent mudlet package file would look something like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MudletPackage>
<MudletPackage version="1.001">
<ScriptPackage>
<Script isActive="yes" isFolder="no">
<name>Cleric Script</name>
<packageName>Cleric3k</packageName>
<script>
-- General initialization, this will happen once when the client starts and if someone goes in and clicks on it for some reason
-- "I'd wrap that in a block not to re-initialise if already initialised, else someone is in for a nasty surprise when they open the script and all the values get reset" -- Vadi
-- So I did that.
  curelimit = curelimit or .7
  heallimit = heallimit or .8
  retlimit = retlimit or .9
  lflimit = lflimit or 10

  nuking = nuking or true
  autolf = autolf or true
  
  mygxp = mygxp or 0
  lastgxp = lastgxp or 0
  deltagxp = deltagxp or 0

  function SendNoEcho(stuff)
    send(stuff, false)
  end

  function addGXP(thisGXP)
	lastgxp = mygxp
	mygxp = thisGXP
	deltagxp = lastgxp - mygxp
	echo("\nThis round gxp: " .. mygxp .. " Last round: " .. lastgxp .. " Delta: " .. deltagxp)
  end

</script>
<eventHandlerList />
</Script>
</ScriptPackage>
	<TriggerPackage>
		<Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
			<name>Cleric HP Trigger</name>
			<script>

curhp = tonumber(matches[2])
maxhp = tonumber(matches[3])
hpper = curhp/maxhp

curmana = tonumber(matches[4])
maxmana = tonumber(matches[5])
manaper = curmana/maxmana

curwill = tonumber(matches[6])
maxwill = tonumber(matches[7])
willper = curwill/maxwill

hpstub = matches[8]

addGXP( string.match( hpstub, "%d+" ) )

if (hpper &lt;  heallimit) then 
	-- Switch heal for cure until glev 50
	-- SendNoEcho("cure")
	SendNoEcho("heal")
	return
end

if ((hpper &lt; curelimit) and (hpper &gt; heallimit)) then
	SendNoEcho("cure")
	return
end

shieldup = string.find(hpstub, "DS:")
if (not shieldup) then
	SendNoEcho("divine shield")
	return
end

blessed = string.find(hpstub, "B:")
if (not blessed) then
	SendNoEcho("blessing")
	return
end

incombat = string.find(hpstub, "T:")
if (nuking and incombat and manaper &gt; retlimit) then 
	SendNoEcho("hw")
	return
end


lfon = string.match(hpstub, '%b()')
if (lfon) then
	lfperstring = string.sub(lfon, string.find(lfon, '%d+'))
	if(autolf and tonumber(lfperstring) &lt; 10) then
		SendNoEcho("unwrap")
		SendNoEcho("lifeforce corpse")
		lfon=false
		return
	end
end</script>
			<triggerType>0</triggerType>
			<conditonLineDelta>0</conditonLineDelta>
			<mStayOpen>0</mStayOpen>
			<mCommand></mCommand>
			<packageName>Cleric3k</packageName>
			<mFgColor>#ff0000</mFgColor>
			<mBgColor>#ffff00</mBgColor>
			<mSoundFile></mSoundFile>
			<colorTriggerFgColor>#000000</colorTriggerFgColor>
			<colorTriggerBgColor>#000000</colorTriggerBgColor>
			<regexCodeList>
				<string>HP: (\d+)\/(\d+)  Mana: (\d+)\/(\d+)  Will: (\d+)\/(\d+)  G2L: (.*)</string>
			</regexCodeList>
			<regexCodePropertyList>
				<integer>1</integer>
			</regexCodePropertyList>
		</Trigger>
		<Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
			<name>Cleric Corpse Trigger</name>
			<script>if (matches[2] == 'Isham') then
  send("lifeforce corpse",false)
  send("wrap corpse",false)
  send("get gold from corpse",false)
  send("eat corpse",false)
  send("split",false)
end</script>
			<triggerType>0</triggerType>
			<conditonLineDelta>0</conditonLineDelta>
			<mStayOpen>0</mStayOpen>
			<mCommand></mCommand>
			<packageName></packageName>
			<mFgColor>#ff0000</mFgColor>
			<mBgColor>#ffff00</mBgColor>
			<mSoundFile></mSoundFile>
			<colorTriggerFgColor>#000000</colorTriggerFgColor>
			<colorTriggerBgColor>#000000</colorTriggerBgColor>
			<regexCodeList>
				<string>(\w+) dealt the killing blow to</string>
			</regexCodeList>
			<regexCodePropertyList>
				<integer>1</integer>
			</regexCodePropertyList>
		</Trigger>
	</TriggerPackage>
	<KeyPackage>
		<KeyGroup isActive="yes" isFolder="yes">
			<name>Keypad</name>
			<packageName>Cleric3k</packageName>
			<script></script>
			<command></command>
			<keyCode>-1</keyCode>
			<keyModifier>-1</keyModifier>
			<Key isActive="yes" isFolder="no">
				<name>keypad7</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>northwest</command>
				<keyCode>55</keyCode>
				<keyModifier>536870912</keyModifier>
			</Key>
			<Key isActive="yes" isFolder="no">
				<name>keypad8</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>north</command>
				<keyCode>56</keyCode>
				<keyModifier>536870912</keyModifier>
			</Key>
			<Key isActive="yes" isFolder="no">
				<name>keypad4</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>west</command>
				<keyCode>52</keyCode>
				<keyModifier>536870912</keyModifier>
			</Key>
			<Key isActive="yes" isFolder="no">
				<name>keypad9</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>northeast</command>
				<keyCode>57</keyCode>
				<keyModifier>536870912</keyModifier>
			</Key>
			<Key isActive="yes" isFolder="no">
				<name>keypad1</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>southwest</command>
				<keyCode>49</keyCode>
				<keyModifier>536870912</keyModifier>
			</Key>
			<Key isActive="yes" isFolder="no">
				<name>keypad2</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>south</command>
				<keyCode>50</keyCode>
				<keyModifier>536870912</keyModifier>
			</Key>
			<Key isActive="yes" isFolder="no">
				<name>keypad3</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>southeast</command>
				<keyCode>51</keyCode>
				<keyModifier>536870912</keyModifier>
			</Key>
			<Key isActive="yes" isFolder="no">
				<name>keypad5</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>kill zombie</command>
				<keyCode>53</keyCode>
				<keyModifier>536870912</keyModifier>
			</Key>
			<Key isActive="yes" isFolder="no">
				<name>keypad6</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>east</command>
				<keyCode>54</keyCode>
				<keyModifier>536870912</keyModifier>
			</Key>
			<Key isActive="yes" isFolder="no">
				<name>minuskeypad</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>up</command>
				<keyCode>-1</keyCode>
				<keyModifier>-1</keyModifier>
			</Key>
			<Key isActive="yes" isFolder="no">
				<name>pluskeypad</name>
				<packageName>Cleric3k</packageName>
				<script></script>
				<command>down</command>
				<keyCode>-1</keyCode>
				<keyModifier>-1</keyModifier>
			</Key>
		</KeyGroup>
	</KeyPackage>
</MudletPackage>