LUA 5 IN DC++ CLIENTS
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

LUA 5 IN DC++ CLIENTS

Started by -Slash-, 23 August, 2005, 14:01:38

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

-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.

bastya_elvtars

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.
Everything could have been anything else and it would have just as much meaning.

-Slash-

what is the command to send a string to all user in chat?
hub:sendChat???

bastya_elvtars

Yes.

hub:sendChat("Hey, I am just sending a chat message by script! :-)")
Everything could have been anything else and it would have just as much meaning.

-Slash-

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 **" )

bastya_elvtars

Work in progress... I am totally a newbie when it comes to clientside scripting.
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

--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 **" )
Everything could have been anything else and it would have just as much meaning.

-Slash-

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",

bastya_elvtars

#8
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 **" )
Everything could have been anything else and it would have just as much meaning.

-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

bastya_elvtars

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.
Everything could have been anything else and it would have just as much meaning.

-Slash-

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

bastya_elvtars

What if you used the latest code I posted?
Everything could have been anything else and it would have just as much meaning.

-Slash-


bastya_elvtars

QuoteOriginally posted by -Slash-
yes...the last!

Just asking because there is no 'hubaddresses' in it. Copy and save again.
Everything could have been anything else and it would have just as much meaning.

-Slash-

what should i copy?

bastya_elvtars

QuoteOriginally posted by -Slash-
what should i copy?

The code I posted.
Everything could have been anything else and it would have just as much meaning.

-Slash-

wow u are the best!!! now it work
thank u a lot!!!

SMF spam blocked by CleanTalk