PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Help with scripts => Topic started by: TZB on 23 January, 2010, 12:45:23

Title: G-Bot
Post by: TZB on 23 January, 2010, 12:45:23
Hello Everyone i am here trying to learn and make AOI.Crazyguy helped me with most of this.Now i am stuck with few things in module.I am pasting the main code and the module to be loaded.I am having error in tables which i am not able to get it. Please if someone can help me make this things right and also help me how to improve the script since i am just a beginner.
Main script.
OnStartup = function()
local sPath = Core.GetPtokaXPath().."scripts/GBOT/"
pcall(dofile,sPath.."settings.ini")
sPath = sPath.."Modules/"
pcall(dofile,sPath.."LoginInfo.lua")


if tSettings and tLoginInfo then
Core.RegBot(tSettings.sBot.RegName,tSettings.sBot.Description,tSettings.sBot.Email,tSettings.sBot.Op)
local sInit = "tLoginInfo Init "
if tLoginInfo.Init() == true then
sInit = sInit.."was successful."
else
sInit = sInit.."was NOT successful."
end
Core.SendToAll(tSettings.sBot.Name..sInit)
tLoginInfo.Display()
                tLoginInfo.Function()
else
OnError()       
ScriptMan.StopScript("G-BOT.lua")
end
end


Settings.ini is loaded perfectly thanks to crazyguy. the another module is having some problem which i can't make it out.
tLoginInfo = {
Init = function()
local sPath = Core.GetPtokaXPath().."scripts/GBOT/Modules"
end,
            Display = {
                     Hubs = true,
                     Profile = true,
                     IP = true,
                     Desc = true,
                     },
            Function = {
            Info = function(user)
                   Core.GetUserAllData(user)
                   Msg = Msg.. "\r\n\tInformation"
                   Msg = Msg.. " Nick: " ..user.sNick
                   
               if tLoginInfo.Display.Profile then
                  Prof = ProfMan.GetProfile(user.iProfile)
                  if Prof then
                      Msg = Msg.. " Profile: " ..Prof.sProfileName
                  else
                      Msg = Msg.. " Profile: User " 
                  end
                end
               if tLoginInfo.Display.IP then
                      Msg = Msg.. " IP: " ..(user.sIP or "Unknown")
                end
               if tLoginInfo.Display.Desc then
                      Msg = Msg.. " Description: " ..(user.sDescription)
               end
               tCore.Send(user,Msg,1)
             end,
             },
                   
}


the error message is
Quote[17:13] Syntax D:\0.4.1.2-5.2.0-W2_2\scripts\G-BOT.lua:17: attempt to call field 'Display' (a table value)
Title: Re: G-Bot
Post by: TTB on 23 January, 2010, 14:01:36
You're calling a function which is not a function. You can't run a table value as a function.

What does it do when deleting this line?
tLoginInfo.Display()
Title: Re: G-Bot
Post by: TZB on 23 January, 2010, 14:03:55
I am still trying to get a grip on it TTB can you help me understand this.
Please.
Title: Re: G-Bot
Post by: TTB on 23 January, 2010, 14:40:56
A little help:

OnStartup = function()
local sPath = Core.GetPtokaXPath().."scripts/GBOT/"
pcall(dofile,sPath.."settings.ini")
sPath = sPath.."Modules/"
pcall(dofile,sPath.."LoginInfo.lua")


if tSettings and tLoginInfo then
Core.RegBot(tSettings.sBot.RegName,tSettings.sBot.Description,tSettings.sBot.Email,tSettings.sBot.Op)
local sInit = "tLoginInfo Init "
if tLoginInfo.Init() == true then
sInit = sInit.."was successful."
else
sInit = sInit.."was NOT successful."
end
Core.SendToAll(tSettings.sBot.Name..sInit)
else
--OnError()    DEFINE!       
ScriptMan.StopScript("G-BOT.lua")
end
end

-- Sorry, lazy to check the core thingie of PtokaX api. Fix it on your own :)
RegConnected = function(user)
tLoginInfo.Info(user)
end
OpConnected = RegConnected


tLoginInfo = {
Init = function()
local sPath = Core.GetPtokaXPath().."scripts/GBOT/Modules"
end,
Display = {
Hubs = true,
Profile = true,
IP = true,
Desc = true,
},
Info = function(user)
Core.GetUserAllData(user)
Msg = ""
Msg = Msg.. "\r\n\tInformation"
Msg = Msg.. " Nick: " ..user.sNick
if tLoginInfo.Display.Profile then
Prof = ProfMan.GetProfile(user.iProfile)
if Prof then
Msg = Msg.. " Profile: " ..Prof.sProfileName
else
Msg = Msg.. " Profile: User " 
end
end
if tLoginInfo.Display.IP then
Msg = Msg.. " IP: " ..(user.sIP or "Unknown")
end
if tLoginInfo.Display.Desc then
Msg = Msg.. " Description: " ..(user.sDescription)
end
tCore.Send(user,Msg,1)
end
}
Title: Re: G-Bot
Post by: TZB on 23 January, 2010, 15:19:03
Main == >
OnStartup = function()
local sPath = Core.GetPtokaXPath().."scripts/GBOT/"
pcall(dofile,sPath.."settings.ini")
sPath = sPath.."Modules/"
pcall(dofile,sPath.."LoginInfo.lua")


if tSettings and tLoginInfo then
Core.RegBot(tSettings.sBot.RegName,tSettings.sBot.Description,tSettings.sBot.Email,tSettings.sBot.Op)
local sInit = "tLoginInfo Init "
if tLoginInfo.Init() == true then
sInit = sInit.."was successful."
else
sInit = sInit.."was NOT successful."
end
Core.SendToAll(tSettings.sBot.Name..sInit)
                tLoginInfo.Info(user)
else
OnError()     
ScriptMan.StopScript("G-BOT.lua")
end
end


Module ==>
tLoginInfo = {
Init = function()
local sPath = Core.GetPtokaXPath().."scripts/GBOT/Modules"
end,
Display = {
Hubs = true,
Profile = true,
IP = true,
Desc = true,
},
        OpConnected = function(user)
tLoginInfo.Info(user)
end,
UserConnected =  function(user)
tLoginInfo.Info(user)
end,
RegConnected = function(user)
tLoginInfo.Info(user)
end,
Info = function(user)
Core.GetUserAllData(user)
Msg = ""
Msg = Msg.. "\r\n\tInformation"
Msg = Msg.. " Nick: " ..user.sNick
if tLoginInfo.Display.Profile then
Prof = ProfMan.GetProfile(user.iProfile)
if Prof then
Msg = Msg.. " Profile: " ..Prof.sProfileName
else
Msg = Msg.. " Profile: User " 
end
end
if tLoginInfo.Display.IP then
Msg = Msg.. " IP: " ..(user.sIP or "Unknown")
end
if tLoginInfo.Display.Desc then
Msg = Msg.. " Description: " ..(user.sDescription)
end
tCore.Send(user,Msg,1)
end
}

I know i am doing it too much going for this.
The error when i have this thing loaded is the core thing.
Quote[19:44] Syntax D:/0.4.1.2-5.2.0-W2_2/scripts/GBOT/Modules/LoginInfo.lua:22: bad argument #1 to 'GetUserAllData' (table expected, got nil)

and when i omit the tLoginInfo.Info(user) then the script shows no error though but the script sends a message of not loading.
Quote[19:44:50] <G-Bot> LoginInfo Init was NOT successful.
and now again i am stuck again with tables trying to figure out if anyone can send me some hints please.
Title: Re: G-Bot
Post by: TTB on 23 January, 2010, 15:54:14
Like I told you... the OnStartup() is not user defined! The user is unknown so you can't call your module in your Startup function!
Title: Re: G-Bot
Post by: TZB on 23 January, 2010, 21:42:47
Thanks Guy for all the help i am really very thankful.
TTB i am sharing the files so that others can also learn as you said.
Thanks CrazyGuy will be troubling you with another module soon. :P
I am sharing the files in finished scripts.