User:Hsima
Jump to navigation
Jump to search
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 < 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</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>