PtokaX forum

Development Section => Your Developing Problems => Topic started by: OneHero on 25 October, 2004, 19:12:16

Title: HOW-TO put 3 scripts into 1, or more?
Post by: OneHero on 25 October, 2004, 19:12:16
can some1 help me here?
Title:
Post by: bastya_elvtars on 25 October, 2004, 19:39:54
if you dont post the scripts: NO
Title:
Post by: Psycho_Chihuahua on 25 October, 2004, 20:04:45
QuoteOriginally posted by OneHero
can some1 help me here?


you gotta


put all the data arrivals/main functions/other functions together in a blender and press the switch   :D

but seriously, without knowing whitch  scripts you wann put together, noone can help you properly
Title:
Post by: Herodes on 25 October, 2004, 20:43:48
has anyone mentioned that the scripts should be posted too ?
Title:
Post by: OneHero on 26 October, 2004, 07:03:09
i was speaking generally... if i want to put some script together, how? is there a program or do i have to be an expert in .lua?
Title:
Post by: Typhoon on 26 October, 2004, 09:45:38
theres only 1 program capable of it, thats your brain

Typhoon?
Title:
Post by: OneHero on 27 October, 2004, 07:26:22
okey :D then i ask :

how to put these 2 scipts together?

script 1

-- FreshStuff v.3.4
-- original idea/script by chilla
-- completely rewriten by plop
-- if you were running 3.0 then you gotta delete the old file
-- it's incompatible with this version
-- deleting now goes by id number
-- anounces the new releas in mainchat

-- Name the commands to what U like
-- This command adds stuff, syntax : !addrelease TYPE/CATAGORY THESTUFF2ADD
cmd1 = "!addrelease"

-- This command shows the stuff, syntax : !releases with options new/game/warez/music/movie
cmd2 = "!releases"

-- This command deletes an entry, syntax : !delrelease THESTUFF2DELETE
cmd3 = "!delrelease"

-- This command shows the latest stuff, syntax : !newreleases
cmd4 = "!newreleases"

-- This command reloads the txt file. syntax : !reloadreleases
-- (this command is needed if you manualy edit the text file)
cmd5 = "!reloadreleases"

-- Show latest stuff on entry 1=yes, 0=no
ShowOnEntry = 0

-- Max stuff shown on newalbums/entry
MaxNew = 20

-- The file storing the stuff
file = "txt/AlbumsAll.txt"

-- Name of the bot
Bot = "-=NorwegianHeros=-"

-- you can add catagory's yourself ["trigger_name"]="catagory_name"
Types = {["movie"] = "Movies", ["music"]="Music", ["warez"]="Warez", ["game"]="Games"}

--------------------- don't change anything below here
AllStuff = {}
NewestStuff = {}

function Main()
   frmHub:RegBot(Bot)
   ReloadRel()
end

function NewUserConnected(user)
   if ShowOnEntry == 1 then
      user:SendPM(Bot, MsgNew.."|")
   end
end

function OpConnected(user)
   if ShowOnEntry == 1 then
      user:SendPM(Bot, MsgNew.."|")
   end
end

function DataArrival(user,data)
   if (strsub(data, 1, 1) == "<") then
      data = strsub(data,1,strlen(data)-1)
      s,e,cmd,type,tune = strfind(data, "%b<>%s+(%S+)%s*(%S*)%s*(.*)")
      if cmd == cmd2 then
         if type == "" then
            user:SendPM(Bot, MsgAll.."|")
         elseif type == "new" then
            user:SendPM(Bot, MsgNew.."|")
         elseif Types[type] then
            ShowRelType(type)
            user:SendPM(Bot, MsgType.."|")
         end
         return 1
      elseif cmd == cmd4 then
         user:SendPM(Bot, MsgNew.."|")
         return 1
      elseif user.bOperator then
         if cmd == cmd3 then
            if type ~= "" then
               DelRel(user, type)
            else
               user:SendData(Bot, "yea right, like i know what i got 2 delete when you don't tell me!|")
            end
            return 1
         elseif cmd == cmd1 then
            if tune ~= "" and Types[type] then
              AddRel(user, tune, type)
            elseif Types[type] == nil then
               user:SendData(Bot, "I need to know the catagory to add it to!|")
            else
               user:SendData(Bot, "yea right, like i know what you got 2 add when you don't tell me!|")
            end
            return 1
         elseif cmd == cmd5 then
            Reload()
            user:SendData(Bot, "Albums reloaded!|")
            return 1
         end
      elseif user.iProfile == 2 then
         if cmd == cmd1 then
            if tune ~= "" and Types[type] then
               AddRel(user, tune, type)
            elseif Types[type] == nil then
               user:SendData(Bot, "I need to know the catagory to add it to!|")
            else
               user:SendData(Bot, "yea right, like i know what you got 2 add when you don't tell me!|")
            end
            return 1
         end
      end
   end
end

function OpenRel()
   AllStuff = nil
   NewestStuff = nil
   AllStuff = {}
   NewestStuff = {}
   Count = 0
   Count2 = 0
   readfrom(file)
   while 1 do
      local line = read()
      if ( line == nil ) then
         break
      else
         Count = Count +1
         AllStuff[Count]=line
      end
   end
   readfrom()
   if Count > MaxNew then
      local temp = Count - MaxNew + 1
      for i=temp, Count do
         Count2 = Count2 + 1
         NewestStuff[Count2]=AllStuff[i]
      end
   else
      for i=1, Count do
         Count2 = Count2 + 1
         NewestStuff[Count2]=AllStuff[i]
      end
   end
end

function ShowRel(table)
   Msg = "\r\n"
   if table == NewestStuff then
      if Count2 == 0 then
         MsgNew = "\r\n\r\n".." --------- The Latest Releases -------- \r\n\r\n  No releases on the list yet\r\n\r\n --------- The Latest Releases -------- \r\n\r\n"
      else
         for i=1, Count2 do
            s,e,type,who,when,title=strfind(NewestStuff[i], "(.+)$(.+)$(.+)$(.+)")
            if title then
               Msg = Msg.."  "..when.." -- "..who.." -- "..type.." -- "..title.."\r\n"
            else
               Msg = Msg..NewestStuff[i].."\r\n"
            end
         end
         MsgNew = "\r\n\r\n".." --------- The Latest "..MaxNew.." Releases -------- "..Msg.."\r\n --------- The Latest "..MaxNew.."  Releases -------- \r\n\r\n"
      end
   else
      if Count == 0 then
         MsgAll = "\r\n\r\r\n".." --------- All The Releases -------- \r\n\r\n  No releases on the list yet\r\n\r\n --------- All The Releases -------- \r\n\r\n"
      else
         MsgHelp = "  use "..cmd2.."          for a,b in Types do
            MsgHelp = MsgHelp.."/"..a
         end
         MsgHelp = MsgHelp.."> to see only the selected types"
         for i=1, Count do
            s,e,type,who,when,title=strfind(AllStuff[i], "(.+)$(.+)$(.+)$(.+)")
            if title then
               Msg = Msg.."  ID: "..i.." -- "..when.." -- "..who.." -- "..type.." -- "..title.."\r\n"
            else
               Msg = Msg..AllStuff[i].."\r\n"
            end
         end
         MsgAll = "\r\n\r\r\n".." --------- All The Releases -------- "..Msg.."\r\n --------- All The Releases -------- \r\n"..MsgHelp.."\r\n"
      end
   end
end

function ShowRelType(what)
   Msg = "\r\n"
   tmp = 0
   if Count == 0 then
      MsgType = "\r\n\r\n".." --------- All The "..Types[what].." -------- \r\n\r\n  No "..strlower(Types[what]).." yet\r\n\r\n --------- All The "..Types[what].." -------- \r\n\r\n"
   else
      for i=1, Count do
         s,e,type,who,when,title=strfind(AllStuff[i], "(.+)$(.+)$(.+)$(.+)")
         if type == what then
            tmp = tmp + 1
            Msg = Msg.."  "..when.." -- "..who.." -- "..title.."\r\n"
         end
      end
      if tmp == 0 then
         MsgType = "\r\n\r\n".." --------- All The "..Types[what].." -------- \r\n\r\n  No "..strlower(Types[what]).." yet\r\n\r\n --------- All The "..Types[what].." -------- \r\n\r\n"
      else
         MsgType= "\r\n\r\n".." --------- All The "..Types[what].." -------- \r\n"..Msg.."\r\n --------- All The "..Types[what].." -------- \r\n\r\n"
      end
   end
end

function AddRel(user, what, type)
   Count = Count + 1
   AllStuff[Count]=(type.."$"..user.sName.."$"..date("%x").."$"..what)
   user:SendData(Bot, what.." is added to the releases as "..type.."|")
   SendToAll(Bot, user.sName.." added to the "..type.." releases: "..what.."|")
   SaveRel()
   ReloadRel()
end

function DelRel(user, what)
   if tonumber(what) then
      what = tonumber(what)
      if AllStuff[what] then
         local s,e,which=strfind(AllStuff[what], "([^%$]+)$")
         user:SendData(Bot, which.." is deleted from the releases|")
         AllStuff[what]=nil
         SaveRel()
         ReloadRel()
      else
         user:SendData(Bot, what.." wasn't found in the releases|")
      end
   else
      user:SendData(Bot, "I need the ID number to delete a releas|")
   end
end

function SaveRel()
   writeto(file)
   for i=1,Count do
      if AllStuff[i] then
         write(AllStuff[i].."\n")
      end
   end
   writeto()
end

function ReloadRel()
   OpenRel()
   ShowRel(NewestStuff)
   ShowRel(AllStuff)
end

function DelRelOld(user, what)
   Okie = nil
   for a,b in AllStuff do
      s,e,title=strfind(b, ".+$(.+)$")
      if title == what then
         AllStuff[a]=nil
         user:SendData(Bot, what.." is removed from the releases|")
         Okie = 1
         break
      end
   end
   if Okie then
      SaveRel()
      ReloadRel()
   else
      user:SendData(Bot, what.." wasn't found in the releases|")
   end
end

script 2

-- texter bot by plop
-- thx 2 chilla for the faster routine for opening the files
-- shows text files from a folder named text.
-- doesn't mather what prefix it used.
-- if the file excist it shows.

Bot = "-=NorwegianHeros=-"
FDFolder = "text"

function Main()
   frmHub:RegBot(Bot)
end

function DataArrival(user, data)
   data=strsub(data,1,strlen(data)-1)
   if( strsub(data, 1, 1) == "<" ) then
      s,e,cmd = strfind(data,"%b<>%s+%S(%w+)")
      if cmd and readfrom(FDFolder.."/"..cmd..".txt") then
         showtext(user, cmd)
         return 1
      end
   elseif(strsub(data, 1, 4) == "$To:") then
      s,e,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+%S(%w+)")
      if cmd and readfrom(FDFolder.."/"..cmd..".txt") then
         showtext(user, cmd)
         return 1
      end
   end
end

function showtext(user, file)
local handle = openfile(FDFolder.."/"..file..".txt", "r")
local contents = gsub(read(handle, "*a"),strchar(10), "\r\n")
closefile (handle)
user:SendPM(Bot, "\r\n"..contents.."\r\n|")
end
Title:
Post by: Herodes on 27 October, 2004, 11:07:44
you know what ?  that is interesting ...
I'll be back later with smth ..
(I thought you wanted 3 in 1 ... :)
Title:
Post by: OneHero on 28 October, 2004, 07:02:11
your right, i wanted 3 scripts in one, but couldnt get all 3 scripts in one post :D but here is the 3rd script, so now you can try to put the 3 in 1 script :D
-- PostMan Bot 0.1 by bastya_elvtars (the rock n' roll doctor)
-- offline message system
-- you can set the inbox size and the bot name
-- code ripped from law maker bot
-- comands can be PMed or typed in main, the bot responds to them according to the environment (sometimes at least :D)
-- the commands are case insensitive, the parameters aren't :)
-- 0.2: added function so ppl cannot post 2 offline users

------------- settings

Bot="-=NorwegianHeros=-" -- he he he

inboxsize=10 -- the maximum amount of messages users can have in their inbox

------------ end of settings

function Main()
if not readfrom("offline.ini") then message={} else dofile("offline.ini") end
frmHub:RegBot(Bot)
end

function loadlist(file) -- to see if the user was in the hub at all
table=nil
table={}
readfrom(file)
while 1 do
local line = read()
if line == nil then
readfrom()
break
end
table[line] = 1
end
readfrom()
if table then
return table
else
return {}
end
end

function savefile(table,file) -- save users names who were in the hub
writeto(file)
for a,b in table do
write(a.."\n")
end
writeto()
end

function postmsg(user,data,env)
local _,_,nick,msg=strfind(data,"%b<>%s+%S+%s+(%S+)%s+(.*)")
if nick then
if not GetItemByName(nick) then
local washere=loadlist("washere.lst")
if not washere then washere={} end
if washere[nick] then
if not message[nick] then
message[nick]={[1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}}
user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
savemsg()
else
if checksize(nick)>=inboxsize then -- >= only for safety lol
user:SendData(parseenv(user,env,Bot).."Sorry, but "..nick.." has a full inbox. Try again later.")
else
message[nick][checksize(nick)+1]={["message"]=msg,["who"]=user.sName,["when"]=date("%Y. %m. %d. %X"),["read"]=0}
user:SendData(parseenv(user,env,Bot).."Successfully sent the message!")
savemsg()
end
end
else
user:SendData(parseenv(user,env,Bot).."User "..nick.." has never been in the hub.")
end
else
user:SendData(parseenv(user,env,Bot)..nick.." is online! PM would be simpler in this case...")
end
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !postmsg ")
end
end

function readmsg (user,data,env)
if message[user.sName] then
local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
if args then
gsub(args,"(%d+)",function(nmbr)
nmbr=tonumber(nmbr)
if message[%user.sName][nmbr] then
local msg="\r\n\r\n\t\t\t\t\t\t\tMessage #"..nmbr.."\r\n=================================================================================================================================\r\n\r\nFrom: "..message[%user.sName][nmbr]["who"].."\r\nTime of sending: "..message[%user.sName][nmbr]["when"]..
"\r\nMessage: "..message[%user.sName][nmbr]["message"].."\r\n\r\n================================================================================================================================="
%user:SendPM(Bot,msg)
if message[%user.sName][nmbr]["read"]==0 then
message[%user.sName][nmbr]["read"]=1
savemsg()
end
else
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
end
end)
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !showmsg . Multiple numbers can be added separated by spaces.")
end
else
user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
end
end

function numess(nick,a)
if message[nick][a]["read"]==0 then return "no"
else return "yes" end
end

function inbox (user,env)
local msg="\r\n\r\n\t\t\t\t\t\t\tHere is your inbox:\r\n================================================================================================================================="..
"\r\nMessage #\t\t\tSender\t\t\t\t\tTime of sending\t\t\t\t\tRead\r\n================================================================================================================================="
if message[user.sName] then
for a,b in message[user.sName] do
msg=msg.."\r\n"..a.."\t\t\t\t"..b["who"].."\t\t\t"..b["when"].."\t\t\t\t"..numess(user.sName,a).."\r\n================================================================================================================================="
end
user:SendPM(Bot,msg)
user:SendPM(Bot,"Type !readmsg too see an individual message. Multiple numbers can be added separated by spaces.")
if checksize(user.sName) >= inboxsize then
user:SendPM(Bot,"Alert: Your inbox is full!")
end
else
user:SendData(parseenv(user,env,Bot).."You have no messages.")
end
end

function checksize(nick)
local array={}
for a,b in message[nick] do
tinsert(array,a)
end
return getn(array)
end

function delmsg(user,data,env)
if message[user.sName] then
local _,_,args=strfind(data,"%b<>%s+%S+%s+(.+)")
if args then
gsub(args,"(%d+)",function (nmbr)
nmbr=tonumber(nmbr)
if message[%user.sName][nmbr] then
message[%user.sName][nmbr]=nil
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." has been successfully deleted!")
else
%user:SendData(parseenv(%user,%env,Bot).."Message #"..nmbr.." does not exist!")
end
end)
if checksize(user.sName)==0 then
message[user.sName]=nil
savemsg()
else
local array={}
for a,b in message[user.sName] do
tinsert(array,b)
end
for i=1,getn(array) do
message[user.sName]=resort(array)
end
savemsg()
end
else
user:SendData(parseenv(user,env,Bot).."Bad syntax! Usage: !delmsg . Multiple numbers can be added separated by spaces.")
end
else
user:SendData(parseenv(user,env,Bot).."Your inbox is empty.")
end
end

function resort(array)
local tbl={}
for i=1,getn(array) do
tbl[i]=array[i]
end
return tbl
end
-- nmbr, who, when, message
function parse(tbl)
local cnt=""
for a,b in tbl do
cnt=cnt.."\t\t\t\t\t\t\t\t\t["..a.."]=\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t[\"who\"]=\""..b["who"].."\",\n\t\t\t\t\t\t\t\t\t[\"when\"]=\""..b["when"]..
"\",\n\t\t\t\t\t\t\t\t\t[\"message\"]=\""..b["message"].."\",\n\t\t\t\t\t\t\t\t\t},\n"
end
return cnt
end

function savemsg()
writeto("offline.ini")
local what="message=\n{"
for a,b in message do
what=what.."\n\t\t\t[\""..a.."\"]={\n"..parse(b).."\t\t\t},"
end
what=what.."\n}"
write(what)
writeto()
end

function parseenv(user,env,bot)
if env=="PM" then
return "$To: "..user.sName.." From: "..bot.." $<"..bot.."> "
elseif env=="MAIN" then
return "<"..bot.."> "
end
end

function NewUserConnected(user)
local washere=loadlist("washere.lst")
if not washere then washere={} end
if not washere[user.sName] then
washere[user.sName]=1
savefile(washere,"washere.lst")
end
if message[user.sName] then
local count={[user.sName]=0}
for a,b in message[user.sName] do
if b["read"]==0 then
count[user.sName]=count[user.sName]+1
end
end
if count[user.sName]>0 then
user:SendPM(Bot,"You have "..count[user.sName].." new messages. Type !inbox to see your inbox!")
end
end
end

function DataArrival(user,data)
if strsub(data,1,1)=="<" then
data=strsub(data,1,strlen(data)-1)
local _,_,cmd = strfind(data,"%b<>%s+(%S+)")
cmd=strlower(cmd)
return parsecmds(user,data,cmd,"MAIN")
elseif strsub(data, 1, 4) == "$To:" then
data=strsub(data,1,strlen(data)-1)
local _,_,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == Bot) then
local _,_,cmd = strfind(data,"$To:%s+%S+%s+From:%s+%S+%s+$%b<>%s+(%S+)")
cmd=strlower(cmd)
return parsecmds(user,data,cmd,"PM")
end
end
end

function parsecmds(user,data,cmd,env)
local returndata=0
if cmd=="!postmsg" then
postmsg(user,data,env) returndata=1
elseif cmd=="!readmsg" then
readmsg (user,data,env) returndata=1
elseif cmd=="!inbox" then
inbox(user,env) returndata=1
elseif cmd=="!delmsg" then
delmsg(user,data, env) returndata=1
end return returndata
end

function UserDisconnected(user)
local washere=loadlist("washere.lst")
if not washere then washere={} end
if not washere[user.sName] then
washere[user.sName]=1
savefile(washere,"washere.lst")
end
end

function OnExit()
savemsg()
end

OpDisconnected=UserDisconnected
OpConnected=NewUserConnected
Title:
Post by: Corayzon on 31 October, 2004, 05:25:06
u can use cSlave ;)

but there is no point cause adding 3 ptokax scripts like so wouldnt save process on the server ;)

and thats what cSlave does!

noza
Title:
Post by: Corayzon on 31 October, 2004, 06:57:22
i could go on for hours Mutor

noza
Title:
Post by: Corayzon on 31 October, 2004, 07:03:51
ur pathetic mate!

grow up and get with the program!

noza
Title:
Post by: Corayzon on 31 October, 2004, 07:06:42
*walks away*

noza
Title:
Post by: plop on 31 October, 2004, 14:56:22
c-slave is a kind of collection of functions.
with it it's very easy 2 create your own script.
a perfect tool for ppl who want 2 learn lua scripting on ptokax.

plop
Title:
Post by: OneHero on 31 October, 2004, 18:20:39
where can i dl this program?