MUSHclient script capture within a trigger AFTER several lines of output

Posted by Lua_Newbie on Wed 25 Feb 2015 01:19 PM — 6 posts, 22,350 views.

#0
Hello from the U.K !
I am learning Lua (as my first scripting language) and I have this script as a plugin (.xml) for MUSHclient:

Quote:

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

<muclient>
<plugin
name="FINAL_GOLD_AUC_LUANEWB"
author="Luanewb"
id="bd6a63354eec6157b8088351"
language="Lua"
purpose="GOLD_AUC_TRACKER"
save_state="y"
date_written="2100-12-12 12:12:12"
requires="4.93"
version="1.0"
>
<description trim="n">
<![CDATA[

]]>
</description>

</plugin>

<include name="constants.lua"/>

<aliases>

<alias
match="^vars$"
enabled="y"
regexp="y"
send_to="12"
omit_from_output="y"
script="ShowVariables"
sequence="100"
>
</alias>

</aliases>

<triggers>
<trigger
match="^{chan ch=auction}Auction: (?<item>.*?) SOLD to (?<player>\w+) for (?<gold>[0-9,]+) gold\.$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
script="RecordSale"
>
</trigger>

</triggers>


<script>
<![CDATA[

local item_name = GetVariable("item_name") or ""
local player_name = GetVariable("player_name") or "Luanewb"
local gold_amount = GetVariable("gold_amount") or 0

function RecordSale (name, line, wildcards)
item_name = wildcards.item
if (wildcards.player == player_name) then
local num_no_commas = string.gsub(wildcards.gold, ",", "")
gold_amount = tonumber(gold_amount) + tonumber(num_no_commas)
end
end

function ShowVariables ()
Note("Player Name: " .. player_name)
Note("Last Item Sold: " .. item_name)
Note("Total Gold: " .. gold_amount)
end

function OnPluginSaveState()
SetVariable("item_name", item_name)
SetVariable("player_name", player_name)
SetVariable("gold_amount", gold_amount)
end

]]>
</script>
</muclient>


which works just fine however I'm looking to add some code to it to make it also track gold received from items sold by a particular player (self)

so I'm guessing it would be something like this in the triggers tags and the script tags:

Quote:

<triggers>
<trigger
match="^{chan ch=auction}Auction: (?<item>.*?) SOLD to (?<player>\w+) for (?<gold>[0-9,]+) gold\.$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
script="RecordAucBought"
>
</trigger>
<trigger
match="^{chan ch=auction}Auction: (?<player>\w+) is auctioning (?<item>.*?) (level (?<item_level>.*?), Num (?<item_number>.*?)). Current bid is (?<gold>[0-9,]+)\.$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
script="RecordAucSold"
>
</trigger>

</triggers>

<script>
<![CDATA[

local player_name = GetVariable("player_name") or "Luanewb"
local gold_auc_bought = GetVariable("gold_auc_bought") or 0
local gold_auc_sold = GetVariable("gold_auc_sold") or 0

function RecordAucbought (name, line, wildcards)
item_name = wildcards.item
if (wildcards.player == player_name) then
local num_no_commas = string.gsub(wildcards.gold, ",", "")
gold_auc_bought = tonumber(gold_auc_bought) + tonumber(num_no_commas)
end
end

function RecordAucSold (name, line, wildcards)
item_name = wildcards.item
if (wildcards.player == player_name) then

local num_no_commas = string.gsub(wildcards.gold, ",", "")
gold_auc_sold = tonumber(gold_auc_sold) + tonumber(num_no_commas)
end
end

function ShowVariables ()
Note("Total Gold Spent On Auction: " .. gold_auc_bought)
Note("Total Gold Received From Auction: " .. gold_auc_sold)
end

function OnPluginSaveState()
SetVariable("gold_auc_bought", gold_auc_bought)
SetVariable("gold_auc_sold", gold_auc_sold)
end

]]>
</script>


except I need to capture the amount the item actually sold for several lines of MUD output AFTER the trigger fires. (the amount the item eventuall sold for) I'm guessing I need some sort of trigger within a trigger mechanic? Is that even possible?? I hope so! :)

Please Help !
Amended on Wed 25 Feb 2015 05:44 PM by Lua_Newbie
Australia Forum Administrator #1
Can you post an example? You mean line A is the trigger but line B (further down) has the amount?
#2
Hello Nick!! firstly thank you for offering to help me with this its a real head scratcher for me. I'mnot sure what you mean by line a and line b but.. I've been thinking about it and I believe that what I need is a match on world output with an if statement once i can get this trigger to fire as part of the plugin:

Quote:

</trigger>
<trigger
match="^{chan ch=auction}Auction: (?<player>\w+) is auctioning (?<item>.*?) (level (?<item_level>.*?), Num (?<item_number>.*?)). Current bid is (?<gold>[0-9,]+)\.$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
script="RecordAucSold"
>
</trigger>


to match this part within the script tags:

Quote:

function RecordAucSold (name, line, wildcards)
item_name = wildcards.item
if (wildcards.player == player_name) then

local num_no_commas = string.gsub(wildcards.gold, ",", "")
gold_auc_sold = tonumber(gold_auc_sold) + tonumber(num_no_commas)
end
end



I'm not even sure that the match is correct as I had lots of help with the original match for tracking gold spent on auction channel:

Quote:

match="^{chan ch=auction}Auction: (?<item>.*?) SOLD to (?<player>\w+) for (?<gold>[0-9,]+) gold\.$"


I'm trying to make a tracking plugin for currencies in the MUD (Aardwolf) which are gold/TP/and QP and this is the early stage but once I have these basics figured out I can <!--hopefully--> apply pretty much the same code to the rest of my .xml file, someone practically wrote the original script for me and I understand the most part of it but trip up when it comes to the trigger matches and all within the script tags (but have a VERY basic/vague understanding).

It just occoured to me maybe this is what you meant by line a and line b:

line a: Auction: The Oculus of the K'estest SOLD to Luanewb for 23,456 gold.
(which works fine in the original script as posted)

line b: Luanewb is auctioning (!(Sight Beyond Sight)!) (Level 1, Num 620). Current bid is 100.
(which is what I'm having trouble getting my head around)
i need to check if the person auctioning the item is the same as @player_name then once the item sells to update @gold_auc_sold (as the total received from auctioning items)

I hope I explained my problem well enough ! :)
Amended on Wed 25 Feb 2015 11:01 PM by Lua_Newbie
Australia Forum Administrator #3
Well I asked you to post example output, and you haven't.
#4
God I feel so stupid, sorry Nick, I didn't realise you meant sample output, here it is:

Quote:


Player Name: Luanewb
Last Item Sold: (!(Sight Beyond Sight)!)
Total Gold: 3000



Then when I buy another item like this:

Quote:


Auction: (!(Shadowbane)!) SOLD to Luanewb for 1,000 gold.



and type "vars" I get this:

Quote:


Player Name: Luanewb
Last Item Sold: (!(Shadowbane)!)
Total Gold: 4000



Like I said before this is the original script and is working right.

The bit I need help with is a method to have a 2nd trigger in the .xml file that matches on this:

Quote:


Auction: Luanewb is auctioning (!(Shadowbane)!) (Level 1, Num 750). Current bid is 100.



then captures the final sale price as to update the variable gold_auc_sold.

when I try loading the updated .xml file which contains this:

Quote:


<triggers>
<trigger
match="^{chan ch=auction}Auction: (?<item>.*?) SOLD to (?<player>\w+) for (?<gold>[0-9,]+) gold\.$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
script="RecordAucBought"
>
</trigger>
<trigger
match="^{chan ch=auction}Auction: (?<player>\w+) is auctioning (?<item>.*?) (level (?<item_level>.*?), Num (?<item_number>.*?)). Current bid is (?<gold>[0-9,]+)\.$"
enabled="y"
regexp="y"
send_to="12"
sequence="100"
script="RecordAucSold"
>
</trigger>

</triggers>

<script>
<![CDATA[

local player_name = GetVariable("player_name") or "Luanewb"
local gold_auc_bought = GetVariable("gold_auc_bought") or 0
local gold_auc_sold = GetVariable("gold_auc_sold") or 0

function RecordAucbought (name, line, wildcards)
item_name = wildcards.item
if (wildcards.player == player_name) then
local num_no_commas = string.gsub(wildcards.gold, ",", "")
gold_auc_bought = tonumber(gold_auc_bought) + tonumber(num_no_commas)
end
end

function RecordAucSold (name, line, wildcards)
item_name = wildcards.item
if (wildcards.player == player_name) then

local num_no_commas = string.gsub(wildcards.gold, ",", "")
gold_auc_sold = tonumber(gold_auc_sold) + tonumber(num_no_commas)
end
end

function ShowVariables ()
Note("Total Gold Spent On Auction: " .. gold_auc_bought)
Note("Total Gold Received From Auction: " .. gold_auc_sold)
end

function OnPluginSaveState()
SetVariable("gold_auc_bought", gold_auc_bought)
SetVariable("gold_auc_sold", gold_auc_sold)
end

]]>
</script>
</muclient>



A large window opens in MUSHclient titled: Missing script procedure names. beneath that it says this:
The following errors were encountered when attempting to link to script subroutines. The missing subroutines will not be called.

And beneath that in the main output window it says:
You have not specified a script file name
The trigger subroutine named "RecordAucBought" could not be found.

Is there something wrong with this?:

Quote:


script="RecordAucBought"



and this?:

Quote:


script="RecordAucSold"



Many Thank You's in advance !
Australia Forum Administrator #5
I'm not quite following what you've done. Is that in a plugin? If so can you post all of it?