Author Topic: display txt from file  (Read 3650 times)

0 Members and 1 Guest are viewing this topic.

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
display txt from file
« on: 28 September, 2004, 22:51:21 »
I'm makeing a "FunScript"
And i want a function that reads some SendToAll lines from a txt

Ex..
If !insult Madman then
do insult.txt
SendToAll(Bot, Random text in insult.txt)

Ex.. of a line to send ;)
SendToAll("*** "..curUser.sName.." thinks that  "..vUser.sName.." smells like a 120 year old dead body ")
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

PtokaX forum

display txt from file
« on: 28 September, 2004, 22:51:21 »

Offline EXNET OWNER

  • Member
  • ***
  • Posts: 43
  • Karma: +0/-0
...
« Reply #1 on: 29 September, 2004, 02:00:27 »
couldnt you do a random table like

RandomTable = {
["you stink"]=1,
["f**k you"]=2,
}

then say where it says random do 1-5 for example, easier than reading from a .txt file???

just an idea, i am tired so i dont know if i am making any sense
« Last Edit: 29 September, 2004, 02:01:24 by EXNET OWNER »

Offline BottledHate

  • Triple Ace
  • **
  • Posts: 244
  • Karma: +2/-0
(No subject)
« Reply #2 on: 29 September, 2004, 03:13:27 »
Quote
Originally posted by madman
I'm makeing a "FunScript"
And i want a function that reads some SendToAll lines from a txt

Ex..
If !insult Madman then
do insult.txt
SendToAll(Bot, Random text in insult.txt)

Ex.. of a line to send ;)
SendToAll("*** "..curUser.sName.." thinks that  "..vUser.sName.." smells like a 120 year old dead body ")

have a look at StabBot (hubs scripts)... it can easily be an insult bot..
 all you have to do is add your replies to the file.. and
 chage the user defined commands. it reads the replies
from a file on load, and displays them at random when
triggered. so other silly stuff in there too... ;)


-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
(No subject)
« Reply #3 on: 29 September, 2004, 19:48:33 »
Thanks BH =)

Can anybody help me with this?

I took this code to use with my insult function
Code: [Select]
function DataArrival(curUser, data)
if strsub(data, 1, 1) == "<" then
local _,_,cmd=strfind(data, "%b<>%s+(%S+).+")
local IUser = curUser.sName
local _,_,junk=strfind(data, "%b<>%s+%S+%s+(.+)|")
local requestString = ""
if cmd == "!insult" then
local answer,victim = Stabs[random(getn(Stabs))], junk
answer = gsub( answer, "(%[CURUSER%])", IUser )
answer = gsub( answer, "(%[VIC%])", victim )
SendToAll( answer.."|" )
end
end
end

Now.. Since it allready is a DataArival in the script
And i placed the code in it...
I though i could do this
Code: [Select]
--function DataArrival(curUser, data)
-- if strsub(data, 1, 1) == "<" then
local _,_,cmd=strfind(data, "%b<>%s+(%S+).+")
local IUser = curUser.sName
local _,_,junk=strfind(data, "%b<>%s+%S+%s+(.+)|")
local requestString = ""
if cmd == "!insult" then
local answer,victim = Stabs[random(getn(Stabs))], junk
answer = gsub( answer, "(%[CURUSER%])", IUser )
answer = gsub( answer, "(%[VIC%])", victim )
SendToAll( answer.."|" )
end
-- end
--end

And would still work...
but instead i get this..

Syntax error: bad argument #3 to `gsub' (string or function expected)
stack traceback:
   1:  function `gsub' [C]
   2:  function `DataArrival' at line 114 [file `...ram\Hub\PtokaX-0.330 madhouse\scripts\Funv3.lua']

Why?

Btw this is line 114
answer = gsub( answer, "(%[VIC%])", victim )
And what can i do to be able to remove The Second DataArival? (2nd is in that code)
« Last Edit: 30 September, 2004, 01:16:19 by madman »
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Offline BottledHate

  • Triple Ace
  • **
  • Posts: 244
  • Karma: +2/-0
(No subject)
« Reply #4 on: 30 September, 2004, 02:52:05 »
the prob is in here:
Code: [Select]

local answer,victim = Stabs[random(getn(Stabs))], junk


what is your table with the answers called?? is it Stabs? ....
also have a look at the answers file in stabot for a look at the  format to set up your table.

post you data arrival as it is now, and i'll tell you how to remove that extra junk...

hope that helps.....


-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
(No subject)
« Reply #5 on: 30 September, 2004, 03:31:10 »
My Script looks like this now...
The test version that is.. got many more cmds in the orginal....And Aslo got the OutThrow function for the throw command ;p


Code: [Select]
--//Fun Script Made By Madman
--//Thanks NightLitch for the help with the victim function
--//Sendto Stuff stolen from zRightClicker ;p
--//Version 2
--//Random Function Added... Do You Feel Lucky? ;p
--//Random Re written, Now Works Correct..
--//-=NewCommand=- Added Beacuse It Is So Many Commands
--//"Rewrote" --==NewCommand==-- ;p Now Script More Sorted
--//--==NewVictimCommand==-- Added
--//--==NewFunctionCommand==-- Added
--//Version 3
--//Stab Commandd Added Thankx BottledHate
--//Stab Text Readed From FunScript.txt

--//Add Ver 2 cmd later!


Bot = "FunScript"
dofile("FunScript.txt")

--// This function is fired at the serving start
function Main()
frmHub:RegBot(Bot)
end

--//User To send Text 2 (Victim function)
-- 1=on / 0=off
SendTo = {
[0] = 0,   -- Masters
[1] = 1,   -- Operators
[2] = 1,   -- Vips
[3] = 1,   -- Regs
[4] = 0,   -- Moderator
[5] = 0,   -- NetFounder
[-1] = 1,  -- Users
}

--// This function is fired when a new data arrives
function DataArrival(curUser,data)
if strsub(data, 1, 1) == "<" then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data,"%b<>%s+(%S+)")
--==NewVictimCommand==--
--//Victim funtion
--//Call command
if cmd == "!throw" then
--//Parse the data string to catch the "victim" nick
local s,e,victim = strfind(data,"%b<>%s+%S+%s+(%S+)")
--//if no victim nick entered then return syntax message
if victim == nil then
curUser:SendData(Bot, "Syntax: !throw nick")
return 1
end
--//Check if nick/user is online
vUser = GetItemByName(victim)
if not vUser then
curUser:SendData(Bot, " *** " ..victim.." is not online or wrong name...")
return 1
end
--//Check if you is victim
if curUser.sName == vUser.sName then
curUser:SendData(Bot, "Why throw your self?")
return 1
end
--//Safe Function 4 Ops
if vUser.bOperator then
--//Send sendData To Users in Send To List (in the begining....)
if (SendTo[curUser.iProfile]==1) then
curUser:SendData(Bot, "You Are Not Allowd To Throw Ops!")
--//But if master or higher, throw user and skip above text... Mohaha! Evil!
elseif (curUser.iProfile == 0) and (vUser.bOperator) then
--//Do the "Throw" code here...
--//Random function
OPThrow = random (2)
--//Throw victim
if OPThrow == 1 then
SendToAll(Bot, vUser.sName.." has been thrown out of the hub by "..curUser.sName)
vUser:SendData(Bot, "You have been thrown out of the hub by "..curUser.sName.."!")
vUser:Disconnect()
elseif OPThrow == 2 then OutThrow(curUser)
--//Ops... Throwed your self (Unless OutThrow)
-- SendToAll(Bot, curUser.sName.." got unlucky and throwed him/herself out "..curUser.sName)
-- curUser:SendData(Bot, "Whoops.. You throwed your self out"..curUser.sName.."!")
-- curUser:Disconnect()
end
--//End of random fuction
end
--//End of Safe function
else
--//Do the "Throw" code here...
UserThrow = random (2)
--//Throw victim
if UserThrow == 1 then
SendToAll(Bot, vUser.sName.." has been thrown out of the hub by "..curUser.sName)
vUser:SendData(Bot, "You have been thrown out of the hub by "..curUser.sName.."!")
vUser:Disconnect()
elseif UserThrow == 2 then OutThrow(curUser)
--//Ops... Throwed your self (Unless OutThrow)
-- SendToAll(Bot, curUser.sName.." got unlucky and throwed him/herself out "..curUser.sName)
-- curUser:SendData(Bot, "Whoops.. You throwed your self out"..curUser.sName.."!")
-- curUser:Disconnect()
end
end
end
--//End of vicim function
--==NewVictimCommand==--
--//Stab function
function DataArrival(curUser, data)
if strsub(data, 1, 1) == "<" then
local _,_,cmd=strfind(data, "%b<>%s+(%S+).+")
local User = curUser.sName
local _,_,junk=strfind(data, "%b<>%s+%S+%s+(.+)|")
local requestString = ""
if cmd == "!stab" then
local answer,victim = Stabs[random(getn(Stabs))], junk
answer = gsub( answer, "(%[CURUSER%])", User )
answer = gsub( answer, "(%[VIC%])", victim )
SendToAll( answer.."|" )
end
end
end
--//End Of Stab function
end
end

Ripped from funscript.txt...
Code: [Select]
--// 3 values can be plugged into the answer as many time..[CURUSER] = invoking user, [VIC] = target
Stabs = {
"*** [CURUSER] gets behind the wheel of a Volvo and back up over [VIC]'s dog. ***" ,
"*** [CURUSER] beats the shit out of [VIC]!*** " ,
}--//this is the end of the answers...
« Last Edit: 30 September, 2004, 20:44:32 by madman »
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
(No subject)
« Reply #6 on: 01 October, 2004, 21:12:43 »
Does any one have a soulation to my problem? :/
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #7 on: 01 October, 2004, 22:27:23 »
Hi,

You have 2 DataArrival, you can't have 2, you have to join both DataArrival in one.

Best regards, nErBoS
--## nErBoS Spot ##--

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
(No subject)
« Reply #8 on: 01 October, 2004, 22:42:23 »
Okey... but i dont know how to do that....
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
(No subject)
« Reply #9 on: 01 October, 2004, 23:53:58 »
unfortnaly neither do i... my pc got f*cked up and refuses to install Xp... have to wait untill my freind come ger tomorrow and help me....Lucky i got more then one pc.. so i can surf and chat on dc =)


*edit*

I dont have ptokax now.. but just create a txt called funscript and insert to it...

--// 3 values can be plugged into the answer as many time..[CURUSER] = invoking user, [VIC] = target
Stabs = {
"*** [CURUSER] gets behind the wheel of a Volvo and back up over [VIC]'s dog. ***" ,
"*** [CURUSER] beats the shit out of [VIC]!*** " ,
}--//this is the end of the answers...

thats all it is in it.. just more stab text...
« Last Edit: 02 October, 2004, 00:05:26 by madman »
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
(No subject)
« Reply #10 on: 02 October, 2004, 19:52:13 »
Okey.. Got my pc working...kind of...
anyway... That did not help mutor..
The problem semmes to be without that 2nd Data arival it cant find the victim
Becuse
Code: [Select]
answer = gsub( answer, "(%[VIC%])", victim )
dont work, but
Code: [Select]
answer = gsub( answer, "(%[VIC%])", User )--victim )
this does
but then i stab my self..so my guess is that we need something to tell the script who the victim is without using the DataArival...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #11 on: 02 October, 2004, 22:27:12 »
Hi,

Let's us take by parts...

1) With User you will get stab your self because of this...

Code: [Select]
local User = curUser.sName
2) So it leaves us it the var victim that is catch in here...

Code: [Select]
local _,_,junk=strfind(data, "%b<>%s+%S+%s+(.+)|")
and used here...

Code: [Select]
local answer,victim = Stabs[random(getn(Stabs))], junk
Now i belive that isn't working because of the catch, you can catch a phrase and not a nick so i would recomend you to use this...

Code: [Select]
local _,_,junk=strfind(data, "%b<>%s+%S+%s+(%S+)")
instead of this...

Code: [Select]
local _,_,junk=strfind(data, "%b<>%s+%S+%s+(.+)|")
For futher understanding of my change check out in the LUA Manual or plop's magical char how to topic, to see how magical chars work.

Best regards, nErBoS
--## nErBoS Spot ##--

Offline Madman

  • Scripter
  • Emperor
  • ******
  • Posts: 1 316
  • Karma: +75/-1
(No subject)
« Reply #12 on: 03 October, 2004, 08:08:35 »
Quote
Originally posted by nErBoS
For futher understanding of my change check out in the LUA Manual or plop's magical char how to topic, to see how magical chars work.

Thanks, That solved the problem...

And plop's magical char how to.... i cant find it... could u give me a link?
« Last Edit: 03 October, 2004, 08:08:56 by madman »
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #13 on: 03 October, 2004, 12:55:36 »
Hi,

Check it HERE

Best regards, nErBoS
--## nErBoS Spot ##--

PtokaX forum

(No subject)
« Reply #13 on: 03 October, 2004, 12:55:36 »