User:Hsima

From Mudlet
Revision as of 19:00, 24 May 2020 by Hsima (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.

The bits in "script" tags should work more or less directly, at least from a lua stand point.

<?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 script would look something like this

<pre>

So an equivalent mudlet script would look something like this

<pre>

if exists("Cleric Aliases", "alias") == 0 then
  permGroup("Cleric aliases", "alias")
end
if exists("Cleric Triggers", "trigger") == 0 then
  permGroup("Cleric triggers", "trigger")
end
if exists("Guild Scripts", "script") == 0 then
  permGroup("Guild Scripts", "script")
end

if exists("Cleric Script", "script") == 0 then
  permScript("Cleric Script", "Guild Scripts", [[
  curelimit = .9
  heallimit = .8

  retlimit = .9

  lflimit = 10

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

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

  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

]])
end
enableScript("Cleric Script")

if exists("nuking", "alias") == 0 then
permAlias("nuking", "Cleric Aliases", "^nuking$", [[
	if (nuking) then
		echo("Nuking disabled.")
		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])
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
]])
end

if exists("Cleric Corpse Trigger", "trigger") == 0 then
permRegexTrigger("Corpse Trigger", "Cleric triggers", {"dealt the killing blow to"}, [[ doCorpseStuff() ]])
end