PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: Oz on 01 December, 2006, 12:30:32

Title: error in script Awayer v 4.lua
Post by: Oz on 01 December, 2006, 12:30:32
hi all, have error in this script, can some help me?

[23:27] Syntax ...s\Bom\Desktop\0.3.5.1.lua5.0.2\scripts\!alarmbot.lua:253: attempt to perform arithmetic on a nil value

--- --- --- Awayer v 4 --- ---

--lua 5 version

--By jiten and Dessamator

-- 1) Converted to lua 5

-- 2) Some bug fixes 

-- 3) enabled it for normal users (not recommended)

-- 4) added allowuser check

-- 5) removed myinfo arrival (not needed)

--- --- --- --- --- --- ---

---  Awayer v3 --- idea by QuitckThinker

--- by Herodes

--- This bot has been writen offline and based on no other script

--- Although the initial idea for the AwayBot is from tezlo's RetroBot...

--- This diplays a prefix for those operators and above that are away

--- It also places the Away message in the users description ...

--- --- --- This script works only for Operators (as intended) --- --- ---

--- !away <reason>   --- <reason> is optional

--- !back

--- !awaylist

--- feel free to develop this further ... 

--- --- v 2 --- ---

--- currently has a problem with the following path ..

--- 1) <user> !away

--- 2) user reconnnects

--- 3) <user> !back

--- this produces a lot of shity names in the list ... dunno y ...:(

--- --- v 3 --- ---

--- fixed v2 problem but has abother one ...

--- following path ..

--- 1) <user> !away

--- 2) <user> <chatmsg> or <user> !back

--- 3) user disconnects ...

--- 4) user receives nickname reserved message (???)

--- --- all other scenarios I have tested and work fine ...

--- --- --- --- --- --- ---

tAways = {}



awpref = "[AWAY]"

defmsg = "Меня нет. Возможно я отвечу позже, если тебе Повезёт :)"

allowuser = true --(allows use of awayer for normal regged users,true/false )--> true not recommended might cause myinfo spam



function Main()

Bot = frmHub:GetHubBotName()

SetTimer(1000)

StartTimer()

end



function OnExit()

for nick, msg in tAways do

SendToAll("$Quit "..awpref..nick)

if GetItemByName(nick).bOperator then

SendToAll("$OpList "..nick)

end

if  GetItemByName(nick) then

SendToAll(GetItemByName(nick).sMyInfoString)

end

end

end



function NewUserConnected(user)

for nick, msg in tAways do

if GetItemByName(nick).bOperator then

user:SendData("$OpList "..awpref..nick)

end

if not GetItemByName(nick).bOperator  then

user:SendData(user.sMyInfoString)

end

end

end



function OpConnected (user)

NewUserConnected(user)

end



function OnTimer()

for nick, msg in tAways do

if GetItemByName(nick) then

SendToAll("$Quit "..nick)

SendToAll("$Quit "..nick)

end

end

end



function ToArrival(user, data)

local s,e,whoTo,from = string.find(data, "%$To:%s(%S+)%sFrom:%s(%S+)%s%$")

local _,__,msg = string.find(data, "%b<>%s+(%S+)")

if string.find(whoTo, awpref) then

SendPmToNick((string.sub(whoTo, string.len(awpref)+1, string.len(whoTo))),from, msg)

end

if tAways[whoTo] then

if tAways[whoTo]["reason"] then

SendPmToNick(from,awpref..whoTo, tAways[whoTo]["reason"].." <Awayer v4> ")

end

end



for nick,message in tAways do

if string.find(from, nick) then

SendPmToNick(whoTo,awpref..from, msg)

return 1

end

end

end



function ChatArrival(user, data)

local s,e,cmd,arg = string.find(data, "%b<>%s*(%S*)%s*(.*)|")

tCmds = {

["!away"] = function(user,data)

if not tAways[user.sName] then

local s,e,name,desc,tag, con,email,share   = string.find(user.sMyInfoString, "$MyINFO $ALL (%S+)%s+(.*)<([^$]+)$ $([^$]*)$([^$]*)$([^$]+)")

tAways[user.sName] = {}

tag=tag or "";

if arg == "" then arg= defmsg end

tAways[user.sName]["d"] = desc or ""

tAways[user.sName]["t"] = "<"..tag

tAways[user.sName]["c"] = con or ""

tAways[user.sName]["e"] = email or ""

tAways[user.sName]["s"] = share or 0

tAways[user.sName]["reason"] = arg

user:SendData("Awayer", "Вы теперь в режиме Away ..")

SendToAll("$MyINFO $ALL "..awpref..user.sName.." AwayMsg: "..arg..tAways[user.sName]["t"].."$ $"..tAways[user.sName]["c"].." $"..tAways[user.sName]["e"].."$"..tAways[user.sName]["s"].."$")

if user.bOperator then

SendToAll("$OpList "..awpref..user.sName)

end

SendToAll("$Quit "..user.sName)

else

user:SendData("Awayer", "Вы уже в режиме Away ... ")

SendToAll("$Quit "..awpref..user.sName)

end

end,

["!back"] = function(user,data)

if tAways[user.sName] then

SendToAll("$Quit "..awpref..user.sName)

SendToAll("Awayer", user.sName.." вернулся .. :)")

SendToAll(user.sMyInfoString)

if user.bOperator then

SendToAll("$OpList "..user.sName)

end

tAways[user.sName] = nil

else

user:SendData("Awayer", "Вы не в режиме Away... :)")

end

end,

["!awaylist"] = function(user,data)

local list = "Пользователь перешёл в режим Away\r\n"

local cnt = 0

for nick, msg in tAways do

cnt = cnt + 1

list = list.."\t"..cnt..". "..nick.."\tAway Msg : "..tAways[nick]["reason"].."\r\n"

end

user:SendData("Awayer",list)

end, }

if tCmds[cmd] then

if  user.bOperator or (user.bRegistered and allowuser) then

return tCmds[cmd](user,data),1

else

user:SendData(Bot,"ы незарегистрированный пользователь, у Вас нет прав для использования этой комманды!")

return 1

end

end

if tAways[user.sName] then

SendToAll("$Quit "..awpref..user.sName)

user:SendData("Awayer", "Вы заговорили в общем чате, теперь вы не Away.")

SendToAll(user.sMyInfoString)

if user.bOperator then

SendToAll("$OpList "..user.sName)

end

tAways[user.sName] = nil

end

end
Title: Re: error in script Awayer v 4.lua
Post by: Dessamator on 01 December, 2006, 14:38:12
To start with, you named ur script alarmbot and its got awayer's script inside. You've got an interesting way to name scripts.Ill assume you pasted the wrong script as im quite sure there is no arithmetic performed in the script you currently pasted.
Title: Re: error in script Awayer v 4.lua
Post by: [ vAiBhAv?] on 01 June, 2009, 17:01:07
hey dude, i had the same problem.. i switched over to a different script..
use this.. its good


--[[
Away 1.0 LUA 5.1
From LawMaker.
Sends away message.
No tag and other things like this.
You can see others' away messages w/o PMing them if you want.
Enjoy.
]]

-- // CONFIG
------------

-- The bot's data (will show in userlist):

Bot={
     name=frmHub:GetHubBotName(),
     desc="Bot.",
     email="Users Email",
   }

--[[
----------------------------------------------------------------------------------------
NO levels. If anyone is allowed to use it, I do not consider it a security risk myself.
Commands must be added without prefix, bot will detect them with prefix.
Syntax:

{"command","help text"},
----------------------------------------------------------------------------------------
]]

cmd={

-- Go away
afk={"away","afk"," Go away and leave a message (that's optional.)"},

-- Come back
back={"back","Come back if away."},

-- Shows whether you are away
mystatus={"mystatus","Shows whether you are away."},

-- Shows a specific user's or all users' away messages
showaways={"showaways"," Shows away messages of a user, with no option it shows all users'."},

-- guess :-]
awayhelp={"awayhelp","Guess! :-]"},

}
-------------------
-- // END OF CONFIG

afk={}

function away(user,data,env)
 if not afk[user.sName] then
   local _,_,why=string.find(data,"%b<>%s+%S+%s+(.+)")
   local Profile = GetProfileName(user.iProfile) or "Unregistered User"
   if not why then
     SendToAll(Bot.name,""..Profile.." "..user.sName.." went away at "..os.date("%X")..".")
     afk[user.sName]=os.date("%A, %c")
     
   else
     SendToAll(Bot.name,""..Profile.." "..user.sName.." went away at "..os.date("%X").." - Message : \""..why.."\".")
     afk[user.sName]=why.."|"..os.date("%A, %c")
     
   end
 else
   SendToAll(Bot.name,""..Profile.." "..user.sName.." returned at "..os.date("%X")..".")
   local _,_,why=string.find(data,"%b<>%s+%S+%s+(.+)")
   local Profile = GetProfileName(user.iProfile) or "Unregistered User"
   if not why then
     SendToAll(Bot.name,""..Profile.." "..user.sName.." went away at "..os.date("%X")..".")
     afk[user.sName]=os.date("%A, %c")
     
   else
     SendToAll(Bot.name,""..Profile.." "..user.sName.." went away at "..os.date("%X").." - Message : \""..why.."\".")
     afk[user.sName]=why.."|"..os.date("%A, %c")
     
   end
 end
end

function returned(user,data,env)
 if afk[user.sName] then
   local Profile = GetProfileName(user.iProfile) or "Unregistered User"
   SendToAll(Bot.name,""..Profile.." "..user.sName.." returned at "..os.date("%X")..".")
   afk[user.sName]=nil
   
 else
   SendTxt(user,env,Bot.name,"You weren't away, dude.")
 end
end

function awaymsg(user,whoTo)
 if not string.find(afk[whoTo],"%|") then
   user:SendPM(whoTo,"I went away on "..afk[whoTo]..".")
 else
   local _,_,why,dat=string.find(afk[whoTo],"(.+)%|(.+)")
   local Profile = GetProfileName(user.iProfile) or "Unregistered User"
   user:SendPM(whoTo,"I went away on "..os.date("%B %d %Y   %X ").."   Message : "..why..".")
 end
end

function myawaystatus(user,env)
 if afk[user.sName] then
   if not string.find(afk[user.sName],"%|") then
     else
     local _,_,why,dat=string.find(afk[user.sName],"(.+)%|(.+)")
 end
 else
   
 end
end

function showawaymsgs(user,data,env)
 awayarray={}
 local _,_,nick=string.find(data,"%b<>%s+%S+%s+(%S+)")
 if nick then
   if afk[nick] then
     if not string.find(afk[nick],"%|") then
       user:SendPM(Bot.name,nick.." went away at "..afk[nick].." and left no message.")
     else
       local _,_,why,dat=string.find(afk[nick],"(.+)|(.+)")
       user:SendPM(Bot.name,nick.." went away at "..dat.." and left this away message: "..why)
     end
   else
     user:SendPM(Bot.name,nick.." is not away or offline.")
   end
 else
   local msg="\r\n\r\n\t\t\t\t\t\tALL USERS' AWAY MESSAGES\r\n=================================================================================================================================\r\n\r\n"
   for a,b in afk do
     table.insert(awayarray,a)
     table.sort(awayarray)
   end
     if table.getn(awayarray)==0 then
       msg=msg.."Nobody is away.\r\n\r\n"
     else
       for a=1,table.getn(awayarray) do
       if not string.find(afk[awayarray[a]],"%|") then
         msg=msg..awayarray[a].." went away at "..afk[awayarray[a]].." and left no message.\r\n\r\n"
else
         local _,_,why,dat=string.find(afk[awayarray[a]],"(.+)|(.+)")
         msg=msg..awayarray[a].." went away at "..dat.." and left this away message: "..why.."\r\n\r\n"
end
     end
   end
   msg=msg.."================================================================================================================================="
 user:SendPM(Bot.name,msg)
 end; awayarray=nil; collectgarbage(); io.flush()
end

function saveaway()
 local f=io.open("away.dat","w+")
 for a,b in afk do
   f:write(a.."|"..b.."\n")
 end
 f:close()
end

function loadaway()
 local f=io.open("away.dat","r")
 if f then
   for line in f:lines() do
     local _,_,nick,msg=string.find(line,"(%S+)|(.+|.+)")
     afk[nick]=msg
   end
   f:close()
 end
end

function help(user)
 local msg=""
 for a,b in cmd do
   msg=msg.."\r\n"..b[1].." - "..b[2]
 end
 user:SendPM(Bot.name,msg)
end

function ParseCmd(user,data,c,env)
 local tmptbl= {
                 [cmd.afk[1]]={away,{user,data,env}},
                 
                 [cmd.back[1]]={returned,{user,data,env}},
                 
                 [cmd.mystatus[1]]={myawaystatus,{user,data,env}},
                 
                 [cmd.showaways[1]]={showawaymsgs,{user,data,env}},
                 
                 [cmd.awayhelp[1]]={help,{user,data,env}},
               }
 if tmptbl[c] then
   tmptbl[c][1](unpack(tmptbl[c][2]))
   return 1
 end
end

function Main()
 loadaway()
 frmHub:RegBot(Bot.name,1,Bot.desc,Bot.email)
end

function SendTxt(user,env,bot,text)
 if env=="PM" then
   user:SendPM(bot,text)
 else
   user:SendData(bot,text)
 end
end

function ToArrival(user,data)
 data=string.sub(data,1,string.len(data)-1)
 local _,_,whoTo = string.find(data,"$To:%s+(%S+)")
 if (whoTo == Bot) then
   local _,_,c = string.find(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+[%!%+%#](%S+)")
   if c then
     return ParseCmd(user,data,string.lower(c),"PM")
   end
 elseif afk[whoTo] then
   awaymsg(user,whoTo)
 end
end

function ChatArrival(user,data)
 data=string.sub(data,1,string.len(data)-1)
 local _,_,c = string.find(data,"%b<>%s+[%!%+%#](%S+)")
 if c then
   return ParseCmd(user,data,string.lower(c),"MAIN")
 end
end

function OnExit()
 saveaway()
end

NewUserConnected = function(user)
 user:SendData("$UserCommand 1 3 Hub Name\\Special Commands\\Away$<%[mynick]> +away %[line:Message]&#124;")
 user:SendData("$UserCommand 1 3 Hub Name\\Special Commands\\Back$<%[mynick]> +back&#124;")
end
OpConnected = NewUserConnected




USE THIS !
Title: Re: error in script Awayer v 4.lua
Post by: PPK on 01 June, 2009, 17:21:05
If you don't noticed, this topic is 2.5 years old... i'm sure that he don't need your help anymore  :P