Rewritten Accelerator example script with triggers

Posted by Rodriguez on Fri 05 Jun 2009 09:34 PM — 16 posts, 67,228 views.

#0
Hi!
I wanted to merge your TargetSwitch plugin with the accelerator example but the first one was written in VBScript and the later in Lua
I got so far but now he started complaining:


<script>
<![CDATA[
function OnPluginInstall ()


  Accelerator "F1", "backstab @target"


  Accelerator "Ctrl+F1", "world.addtrigger "armBackstab", "@target has arrived.|(?<=@target).+ is here.", "backstab @target", eEnabled or eTemporary or eTriggerOneShot, 14, 0, "", ""
  
  -- list them
  for _, v in ipairs (AcceleratorList ()) do Note (v) end

end -- function OnPluginInstall
]]>
</script>


He cant find the end of the "Ctrl+F1" line. I tried to surround it with another "" pair but it didnt change anything.
Amended on Fri 05 Jun 2009 09:35 PM by Rodriguez
Australia Forum Administrator #1
You have quotes within quotes here. In VBscript you have to double the quotes for a single set to go into the string, for example to note:


say "hello" to someone


... you would have to write:


Note "say ""hello"" to someone"
Australia Forum Administrator #2
You might be better off converting the VBscript one to Lua, rather than the Lua one to VBscript.
#3
Ok I think I converted it (at least he doesnt complain in the targeting script anymore...) but I still have a problem with the AddTrigger part:


Accelerator ("Ctrl+F1", "AddTrigger ("armBackstab", "(@target has arrived.|(?<=@target).+ is here.)", "backstab @target", eEnabled or eTemporary or eTriggerOneShot, 14, 0, "", "")")


He says:

[string "Plugin"]:24: ')' expected near 'armBackstab'
Error context in script:
  20 :   Accelerator ("F1", "backstab @target")
  21 : 
  22 :   
  23 :   
  24*:   Accelerator ("Ctrl+F1", "AddTrigger ("armBackstab", "(@target has arrived.|(?<=@target).+ is here.)", "backstab @target", eEnabled or eTemporary or eTriggerOneShot, 14, 0, "", "")")
  25 :     
  26 : 
  27 : 
  28 :   -- list them


But I see no reason why a bracket would be missing there
Australia Forum Administrator #4
Which language are you using now? You still have a quoted string within a quoted string, you need to use different quotes, or double the quotes, like I said.
Australia Forum Administrator #5
If it's Lua now, use single quotes at the start and end, like this:


Accelerator ("Ctrl+F1", 'AddTrigger ("armBackstab", "(@target has arrived.|(?<=@target).+ is here.)", "backstab @target", eEnabled or eTemporary or eTriggerOneShot, 14, 0, "", "")')


The single quotes in the "main" string lets you use double quotes inside the string.
#6
Ah, yes its Lua now and the quotes solved that problem.
Now the part I converted from VBScript to Lua makes problems :/

Guess the bigger problem is that I never did much with script languages and am somewhat confused of all these String concatenation.
There are probably still VBScript parts in there that I missed...



Function/Sub: SetTarget called by alias
Reason: processing alias ""
[string "Plugin"]:2: attempt to call local 'wildcards' (a table value)
stack traceback:
        [string "Plugin"]:2: in function <[string "Plugin"]:1>
Error context in script:
   1 : function SetTarget (sName, sLine, wildcards)
   2*:   which = wildcards (1)
   3 :   to_whom = wildcards (2)



<script>
<![CDATA[
function SetTarget (sName, sLine, wildcards)
  which = wildcards (1)
  to_whom = wildcards (2)
  world.SetVariable ("target" .. which, to_whom)
  world.ColourNote ("moccasin", "darkgreen", "Target " .. CStr (which) .. " now '" .. to_whom .. "'")
end

function ChooseTarget (sName, sLine, wildcards)
  world.SetVariable ("target", world.GetVariable ("target" .. wildcards (1)))
  world.ColourNote ("moccasin", "darkgreen", "Target now '" .. world.GetVariable ("target") .. "'")  
end


]]>
</script>
#7
Ok, I think it works for the most part now


<script>
<![CDATA[
function SetTarget (sName, sLine, wildcards)
  which = wildcards [1]
  to_whom = wildcards [2]
  SetVariable ("target"..which, to_whom)
  ColourNote ("moccasin", "darkgreen", "Target now " .. to_whom )
end

function ChooseTarget (sName, sLine, wildcards)
  SetVariable ("target", GetVariable ("target" .. wildcards [1]))
  ColourNote ("moccasin", "darkgreen", "Target now " .. GetVariable ("target"))  
end


]]>
</script>



But now I have a problem with the variable @target

  Accelerator ("F2", "backstab @target")


now sends "backstab @target" to the mud instead of the target i set.
Even replacing it with GetVariable ('target') doesnt work, not even if I use the scripting prefix...

Australia Forum Administrator #8
You need to get the target at runtime, whereas the Accelerator establishes a fixed string. This will do it:


AcceleratorTo ("F2", "Send ('backstab ' .. GetVariable ('target'))", sendto.script)


What this does is make F2 call a small script, which does a Send appending the current value of the variable 'target' to your message.

http://www.gammon.com.au/scripts/doc.php?function=AcceleratorTo
Amended on Sat 06 Jun 2009 10:10 PM by Nick Gammon
#9
I tried that but I received a Runtime-Error


Immediate execution
[string "Accelerator: Ctrl+F2"]:1: attempt to concatenate a nil value
stack traceback:
        [string "Accelerator: Ctrl+F2"]:1: in main chunk


even adding a SetVariable ("target", "test") right before it doesn't change that.

How confusing :/
Australia Forum Administrator #10
Ah, this is in a plugin is it? In that case it won't pick up main world variables unless you change it a bit.

Try something like:


AcceleratorTo ("F2", "Send ('backstab ' .. GetPluginVariable ('', 'target'))", sendto.script)




http://www.gammon.com.au/scripts/doc.php?function=GetPluginVariable


#11
Ah, yes its a plugin, sorry for not mentioning it earlier...
The problem with the runtime error is still there for some reason.

I guess I better post it in full to avoid further confusion.



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, November 06, 2002, 9:25 AM -->
<!-- MuClient version 3.30 -->

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

<!--


See: http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=1947
-->

<muclient>
<plugin
   name="TargetSwitch"
   author="Nick Gammon"
   id="2adec0ac37689537f9e3daf2"
   language="Lua"
   purpose="Demonstrates switching targets"
   save_state="y"
   date_written="2002-11-06 09:20:06"
   requires="3.23"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Demonstrates how you can switch targets with a couple of aliases.

Usage
-----

t1 = person   (set target 1)
t2 = person   (set target 2)
t3 = person   (set target 3)  ... and so on up to 9 ...

t1            (choose target 1)
t2            (choose target 2)
t3            (choose target 3) ... and so on up to 9 ...

punch         (punch target)
kick          (kick target)

eg.

t1=Bill        (target 1 is Bill)
t2=Benjamin    (target 2 is Benjamin)
t1             (choose Bill)
kick           (kick Bill)
t2             (choose Benjamin)
kick           (kick Benjamin)
t1             (choose Bill again)
punch          (punch Bill)
kick           (kick Bill)
t2             (choose Benjamin again)
punch          (punch Benjamin)
kick           (kick Benjamin)


TargetSwitch:help  <-- this help



]]>
</description>

</plugin>


<!--  Aliases  -->

<aliases>
  <alias
   script="SetTarget"
   match="^t([1-9])\s*\=\s*(.+)$"
   enabled="y"
   regexp="y"
  >
  </alias>
  <alias
   script="ChooseTarget"
   match="^t([1-9])$"
   enabled="y"
   regexp="y"
  >
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[
function SetTarget (sName, sLine, wildcards)
  which = wildcards [1]
  to_whom = wildcards [2]
  SetVariable ("target"..which, to_whom)
  ColourNote ("moccasin", "darkgreen", "Target now " .. to_whom )
end

function ChooseTarget (sName, sLine, wildcards)
  SetVariable ("target", GetVariable ("target" .. wildcards [1]))
  ColourNote ("moccasin", "darkgreen", "Target now " .. GetVariable ("target"))  
end


]]>
</script>



<script>
<![CDATA[
function OnPluginInstall ()

  AcceleratorTo ("F2", "Send ('backstab ' .. GetPluginVariable ('', 'target'))", sendto.script)
  
  AcceleratorTo ("Ctrl+F2","Send (AddTrigger ('armBackstab',(GetPluginVariable ('', 'target') ..'  has arrived.'|(?<=(GetPluginVariable ('', 'target')).+ is here.), 'backstab '.. GetPluginVariable ('', 'target') , eEnabled or eTemporary or eTriggerOneShot, 14, 0, '', ''))",sendto.script)



  -- list them
  for _, v in ipairs (AcceleratorList ()) do Note (v) end

end -- function OnPluginInstall
]]>
</script>


<!--  Plugin help  -->

<aliases>
  <alias
   script="OnHelp"
   match="TargetSwitch:help"
   enabled="y"
  >
  </alias>
</aliases>

<script>
<![CDATA[
function OnHelp (sName, sLine, wildcards)
  World.Note (World.GetPluginInfo (World.GetPluginID, 3))
end
]]>
</script> 

</muclient>
#12
F2 started working when I entered the script ID but Ctrl+F2 does nothing even after removing the OR. I tried to use a hardcoded mob name but even using the examples on the trigger page nothing happens.


  AcceleratorTo (
  	"F2", 
  	"Send ('backstab ' .. GetPluginVariable ('2adec0ac37689537f9e3daf2', 'target'))", 
  	sendto.script
  )
  
   AcceleratorTo (
   	"Ctrl+F2",
   	"Send (AddTrigger ('armBackstab','* Militiaman *','backstab '.. GetPluginVariable ('2adec0ac37689537f9e3daf2', 'target') ,trigger_flag.Enabled or trigger_flag.Temporary or trigger_flag.OneShot or trigger_flag.Replace ,custom_colour.Custom14,0, '', ''))",
   	sendto.script
  )

#13

   AcceleratorTo (
   	"Ctrl+F2",
   	"Send (AddTrigger ('armBackstab','^(.*?)'..GetPluginVariable ('2adec0ac37689537f9e3daf2', 'target')..'(.*?)$','backstab '.. GetPluginVariable ('2adec0ac37689537f9e3daf2', 'target') ,50229,custom_colour.Custom14,0, '', ''))",
   	sendto.script
  )


Seems to work but still sends a "0" or "30006" return codes to the mud. Is there a way of telling MUSHClient to just send them to my output window?
Australia Forum Administrator #14
Why are you doing a Send ( AddTrigger ?

That is sending the results of the AddTrigger to the MUD (which will be a number).

Perhaps you mean to omit the Send altogether?
#15
That is a _really_ good question...

Must have gotten in there with some copy&paste I guess.