[心得] MushClient一鍵啟用或停用觸發

看板mud_jy (金庸修真錄)作者 (rsliang)時間9年前 (2015/08/29 17:48), 編輯推噓2(201)
留言3則, 2人參與, 最新討論串1/1
這個是後來覺得一陣子沒玩,再上來就和新手一樣,通通忘光光了,所以做成可以按的按鈕 ,一鍵啟動或是停止觸發。 分為三個區塊:觸發、Alias、按鈕的plugin。 PS.因為code有不少符號,如果不能用,可能是這些符號被bbs當成特殊的符號處理掉了,請 再和我說,我再修改,謝謝。 ====================================觸發======================================== 這個部份就看需要做什麼了,底下是以我寫的挖銅礦的觸發,原則上我不習慣做太多的觸發 ,以防其中一句沒抓到,整個停下來,所以效率不會太好,堪用就是了。 注意事項: 1.需自行建立兩個變數「jobminecount」、「jobminabexp」,預設值為0。 2.yourpassword請自行改為你的密碼。 3.「abandon exp to 900000」、「deposit 10000 coin」和「jingjie exp 4000 」請自行更改成適合自己的數字;身上的錢還是會越來越多,所以改大一點會比 較好一些。 4.「exert regenerate」和「exert recover」是每做100次工作才會執行一次,請 自行決定要不要用,不用一定會暈,我自己的角色是放著12小時後會用完精力和 氣血。 ===================================挖銅礦code=================================== <trigger enabled="y" group="minecopper" match="^(\&gt; |)你摸了摸了汗,看看空籃子,縷`算是幹完么@趟了。$" name="coppermine01" regexp="y" send_to="12" sequence="100" > <send> world = GetWorldById(GetWorldID()) jobcount = tonumber(world.GetVariable("jobminecount")) abexpcount = tonumber(world.GetVariable("jobmineabexp")) abexpcount = tonumber(abexpcount) +1 world.SetVariable("jobmineabexp", abexpcount) if tonumber(abexpcount) % 100 == 0 then world.SetVariable("jobmineabexp", 1) Send("abandon exp to 900000") DoAfter(1, "yourpassword") DoAfter(6, "recall back") DoAfter(12.5, "west") DoAfter(12.5, "west") DoAfter(13, "deposit 10000 coin") DoAfter(18, "east") DoAfter(18.5, "south") DoAfter(19, "south") DoAfter(19.5, "south") DoAfter(20, "west") DoAfter(20.5, "fill dai") DoAfter(22, "east") DoAfter(23, "rideto hangzhou") DoAfter(25, "south") DoAfter(25, "south") DoAfter(25, "south") DoAfter(26, "southwest") DoAfter(26, "southwest") DoAfter(27, "west") DoAfter(27.5, "west") DoAfter(28, "west") DoAfter(28.5, "southwest") DoAfter(29, "south") DoAfter(29.5, "east") DoAfter(30, "east") DoAfter(30.5, "east") DoAfter(31, "exert regenerate") DoAfter(31.5, "exert recover") DoAfter(33, "ask gong about mine") DoAfter(33.5, "mine") elseif tonumber(abexpcount) % 10 == 0 then Send("jingjie exp 4000") end if tonumber(jobcount) &gt; 10 and tonumber(abexpcount) % 100 ~= 0 then world.SetVariable("jobminecount", 0) DoAfter(1, "eat liang") DoAfter(1, "eat liang") DoAfter(1.5, "drink dai") DoAfter(2, "drink dai") DoAfter(12, "ask gong about mine") DoAfter(13, "mine") elseif tonumber(abexpcount) % 100 ~= 0 then jobcount = jobcount + 1 world.SetVariable("jobminecount", jobcount) DoAfter(12, "ask gong about mine") DoAfter(13, "mine") end</send> </trigger> ================================================================================ ====================================Alias======================================= 其實是從檢查觸發的alias改出來的。 ====================================Code======================================== <alias name="EnORDisTriggers" match="^#tgs (\S+)$" enabled="y" group="SomeCmds" regexp="y" send_to="12" sequence="100" > <send> world = GetWorldById(GetWorldID()) target = "%1" trilist = GetTriggerList() if trilist then for sno, triname in ipairs (trilist) do grname = world.GetTriggerInfo(triname, 26) if grname == target then if world:GetTriggerInfo(triname, 8) then world.EnableTriggerGroup(grname, false) Note("Disable Trigger Group [" .. target .. "].") else world.EnableTriggerGroup(grname, true) Note("Enable Trigger Group [" .. target .. "].") end -- if group of trigger enabled or disabled break end -- if grname exists end -- for end -- if we have any triggers</send> </alias> ================================================================================ =================================按鈕的plugin=================================== 原本想自己寫,但超強的作者大大已經寫好了,所以就直接用啦。 注意事項: 1.按鈕需要一張圖,但這張圖只有32x32(pixels),所以別畫太複雜,我是直接寫 字而已。 2.圖和檔案放一起會比較沒問題他的根目錄預設是Mushclient的安裝目錄,請自行 更改成你放檔安的目錄,不改會看不到圖,但功能是正常可用的。 3.路徑的寫法用「\」要注意一下寫法,因為他是保留字,所以會需要多一個「\」 ,我看作者是用「/」但我沒測試過,請自行測試。XD 4.會寫script的大大可以直接寫,我很懶把他拆到alias去了。 ps1.因為不是我自己寫的,如果違反規則,我會把底下刪了,只留下我自己改的部份。 ps2.最後附上原始連結 http://www.gammon.com.au/forum/?id=9359 ===============================底下是我改好的範例=============================== <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE muclient [ <!ENTITY horizontal "y" > <!ENTITY show_time "n" > ]> <muclient> <plugin name="Icon_Bar" author="Nick Gammon" id="ede0920fc1173d5a03140f0e" language="Lua" purpose="Shows a bar of buttons you can click on to do things" date_written="2009-02-26 09:00" date_modified="2010-05-31 17:22" requires="4.40" save_state="y" version="5.0" > <description trim="y"> <![CDATA[ Install this plugin to show a button bar. Click on an icon to execute a script or send a command to the MUD. ]]> </description> </plugin> <!-- Timers --> <timers> <timer script="handle_cooldowns" enabled="y" second="1.00" active_closed="y" > </timer> </timers> <!-- Script --> <script> -- pull in entities outside the CDATA block horizontal = ("&horizontal;"):lower ():sub (1, 1) == "y"; show_time = ("&show_time;"):lower ():sub (1, 1) == "y"; <![CDATA[ -- table of buttons --[[ Each button can have up to four entries: icon - filename of the image to draw tooltip - what to show if you hover the mouse over the button send - what to send to the MUD script - a script function to call cooldown - time spell takes to cool down, in seconds sound - sound to play when button pressed --]] buttons = { -- button 挖銅礦 { icon = "\worlds\\jins\\MineCopper.png", -- icon image tooltip = "挖銅礦", -- tooltip help text send = "#tgs minecopper", -- what to send --cooldown = 10, -- cooldown time in seconds --sound = "chimes.wav", -- sound to play when cast }, -- end of button 挖銅礦 -- button 2 -- { -- icon = "SwordIcon.png", -- tooltip = "Attack", -- send = "kill @target", -- cooldown = 1 * 60 * 60, -- 1 hour cooldown -- }, -- end of button 2 -- button 3 -- { -- icon = "SparkIcon2.png", -- tooltip = "Special Attacks", -- script = function () -- script to execute when clicked -- -- choose from menu -- local result = WindowMenu (win, -- WindowInfo (win, 14), -- x -- WindowInfo (win, 15), -- y -- "Backstab|Stun|Kick|Taunt") -- -- if not cancelled, do action on current target -- if result ~= "" then -- Send (result:lower () .. " " .. GetPluginVariable ("", "target")) -- end -- if -- end, -- script function -- cooldown = 10 * 60, -- 10 minute cooldown -- }, -- end of button 3 --> add more buttons here } -- end of buttons table -- configuration ICON_SIZE = 32 BACKGROUND_COLOUR = ColourNameToRGB "bisque" BOX_COLOUR = ColourNameToRGB "royalblue" BUTTON_EDGE = ColourNameToRGB "silver" MOUSE_DOWN_COLOUR = ColourNameToRGB "darkorange" -- where to put the window WINDOW_POSITION = 6 -- top right OFFSET = 6 -- gap inside box EDGE_WIDTH = 2 -- size of border stroke --[[ Useful positions: 4 = top left 5 = center left-right at top 6 = top right 7 = on right, center top-bottom 8 = on right, at bottom 9 = center left-right at bottom --]] -- font and size to use FONT_NAME = "Lucida Sans Unicode" FONT_SIZE = 18 FONT_SIZE_MEDIUM = 14 FONT_SIZE_SMALL = 10 FONT_COLOUR = ColourNameToRGB "yellow" -- sound to play if on cooldown ON_COOLDOWN_SOUND = "ding.wav" frames = {} -- remember where each icon was require "commas" function mousedown (flags, hotspot_id) if hotspot_id == "_" then -- find where mouse is so we can adjust window relative to mouse startx, starty = WindowInfo (win, 14), WindowInfo (win, 15) -- find where window is in case we drag it offscreen origx, origy = WindowInfo (win, 10), WindowInfo (win, 11) return end -- if local n = tonumber (hotspot_id) -- draw the button border in another colour for visual feedback WindowRectOp (win, 1, frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2, MOUSE_DOWN_COLOUR) Redraw () end -- mousedown function cancelmousedown (flags, hotspot_id) local n = tonumber (hotspot_id) -- draw the button border in original colour for visual feedback WindowRectOp (win, 1, frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2, BUTTON_EDGE) Redraw () end -- cancelmousedown function mouseup (flags, hotspot_id) -- fix border colour cancelmousedown (flags, hotspot_id) local n = tonumber (hotspot_id) local button = buttons [n] -- shift key clears cooldown if bit.band (flags, 1) == 1 then SetCooldown (n, nil) return end -- if -- can't press button if on cooldown if (button.cooldown_left or 0) > 0 then Sound (ON_COOLDOWN_SOUND) return end -- still on cooldown -- play sound if defined if button.sound then Sound (button.sound) end -- sound to play -- send to world if something specified if type (button.send) == "string" and button.send ~= "" then local errors = {} -- no errors yet -- function to do the replacements for string.gsub local function replace_variables (s) s = string.sub (s, 2) -- remove the @ replacement = GetPluginVariable ("", s) -- look up variable in global variables if not replacement then -- not there, add to errors list table.insert (errors, s) return end -- not there return replacement -- return variable end -- replace_variables -- replace all variables starting with @ local command = string.gsub (button.send, "@%a[%w_]*", replace_variables) -- report any errors if #errors > 0 then for k, v in ipairs (errors) do ColourNote ("white", "red", "Variable '" .. v .. "' does not exist") end -- for return end -- error in replacing Execute (command) end -- if -- execute script if wanted if type (button.script) == "function" then button.script (n) end -- if SetCooldown (n, button.cooldown) end -- mouseup function dragmove(flags, hotspot_id) -- find where it is now local posx, posy = WindowInfo (win, 17), WindowInfo (win, 18) -- move the window to the new location WindowPosition(win, posx - startx, posy - starty, 0, 2); -- change the mouse cursor shape appropriately if posx < 0 or posx > GetInfo (281) or posy < 0 or posy > GetInfo (280) then SetCursor (11) -- X cursor else SetCursor (10) -- arrow (NS/EW) cursor end -- if end -- dragmove function dragrelease(flags, hotspot_id) local newx, newy = WindowInfo (win, 17), WindowInfo (win, 18) -- don't let them drag it out of view if newx < 0 or newx > GetInfo (281) or newy < 0 or newy > GetInfo (280) then -- put it back WindowPosition(win, origx, origy, 0, 2); end -- if out of bounds end -- dragrelease function SetCooldown (n, amount) assert (n >= 1 and n <= #buttons, "Bad button number " .. n .. " to SetCooldown") if amount then assert (amount >= 0, "Bad amount " .. amount .. " to SetCooldown") end -- if local frame = frames [n] local x1, y1, x2, y2 = frame.x1 + 1, frame.y1 + 1, frame.x2 - 1, frame.y2 - 1 buttons [n].cooldown_left = amount -- cooldown time left in seconds local max = buttons [n].cooldown or 0 -- max cooldown time local percent -- how far cooled down we are as a percent if max > 0 then percent = (amount or 0) / max else percent = 0 -- don't divide by zero! end -- if -- reload the image if WindowDrawImage(win, n, x1, y1, -- left, top x2, y2, -- right, bottom 2) -- mode - stretch or shrink ~= error_code.eOK then WindowRectOp (win, 2, x1, y1, -- left, top x2, y2, -- right, bottom BACKGROUND_COLOUR) end if amount and amount > 0 then -- calculate pie end point local endx = math.cos (math.rad (percent * 360 + 90)) * ICON_SIZE + ICON_SIZE / 2 local endy = -1 * math.sin (math.rad (percent * 360 + 90)) * ICON_SIZE + ICON_SIZE / 2 -- clear temporary window WindowRectOp (tempwin, 2, 0, 0, 0, 0, 0xFFFFFF) -- fill with white -- draw the pie showing amount of cooldown WindowCircleOp (tempwin, 5, -10, -10, ICON_SIZE + 10, ICON_SIZE + 10, -- pie 0x000000, 5, 0, -- no pen 0x000000, 0, -- solid brush, black ICON_SIZE / 2, 0, -- from 12 o'clock position endx, endy) -- turn pie shape into an image WindowImageFromWindow(win, "mask", tempwin) -- blend in (darken mode) with 50% opacity WindowBlendImage(win, "mask", x1, y1, x2, y2, -- rectangle 5, -- darken 0.5) -- opacity -- if they want to see the time left (text on top of the button) do that now if show_time then local font = "f" local time_left = convert_time (amount) time_left = string.gsub (time_left, "[ s]", "") -- get rid of spaces, and "s" local time_len = WindowTextWidth (win, font, time_left) -- use smaller font if it doesn't fit if time_len > ICON_SIZE then font = "f2" time_len = WindowTextWidth (win, font, time_left) -- still too big? if time_len > ICON_SIZE then font = "f3" time_len = WindowTextWidth (win, font, time_left) end -- if end -- if local font_height = WindowFontInfo (win, font, 1) local x_offset = math.max ((ICON_SIZE - time_len) / 2, 0) local y_offset = math.max ((ICON_SIZE - font_height) / 2, 0) WindowText (win, font, time_left, x1 + x_offset + 2, y1 + y_offset + 2, x2, y2, 0x000000) WindowText (win, font, time_left, x1 + x_offset, y1 + y_offset, x2, y2, FONT_COLOUR) end -- show_time else buttons [n].cooldown_left = nil end -- if Redraw () end -- function SetCooldown function OnPluginInstall () local x, y, mode, flags = tonumber (GetVariable ("windowx")) or 0, tonumber (GetVariable ("windowy")) or 0, tonumber (GetVariable ("windowmode")) or WINDOW_POSITION, -- top right tonumber (GetVariable ("windowflags")) or 0 -- check miniwindow visible if x < 0 or x > GetInfo (281) or y < 0 or y > GetInfo (280) then x, y = 0, 0 -- reset to top left end -- if not visible win = GetPluginID () -- get a unique name tempwin = win .. ":temp" local gauge_height, gauge_width if horizontal then window_width = (#buttons * (ICON_SIZE + OFFSET)) + OFFSET window_height = ICON_SIZE + (OFFSET * 2) else window_width = ICON_SIZE + (OFFSET * 2) window_height = (#buttons * (ICON_SIZE + OFFSET)) + OFFSET end -- if -- make the miniwindow WindowCreate (win, x, y, -- left, top (auto-positions) window_width, -- width window_height, -- height mode, -- position mode flags, -- flags BACKGROUND_COLOUR) -- for drawing cooldowns (window not visible) WindowCreate (tempwin, 0, 0, -- left, top ICON_SIZE, -- width ICON_SIZE, -- height 12, -- position mode 0, -- flags ColourNameToRGB "white") -- grab fonts WindowFont (win, "f", FONT_NAME, FONT_SIZE, true) WindowFont (win, "f2", FONT_NAME, FONT_SIZE_MEDIUM, true) WindowFont (win, "f3", FONT_NAME, FONT_SIZE_SMALL, true) -- draw the buttons for n, v in ipairs (buttons) do if v.icon then if WindowLoadImage (win, n, GetInfo (66) .. v.icon) ~= error_code.eOK then DoAfterSpecial (1, string.format ([[ ColourNote ("white", "red", "Could not load image '%s'")]], string.gsub (GetInfo (66) .. v.icon, '\\', '\\\\')), sendto.script) end -- if end -- if icon specified local x1, y1, x2, y2 -- where to draw the icon if horizontal then x1, y1 = (n - 1) * (ICON_SIZE + OFFSET) + OFFSET, OFFSET x2, y2 = n * (ICON_SIZE + OFFSET), ICON_SIZE + OFFSET else x1, y1 = OFFSET, (n - 1) * (ICON_SIZE + OFFSET) + OFFSET x2, y2 = ICON_SIZE + OFFSET, n * (ICON_SIZE + OFFSET) end -- if -- draw the image if WindowDrawImage(win, n, x1, y1, -- left, top x2, y2, -- right, bottom 2) -- mode - stretch or shrink ~= error_code.eOK then WindowRectOp (win, 2, x1, y1, -- left, top x2, y2, -- right, bottom BACKGROUND_COLOUR) end -- if -- remember where to draw the frame, for mouse clicks frames [n] = { x1 = x1 - 1, y1 = y1 - 1, x2 = x2 + 1, y2 = y2 + 1 } -- draw the button border WindowRectOp (win, 1, frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2, BUTTON_EDGE) -- make a hotspot we can click on WindowAddHotspot(win, n, frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2, -- rectangle "", -- mouseover "", -- cancelmouseover "mousedown", "cancelmousedown", "mouseup", v.tooltip, -- tooltip text 1, 0) -- hand cursor end -- for each world -- draw the border of the whole box WindowCircleOp (win, 2, 0, 0, 0, 0, BOX_COLOUR, 6, EDGE_WIDTH, 0x000000, 1) -- make a hotspot WindowAddHotspot(win, "_", 0, 0, 0, 0, -- whole window "", -- MouseOver "", -- CancelMouseOver "mousedown", "", -- CancelMouseDown "", -- MouseUp "Drag to move", -- tooltip text 10, 0) -- arrow (NS/EW) cursor WindowDragHandler(win, "_", "dragmove", "dragrelease", 0) if GetVariable ("enabled") == "false" then ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.") EnablePlugin (GetPluginID (), false) return end -- they didn't enable us last time -- ensure window visible WindowShow (win, true) end -- OnPluginInstall -- hide window on removal function OnPluginClose () WindowShow (win, false) -- hide it end -- OnPluginClose -- show window on enable function OnPluginEnable () WindowShow (win, true) -- show it end -- OnPluginEnable -- hide window on disable function OnPluginDisable () WindowShow (win, false) -- hide it end -- OnPluginDisable function OnPluginSaveState () SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17))) SetVariable ("windowx", WindowInfo (win, 10)) SetVariable ("windowy", WindowInfo (win, 11)) SetVariable ("windowmode", WindowInfo (win, 7)) SetVariable ("windowflags", WindowInfo (win, 8)) end -- OnPluginSaveState -- called every second on a timer function handle_cooldowns (name) for n, v in ipairs (buttons) do if buttons [n].cooldown_left then SetCooldown (n, buttons [n].cooldown_left - 1) end -- if some cooldown left end -- for end -- function handle_cooldowns ]]> </script> </muclient> ================================================================================ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 112.105.167.2 ※ 文章網址: https://www.ptt.cc/bbs/mud_jy/M.1440841709.A.C6D.html

08/29 18:16, , 1F
$GT好像是多餘的?
08/29 18:16, 1F

08/29 18:16, , 2F
&gt
08/29 18:16, 2F

08/29 19:48, , 3F
那個是符號>,不能省掉,有時候在mud中最前面會多「> 」
08/29 19:48, 3F
文章代碼(AID): #1LuN_jnj (mud_jy)
文章代碼(AID): #1LuN_jnj (mud_jy)