Author Topic: Several questions...  (Read 5537 times)

0 Members and 1 Guest are viewing this topic.

Offline Psycho_Chihuahua

  • Systemspecialist IT
  • Emperor
  • **
  • Posts: 1 054
  • Karma: +112/-1
  • I am wherever i want to be
    • PtokaX Luaboard
Several questions...
« on: 25 August, 2004, 17:47:42 »
how do i make an on/off switch for certain functions?

this one for instance:
Code: [Select]
function DataArrival( user , data )
if strsub( data , 1 , 7 ) == "$MyINFO" then
local _,_,openhubs = strfind( data , ".+H:(%d+)" );
if ( openhubs ~= "0" ) then
SendToNick( user.name , DisconnectMessage )
user:Disconnect()
end
end
end

Reason: I'm working on Black_Pearl 1.2 atm and i guess some (public) hubowners dont want this check to be done.

The other possibility would be to use it as an addon, hmmm dont know how to do that yet either.

Thanks for the effort ;)
« Last Edit: 26 February, 2006, 23:52:06 by bastya_elvtars »
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

PtokaX forum

Several questions...
« on: 25 August, 2004, 17:47:42 »

Offline Typhoon

  • Lord
  • ***
  • Posts: 397
  • Karma: +22/-3
  • PGE Developer
    • PGE Homepage
tt
« Reply #1 on: 26 August, 2004, 02:16:43 »
you can do it like this ..

Code: [Select]

OpenCheck = 1  -- 1=on/0=off

function DataArrival( user , data )
      if strsub( data , 1 , 7 ) == "$MyINFO" then
         local _,_,openhubs = strfind( data , ".+H:(%d+)" );
         if OpenCheck == 1 then
            if (openhubs ~= "0") then
               SendToNick( user.name , DisconnectMessage )
               user:Disconnect()
            end
         end
      end
end



Hope it helps you to see the point ;)

Typhoon?
« Last Edit: 26 August, 2004, 02:19:31 by Typhoon? »



Offline Psycho_Chihuahua

  • Systemspecialist IT
  • Emperor
  • **
  • Posts: 1 054
  • Karma: +112/-1
  • I am wherever i want to be
    • PtokaX Luaboard
tt
« Reply #2 on: 01 September, 2004, 07:17:06 »
Thnx Typhoon


Well i got another Question:

How do i make a Bot read its variable (on/off) settings out of an *.ini file?

Settings needed are:
Code: [Select]
GuardianCheck = 1
notifyOps = 1
banuser = 1
GuardianFile = "scripts/Data/Blocklist/guarding.p2p"
denyMsg = "*** This is a private hub. You have no business here. - Dies ist ein privater Hub. Du hast hier nichts verloren."
banMsg = "*** Your IP has been banned. - Deine IP wurde gebannt"
OpenCheck = 1  -- 1=on/0=off
DisconnectMessage = "Du bist in einen oder mehreren Open Hubs. Dies verst?sst gegen unsere Regeln. Deshalb wird die Verbindung zur?ckgesetzt! - You are in one or more Open Hubs which is against our Rules!! Connection Terminated..."
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Offline BottledHate

  • Triple Ace
  • **
  • Posts: 244
  • Karma: +2/-0
tt
« Reply #3 on: 01 September, 2004, 08:34:34 »
this should help....

Code: [Select]
readfrom("yourfile.bleh")
while 1 do
   local line = read()
   if (line == nil) then
      break
   else
      if strsub(line,1,9) =="Status =" then
         setting1=strsub(line,9,srlen(line))
      elseif strsub(line..........................
         setting2=strsub(line...............
      end
end
readfrom()

-BH
« Last Edit: 01 September, 2004, 08:34:58 by BottledHate »
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

Offline Psycho_Chihuahua

  • Systemspecialist IT
  • Emperor
  • **
  • Posts: 1 054
  • Karma: +112/-1
  • I am wherever i want to be
    • PtokaX Luaboard
tt
« Reply #4 on: 28 September, 2004, 02:09:51 »
ok..

lets say i have a script that has this in its Settings:
Code: [Select]
SendToMain = 0  -- Send in Main [if 0 send as PM]
then how would i make a cmd Trigger to change that

like !sendmainon sets it to 1 and !setmainoff sets it to 0?


The context its used by is
Code: [Select]
   if SendToMain==0 then
SendPmToAll(bot,tmp)
    else
SendToAll(bot,tmp)
    end
end
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Offline BottledHate

  • Triple Ace
  • **
  • Posts: 244
  • Karma: +2/-0
tt
« Reply #5 on: 28 September, 2004, 03:31:53 »
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

Offline sidetrack

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: tt
« Reply #6 on: 15 March, 2006, 15:16:51 »
Psycho_Chihuahua:
http://board.univ-angers.fr/thread.php?threadid=2847&boardid=4&styleid=1


-BH

That board is dead again.. and I am so needing to figure out how to edit or make changes to a txt/ini file that I have been struggleing with for a long time now.. this thread looked like what I wanted to finally find out. then hit a dead link ARRRRGGGG!

Offline plop

  • Forum God
  • ****
  • Posts: 2 464
  • Karma: +37/-0
Re: Several questions...
« Reply #7 on: 15 March, 2006, 20:40:43 »
push all settings into a table.
opening works a bit like this.
Code: [Select]
function OpenIni()
tSettings = {}
for line in io.lines("settings.ini") do
local s,e,sSet,sVar = string.find(line, "^([^=]+)=([^=]+)")
if sSet and sVar then
tSettings[sSet] = sVar
end
end
end

changing a value for a settings becomes really easy now.
tSettings[sSet] = "new value"

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Herodes

  • Guest
Re: Several questions...
« Reply #8 on: 15 March, 2006, 21:00:08 »
Wanna try a more advanced one ? :)
Not really tested .. it just my inspiration typing ..

Code: [Select]
--- can detect:
-- setting = 'value' | "value" | 0-9* | {...}
-- setting_boolean_like-constant
-- use like: tSettings = OpenIni( 'path/to/filename.ini' )

function OpenIni( file )
t = {}
for line in io.lines(file) do
local s,e,sSet,sVar = string.find(line, "^%s*([^=]+)=([^=]+)%s*$")
if sSet and sVar then
sVar = string.gsub( sVar, "^%s*(.-)%s*$", "%1" )
if string.sub(sVar, 1,1) == "'" or string.sub(sVar, 1,1 ) == "\"" then
t[sSet] = sVar
elseif string.find( sVar, "%d+" )then
local s,e, sNum = string.find( sVar, "(%d+)" )
t[sSet] = tonumber( sNum )
elseif string.sub( sVar, 1,1 ) = '{' and string.sub( sVar, -1 ) == '}' then
t[sSet] = dostring( sVal )
elseif string.lower(sVar) == 'true' or string.lower(sVar) == 'false' then
t[sSet] = true
end
else -- in this way you may do things in an other maybe more convenient way in some cases.
s,e, sSet = string.find( line, "^%s*(%S+)%s*$" )
if sSet then
t[sSet] = true
end
end
end
end

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 753
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: Several questions...
« Reply #9 on: 15 March, 2006, 22:16:40 »
The file management wikipage is being worked on...
Everything could have been anything else and it would have just as much meaning.

PtokaX forum

Re: Several questions...
« Reply #9 on: 15 March, 2006, 22:16:40 »