PtokaX forum

Development Section => Your Developing Problems => Topic started by: Psycho_Chihuahua on 12 April, 2006, 19:58:28

Title: Is it possible..
Post by: Psycho_Chihuahua on 12 April, 2006, 19:58:28
..to read out the active scripts from the hub from within a script?
i've had a look at the Scripting-Interface.txt but can't find it in there.

If it is possible, an example would be fine as i'm trying to learn this stuff ;)
Title: Re: Is it possible..
Post by: Typhoon on 12 April, 2006, 20:13:25
you mean something like the !getscripts command in PtokaX ? ..
it can be done but the enabled/disabled status of the script don't update when you disable it in the script window.. i think it only updates on startup and shutdown.

Typhoon?
Title: Re: Is it possible..
Post by: Psycho_Chihuahua on 12 April, 2006, 20:16:24
yes exactly like the !getscripts command

even if it doesn't update when scripts get deactivated that wouldn't be a problem for me :) the scripts i have running are always enabled ;)
Title: Re: Is it possible..
Post by: Typhoon on 12 April, 2006, 20:34:54
great :) ..
it's acually quite simple all you need to do is read the /Cfg/Scripts.xml file ...

string.find() the script name and also the current status of it ..

then stuff the results in a table and then do a small for loop and output the data ..

let's hear the progress :)

Typhoon?
Title: Get Scripts - LUA 5.1
Post by: jiten on 12 April, 2006, 21:45:19
--[[

Get Scripts 1.0 - LUA 5.1 by jiten (4/12/2006)

]]--


ChatArrival = function(user, data)
local s,e,cmd = string.find(data,"^%b<>%s+[%!%+](%S+).*|$")
if cmd then
if tCommands[string.lower(cmd)] then
cmd = string.lower(cmd)
if tCommands[cmd].tLevels[user.iProfile] then
return tCommands[cmd].tFunc(user, data), 1
else
return user:SendData(frmHub:GetHubBotName(),"*** Error: You are not allowed to use this command!"), 1
end
end
end
end

tCommands = {
showscripts = {
tFunc = function(user)
local sMsg, sTmp = nil, ""
local f = io.open(frmHub:GetPtokaXLocation().."\\cfg\\Scripts.xml")
if f then sMsg = f:read("*all"); f:close(); end
if sMsg then
sMsg = string.gsub(sMsg,string.char(13,10),"");
local tTable = { [0] = "Disabled", [1] = "Enabled" }
for sScript,iStatus in string.gmatch(sMsg,"<Name>(.-)</Name>%s+<Enabled>(.-)</Enabled>") do
sTmp = sTmp.."\t* "..tTable[tonumber(iStatus)].." *\t\t"..sScript.."\r\n"
end
end
user:SendData(frmHub:GetHubBotName(),"\r\n\r\n\t"..string.rep("=",80).."\r\n\tStatus:\t\t\tScript:\r\n\t"..
string.rep("-",160).."\r\n"..sTmp)
end,
tLevels = {
[0] = 1, [1] = 1, [4] = 1, [5] = 1,
},
tRC = "Get Scripts$<%[mynick]> !{}"
},
}

NewUserConnected = function(user)
for i,v in pairs(tCommands) do
local sRC = string.gsub(v.tRC,"{}",i)
user:SendData("$UserCommand 1 3 "..sRC.."&#124;")
end
end

OpConnected = NewUserConnected
Title: Re: Is it possible..
Post by: Psycho_Chihuahua on 12 April, 2006, 22:17:51
nice one jiten - is it possible to do it in Lua 5.02? Sorry but i posted this in the wrong Section by mistake :(
Title: Re: Is it possible..
Post by: Psycho_Chihuahua on 12 April, 2006, 22:24:04
i know that Mutor - i want to build it into your InfoBot script to show the active scripts on hub connection
well at least thats what i'm trying to do
Title: Re: Is it possible..
Post by: Psycho_Chihuahua on 12 April, 2006, 22:37:24
cause i would like it to show the active scripts on connection in the InfoBot  ;D
Title: Re: Is it possible..
Post by: jiten on 13 April, 2006, 07:02:01
Quote from: Psycho_Chihuahua on 12 April, 2006, 22:17:51
nice one jiten - is it possible to do it in Lua 5.02? Sorry but i posted this in the wrong Section by mistake :(

Yes, it's possible. For the LUA 5.0.2 version, you just need to replace string.gmatch with string.gfind

Best regards