PtokaX forum

Archive => Archived 5.1 boards => Help with scripts => Topic started by: tortilla on 31 July, 2006, 00:44:29

Title: please need heklp with this trig to lua 5.1.1
Post by: tortilla on 31 July, 2006, 00:44:29
--
SV = "PiKoleTo Live 1.00 Lua5"
--
-- by Mutor      ..Reworked an old script a bit 10/07/05
--
-- Alerts operators if trigger file is missing.
-- Now reads trigger table from external file.
-- Includes settable string (command) to list available triggers.
--
--Trigger table to be stored in external file
--Add / Remove triggers as you wish, follow the format.
--
---Editable Section---------------------
TrigBot = frmHub:GetHubBotName()-- Name for Bot: frmHub:GetHubBotName() or "Custom_Name"
Prefix = "?"               -- Command Prefix
RunComm = "ton"               -- Command to start TrigChat
StopComm = "toff"            -- Command to stop TrigChat
ListComm = "trig"            -- Command to list triggers (dont use prefix, script doesnt trigger on control chars)
RunStatus = "on"            -- Start TrigChat on or off -> "on"/"off"
TrigFile = "Trigspik.dat"         -- File to store triggers table
ShowVer= "yes"               -- Display script info on start? "yes"/"no"
---End Editable section--------------
--

Main = function()
   if TrigBot ~= frmHub:GetHubBotName() then
      frmHub:RegBot(TrigBot, 1, SV, "")
   end
   if ShowVer == "yes" and RunStatus == "on" then
      SendToAll(TrigBot, SV.." Iniciado en: "..os.date("%B %d %Y @ %X").."\tUsando Nick: "..TrigBot)
   end
   if loadfile(TrigFile) ~= nil then
      dofile(TrigFile)
   else
      local ErrMsg0="\r\n\r\n\tFile Error: "..TrigFile.." does not exist.\r\n"
      if not (frmHub:GetOpChatName()) then
         SendPmToOps(Bot,ErrMsg0)
      else
         SendPmToOps(frmHub:GetOpChatName(),TrigBot..ErrMsg0)
      end
   end
end

ChatArrival = function(user, data)
data=string.sub(data,1,string.len(data)-1)
local s,e,cmd = string.find(data, "^%b<>%s+(%p%w+)")
--local s,e,msg = string.find(data,"^%b<>%s+(.+)$") --match first capture anywhere in the text
local _,_,msg = string.find(data,"%s+(%S+)$")      --match first or last word
local s,e,trg = string.find(data,"^%b<>%s+(%w+)")
   if (cmd==Prefix..StopComm) and user.bOperator then
      if RunStatus == "off" then
         user:SendData(TrigBot,GetProfileName(user.iProfile).." "..user.sName..", TrigChat isn't running now...? ?>8-P")
      else
         RunStatus = "off"
         SendToAll(TrigBot,"TrigChat has been stopped by "..GetProfileName(user.iProfile).." "..user.sName..",...? ?>8-I")
      end
      return 1
   elseif (cmd==Prefix..RunComm) and user.bOperator then
      if RunStatus == "on" then
         user:SendData(TrigBot,GetProfileName(user.iProfile).." "..user.sName..", TrigChat is already running...? ?>8-P")
      else
         RunStatus = "on"
         SendToAll(TrigBot,"TrigChat has been started by? "..GetProfileName(user.iProfile).." "..user.sName..",...? ?>8-O")
      end
         return 1
   elseif trg and (trg == ListComm) then
      user:SendPM(TrigBot,GetTrigs())      --Send list in pm
      --user:SendData(TrigBot,GetTrigs())   --Send list in main
      return
   elseif msg and not cmd then
      local s, e, pre = string.find(data, "^%b<>%s(%p)")
      if pre and GetPrefixes()[1] == pre then
         return
      end
      for key, value in trigs do --
         if RunStatus == "on" and ( string.find( msg, key) ) and string.len(msg)==string.len(key) then -- exact first word
         --if RunStatus == "on" and ( string.find( msg, key) ) then      --any part of text
            answer, x = string.gsub(value,"%b[]", user.sName)--
            local filter = string.gsub(data,"%b<> ","")
            SendToAll(user.sName,filter )
            SendToAll(TrigBot,answer )
            return 1
         end
      end
   end
end

GetTrigs = function()
local reply = "\r\n\r\n\tCurrent Triggers:\r\n"..string.rep("o",150).."\r\n"
   for i,v in trigs do
      reply = reply.." [ "..i.." ] "
   end
   return reply.."\r\n"..string.rep("o",150).."\r\n\tEnd Of Listing"
end
Title: Re: please need heklp with this trig to lua 5.1.1
Post by: tortilla on 31 July, 2006, 16:51:40
thanks mutor