Aardwolf Quest Tracker plugin

Posted by Gedeon on Tue 30 Oct 2018 01:55 AM — 2 posts, 14,462 views.

#0
A nice simple GMCP quest tracker plugin I wrote to track quest average, total quests and to tell me total qp when I complete a quest, all modifiers included through GMCP


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>

<plugin
   name="Quest_Tracker"
   author="GIDEON_THE_BIBLE_BOOK_JUDGES"
   id="0594aa70c008365aa5070abc"
   language="Lua"
   save_state="y"
   date_written="2018-10-13"
   requires="4.98"
   version="2.11"
   >
</plugin>

<include name="constants.lua"/>

<aliases>
  <alias
   match="gmcpquest"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
  	QuestCounter = GetVariable("QuestCounter")
  	QuestCounter = tonumber(QuestCounter)
  	print(QuestCounter, "Quests Completed")
	
	QPtotal = GetVariable("QPtotal")
	QPtotal = tonumber(QPtotal)
	print(QPtotal, "QP total quest points with plugin")
	print(tonumber(GetVariable("QPtotal"))/tonumber(GetVariable("QuestCounter")), " QP Average")


  </send>
  </alias>
</aliases>

<script>
require "serialize"
function OnPluginBroadcast (msg, id, name, text)
	
	if (text == "comm.quest") then -- if we receive some GMCP quest data then do the following block of code up to end of if statement

		res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264", "gmcpval", "comm")
		luastmt = "gmcpdata = " .. gmcparg
		assert (loadstring (luastmt or "")) ()

		local action = gmcpval("quest.action")

		if (action == "comp") then -- begin is statement with then
			LastQuestQPTotal = GetVariable("LastQuestQPTotal")
			LastQuestQPTotal = gmcpval ("quest.totqp")
			print (LastQuestQPTotal, " QP from quest")
			
			SetVariable ("LastQuestQPTotal", LastQuestQPTotal)
			QuestCounter = GetVariable("QuestCounter")
  			QuestCounter = tonumber(QuestCounter)
			QuestCounter = QuestCounter + 1
			SetVariable ("QuestCounter", QuestCounter)
			print(QuestCounter, " Quests Completed with GMCP_Quest_Recorder")
			
			QPtotal = GetVariable("QPtotal")
  			QPtotal = tonumber(QPtotal)
			QPtotal = QPtotal + LastQuestQPTotal
			SetVariable ("QPtotal", QPtotal)
			print(QPtotal, "Quest Points earned with GMCP_Quest_Recorder")
			
			print(tonumber(GetVariable("QPtotal"))/tonumber(GetVariable("QuestCounter")), " QP Average")

		end -- end if statement

	end -- if gmcp quest data receieved comm.quest
	
end -- function onpluginbroadcast

require "gmcphelper" -- this line is necessary for us to be able to use the gmcpval helper function defined in gmcphelper.lua

function OnPluginInstall () 
 	
	QuestCounter = tonumber(GetVariable("QuestCounter"))

	if QuestCounter == nil then 

		SetVariable ("QuestCounter", "0") 
		QuestCounter = tonumber(QuestCounter)

	end

 	QPtotal = tonumber(GetVariable("QPtotal"))
 	
 	if QPtotal == nil then
		
		SetVariable ("QPtotal", "0") 
		QPtotal = tonumber (QPtotal)

	end

end 

function OnPluginSaveState() -- begin OnPluginSaveState function block, NOTE : VARIABLES MUST BE SAVED AS TYPE STRING TO SAVE CORRECTLY AND THEN CONVERTED BACK TO NUMBERS during OnPluginInstall function as demonstrated above
	SetVariable("QuestCounter",  QuestCounter)
	if QPtotal == nil then -- begin if statement with then
		SetVariable("QPtotal",  "0")
		QPtotal = tonumber(QPtotal)
	end
end -- end OnPluginSaveState function block

</script>

</muclient>


Enjoy! :)

- Gedeon
USA Global Moderator #1
Thanks! Just a few tips!

This little dance is no longer necessary in the Aardwolf MUSHclient package:

res, gmcparg = CallPlugin("3e7dedbe37e44942dd46d264", "gmcpval", "comm")
luastmt = "gmcpdata = " .. gmcparg
assert (loadstring (luastmt or "")) ()


See: https://github.com/fiendish/aardwolfclientpackage/wiki/Using-GMCP


In:

LastQuestQPTotal = GetVariable("LastQuestQPTotal")
LastQuestQPTotal = gmcpval ("quest.totqp")

that first line is wasted because you immediately overwrite the value


In:

QuestCounter = GetVariable("QuestCounter")
QuestCounter = tonumber(QuestCounter)
print(QuestCounter, "Quests Completed")
	
QPtotal = GetVariable("QPtotal")
QPtotal = tonumber(QPtotal)
print(QPtotal, "QP total quest points with plugin")
print(tonumber(GetVariable("QPtotal"))/tonumber(GetVariable("QuestCounter")), " QP Average")


You've already gotten and tonumbered your variables, so you don't need to do it again in your print. You should just use the local QuestCounter and QPtotal variables that you set. (This happens twice in two different parts of your code)


When you do something like:

if QuestCounter == nil then 
   SetVariable ("QuestCounter", "0") 
   QuestCounter = tonumber(QuestCounter)

I'm not sure that it's doing what you think. tonumber(nil) is nil. So QuestCounter will still be nil. (Likewise QPtotal). Maybe this is what you intended, but maybe not? Maybe you meant QuestCounter = 0?