PtokaX forum

Development Section => Your Developing Problems => Topic started by: Madman on 28 September, 2004, 22:51:21

Title: display txt from file
Post by: Madman 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 ")
Title: ...
Post by: EXNET OWNER 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
Title:
Post by: BottledHate on 29 September, 2004, 03:13:27
QuoteOriginally 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 (http://www.bottledhate.webhop.org) (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
Title:
Post by: Madman 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
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
--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)
Title:
Post by: BottledHate on 30 September, 2004, 02:52:05
the prob is in here:

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
Title:
Post by: Madman 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


--//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...
--// 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...
Title:
Post by: Madman on 01 October, 2004, 21:12:43
Does any one have a soulation to my problem? :/
Title:
Post by: nErBoS 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
Title:
Post by: Madman on 01 October, 2004, 22:42:23
Okey... but i dont know how to do that....
Title:
Post by: Madman 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...
Title:
Post by: Madman 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
answer = gsub( answer, "(%[VIC%])", victim )
dont work, but
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...
Title:
Post by: nErBoS 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...

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

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

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

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

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
Title:
Post by: Madman on 03 October, 2004, 08:08:35
QuoteOriginally 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?
Title:
Post by: nErBoS on 03 October, 2004, 12:55:36
Hi,

Check it HERE (http://board.univ-angers.fr/thread.php?threadid=763&boardid=4&sid=40bcb5eda22a6fa8ba23be08f75181da)

Best regards, nErBoS