PtokaX forum

Archive => Archived 5.0 boards => Help with scripts => Topic started by: -Slash- on 23 August, 2005, 14:01:38

Title: LUA 5 IN DC++ CLIENTS
Post by: -Slash- on 23 August, 2005, 14:01:38
hi
i need some advices about scripting lua in dc++ client...
what does mean dcpp:setListener?
what are the other words that are basic and necessary in scripting lua in dc++?
es:hub:sendChat hub:injectChat ecc ecc.
Title:
Post by: bastya_elvtars on 23 August, 2005, 14:15:47
QuoteOriginally posted by -Slash-
hi
i need some advices about scripting lua in dc++ client...
what does mean dcpp:setListener?
what are the other words that are basic and necessary in scripting lua in dc++?
es:hub:sendChat hub:injectChat ecc ecc.

There is no documentation on it, you should tell us what you want to do and we will help you sort it out.
Title:
Post by: -Slash- on 23 August, 2005, 14:24:11
what is the command to send a string to all user in chat?
hub:sendChat???
Title:
Post by: bastya_elvtars on 23 August, 2005, 14:30:06
Yes.

hub:sendChat("Hey, I am just sending a chat message by script! :-)")
Title:
Post by: -Slash- on 23 August, 2005, 14:43:17
i'm making a script that after my command, start the timer and the script send in chat a mex every 30 minutes...
help me to make this script run correctly


--TimerScriptForClients

Tempo={}
--Nome bot
Bot="Spike401k"
--Timer
Tempo = 30
--Abilitazione script 1=abilitato, 0=disabilitato
TimeStatus=1
--comandi
Comando1="+inizia"
Comando2="+ferma"

frasi = {"\n ciao ecco il nuovo script per client fatto da slash",
      "\n ciao ecco il nuovo script per client fatto da slash",
}

c=table.getn(frasi)

function Main()
SetTimer(Tempo*60000)
   if TimeStatus==1 then
      StartTimer()
   end
dcpp:setListener( "timerscript", "Tempo",
function ( hub, text )
      local s = string.lower( text )
      if text == Commando1  then
         hub:sendChat(Bot,"Hai avviato lo script")
         TimeStatus=1
         StartTimer()
         return 1
      elseif text == Commando2  then
         hub:sendChat(Bot, "Hai fermato lo script")
         TimeStatus=0
         StopTimer()
         return 1
      end
end
)
function OnTimer()
if TimeStatus==1 then
TopA = frasi[math.random(1,c)]
hub:sendChat(""..Bot.." "..TopA.."")
end
end
end

DC():PrintDebug( "  ** TimerScriptForClients.lua ? stato caricato **" )
Title:
Post by: bastya_elvtars on 23 August, 2005, 15:15:42
Work in progress... I am totally a newbie when it comes to clientside scripting.
Title:
Post by: bastya_elvtars on 23 August, 2005, 16:11:53
--TimerScriptForClients
-- we cannot use botname here, only the client's nick
-- also there is no OnTimer(), everything goes by listeners here

--Timer
Tempo =1

--Abilitazione script 1=abilitato, 0=disabilitato
TimeStatus=1
--comandi
Comando1="+inizia"
Comando2="+ferma"

-- enter the IPs of the hubs you wanna make this work in
HubIPs=
  {
    ["127.0.0.1"]=1,
  }

frasi = {"\n ciao ecco il nuovo script per client fatto da slash",
"\n ciao ecco il nuovo script per client fatto da slash",
}

k=0



dcpp:setListener( "chat", "Tempo-all",
  function(hub,user,text)
    local s = string.lower( text )
    if text==Comando1 then
      hub:sendChat("Hai avviato lo script")
      TimeStatus=1
      return 1
    elseif text == Comando2 then
      hub:sendChat("Hai fermato lo script")
      TimeStatus=0
      return 1
    end
  end)


dcpp:setListener( "ownChatOut", "Tempo-own",
  function(hub,text)
    local s = string.lower( text )
    if text==Comando1 then
      hub:sendChat("Hai avviato lo script")
      TimeStatus=1
      return 1
    elseif text == Comando2 then
      hub:sendChat("Hai fermato lo script")
      TimeStatus=0
      return 1
    end
  end)

dcpp:setListener("timer","tmr",
  function ()
    if TimeStatus==1 then
      if k==Tempo*60 then
        local TopA = frasi[math.random(table.getn(frasi))]
        for _,hub in dcpp:getHubs() do
          if hubaddresses[hub:getAddress()] then
            hub:sendChat(TopA)
          end
        end
        k=0
      else
        k=k+1
      end
    end
  end)

DC():PrintDebug( " ** TimerScriptForClients.lua e stato caricato **" )
Title:
Post by: -Slash- on 23 August, 2005, 16:27:44
dcpp:setListener( "chat", "Tempo-all",
  function(hub,user,text)
    local s = string.lower( text )
    if text==Comando1 then
      hub:sendChat("Hai avviato lo script")
      TimeStatus=1
      return 1
    elseif text == Comando2 then
      hub:sendChat("Hai fermato lo script")
      TimeStatus=0
      return 1
    end
  end)

dcpp:setListener( "ownChatOut", "Tempo-own",
  function(hub,text)
    local s = string.lower( text )
    if text==Comando1 then
      hub:sendChat("Hai avviato lo script")
      TimeStatus=1
      return 1
    elseif text == Comando2 then
      hub:sendChat("Hai fermato lo script")
      TimeStatus=0
      return 1
    end
  end)

why did u written it 2 times?
only the dcpp:setListener changes...

PS:do u set casually the text near dcpp:setListener or not? --->"ownChatOut", "Tempo-own",    or "chat", "Tempo-all",
Title:
Post by: bastya_elvtars on 23 August, 2005, 16:39:10
Because otherwise it raises an error. You are using a weird way of 'thank you' by the way...

 :rolleyes:

-- // Edit

Sorted out:

--TimerScriptForClients
-- we cannot use botname here, only the client's nick
-- also there is no OnTimer(), everything goes by listeners here

--Timer
Tempo =1

--Abilitazione script 1=abilitato, 0=disabilitato
TimeStatus=1
--comandi
Comando1="+inizia"
Comando2="+ferma"

-- enter the IPs of the hubs you wanna make this work in
HubIPs=
  {
    ["127.0.0.1"]=1,
  }

frasi = {"\n ciao ecco il nuovo script per client fatto da slash",
"\n ciao ecco il nuovo script per client fatto da slash",
}

k=0

function Commands(hub,user,text)
  text=text or user
  local s = string.lower( text )
  if text==Comando1 then
    hub:sendChat("Hai avviato lo script")
    TimeStatus=1
    return 1
  elseif text == Comando2 then
    hub:sendChat("Hai fermato lo script")
    TimeStatus=0
    return 1
  end
end

dcpp:setListener( "chat", "Tempo-all",function (hub,user,text) return Commands(hub,user,text) end)
dcpp:setListener( "ownChatOut", "Tempo-own",function(hub,text) return Commands(hub,text) end)

dcpp:setListener("timer","tmr",
  function ()
    if TimeStatus==1 then
      if k==Tempo*60 then
        local TopA = frasi[math.random(table.getn(frasi))]
        for _,hub in dcpp:getHubs() do
          if HubIPs[hub:getAddress()] then
            hub:sendChat(TopA)
          end
        end
        k=0
      else
        k=k+1
      end
    end
  end)

DC():PrintDebug( " ** TimerScriptForClients.lua e stato caricato **" )
Title:
Post by: -Slash- on 23 August, 2005, 16:49:38
no no...i'm very grateful for your help...but i was so exciting to know how u did the script...however thank u!
PS:the script doestn't work...because after my command doesn't start the sentences with the timer
Title:
Post by: bastya_elvtars on 23 August, 2005, 16:57:23
QuoteOriginally posted by -Slash-
no no...i'm very grateful for your help...but i was so exciting to know how u did the script...however thank u!
PS:the script doestn't work...because after my command doesn't start the sentences with the timer

What hub address have you specified? It should be an IP, not a DNS. By the way I have found a minor annoyance as well, but fixed. ;-) Edited the above post.
Title:
Post by: -Slash- on 24 August, 2005, 00:39:41
nothing....doesn't work...

LUA Error: ...0.047\DCDM++-0.047\scripts\TimerScriptForClients.lua:50: attempt to index global `hubaddresses' (a nil value)

you are the only one who can hel me! =) tnks
Title:
Post by: bastya_elvtars on 24 August, 2005, 00:43:06
What if you used the latest code I posted?
Title:
Post by: -Slash- on 24 August, 2005, 00:47:44
yes...the last!
Title:
Post by: bastya_elvtars on 24 August, 2005, 00:51:34
QuoteOriginally posted by -Slash-
yes...the last!

Just asking because there is no 'hubaddresses' in it. Copy and save again.
Title:
Post by: -Slash- on 24 August, 2005, 00:58:46
what should i copy?
Title:
Post by: bastya_elvtars on 24 August, 2005, 01:14:29
QuoteOriginally posted by -Slash-
what should i copy?

The code I posted.
Title:
Post by: -Slash- on 24 August, 2005, 01:42:54
wow u are the best!!! now it work
thank u a lot!!!