PtokaX forum

Archive => Archived 4.0 boards => Finished Lua 4 scripts => Topic started by: d-deeds on 18 November, 2005, 15:49:52

Title: Ptokax text commands?
Post by: d-deeds on 18 November, 2005, 15:49:52
Hi,

My hub has been runned by ynhub earlier and i figure out that ptokax woudn't been bad.. :)

Now here's my problem. With Ynhub i could create a text commands that:
- Only shows in main and is broadcasted to everyone..
ex: If someone want's to tell the entire hub in main that his go to bed i had a ASCII picture for that...

Is that possible in ptokax?

Please help me

Deeds
Title:
Post by: bastya_elvtars on 18 November, 2005, 15:55:11
So basically it displays a text file. I. e. +bed show an ASCII art and shows: "Joe is going to bed.", where joe is the actual user's name. Or not?
Title:
Post by: UwV on 18 November, 2005, 15:55:54
a three step plan..

1. enable textfiles support ..
2. put a file named "bedtime.txt" in ptokaxfolder/txt and paste your ascii of the bed in there.
3. use command !bedtime
Title:
Post by: d-deeds on 18 November, 2005, 16:18:45
-----------------------------------
a three step plan..

1. enable textfiles support ..
2. put a file named "bedtime.txt" in ptokaxfolder/txt and paste your ascii of the bed in there.
3. use command !bedtime

-----------------------------------

Well UwV...
It's not that simple,,,, yes now i got the text command.
But it's sent in pm and only to "the one that writing"!

I would like to have it in MAIN and sent to everyone...
Title:
Post by: Dessamator on 18 November, 2005, 17:42:48
There are quite a lot of scripts that do that, just Search the forum
Title:
Post by: d-deeds on 18 November, 2005, 17:54:43
Do you got any good examples that works?
Title:
Post by: ??????Hawk?????? on 18 November, 2005, 18:35:40
QuoteOriginally posted by d-deeds
Do you got any good examples that works?

Yes  we got loads of good Examples ...  


You could too IF only you used the forums Search..
Title:
Post by: d-deeds on 18 November, 2005, 19:41:30
i didn't find very much...
but i find "hawk"s  script with ascii,,, this is probably not what i search for? or isit?

/deeds


-- Yet another version AsciiTexter Bot
--  By ??????Hawk?????? 03/07/2005
-- Create an   ascii folder within the scripts folder and copy all your ascii files in.

AsciiBotName =  botname   --// Set Bot name here

SendTo = { --> 1=on/0=off
Title:
Post by: ??????Hawk?????? on 18 November, 2005, 19:45:57
for your needs you are "probably " best following UwV's suggestion..


QuoteOriginally posted by UwV
a three step plan..

1. enable textfiles support ..
2. put a file named "bedtime.txt" in ptokaxfolder/txt and paste your ascii of the bed in there.
3. use command !bedtime


??????Hawk??????
Title:
Post by: d-deeds on 18 November, 2005, 19:49:46
yes but then it's not useful..

the idea is that a person can tell the entire hub something in main with a command...

Uwv's sugestion is very good, but it's sent to the one that writing and in pm... :)

/deeds
Title:
Post by: ??????Hawk?????? on 18 November, 2005, 19:58:25
ahhh  ic  ..  

the script you posted should work for you  ..

create a folder in your scripts folder called  '   ascii  '
and put all your ascii text files in it  ...


??????Hawk??????
Title:
Post by: d-deeds on 18 November, 2005, 20:08:27
well... it works...

but i can't get any message in main,,, well,,, nothing happends at all... i can't even see the command i've typed in main +bed
Title:
Post by: ??????Hawk?????? on 18 November, 2005, 20:30:33
QuoteOriginally posted by d-deeds
well... it works...

but i can't get any message in main,,, well,,, nothing happends at all... i can't even see the command i've typed in main +bed

does the file   bed.txt  exist in the ascii folder  ... ?

AND  did you restart scripts when you put the text file in  ..  ?


??????Hawk??????
Title:
Post by: d-deeds on 19 November, 2005, 01:19:38
yes and yes...
Title:
Post by: GeceBekcisi on 19 November, 2005, 03:49:09
This sample code can show you where to start, because LUA is really very easy and is fun to work with.-- Reads 'sFile' and sends it to main when command
-- '!bed', '+bed', '?bed', '#bed' is sent to main chat
-- by GeceBekcisi

sBotName = frmHub:GetHubBotName()
sFile = "ascii/bed.txt"

function ChatArrival(curUser, data)
local data = string.sub(data,1, -2)
local s,e,cmd = string.find(data, "%b<>%s[%!%+%?%#%+](%S+)")
if cmd == "bed" then
local filedata ="\r\n\r\n"
for line in io.lines(sFile) do
filedata = filedata..line.."\r\n"
end
SendToAll(sBotName, filedata..curUser.sName.." goes to bed and says: Good night all!\r\n")
return 1
end
end
Play with code, and please feel free to ask about anything. Best regards
Title:
Post by: d-deeds on 19 November, 2005, 04:31:35
THANKS GECEBEKCISI!!!!

That did work just perfect...

Just one tiny little thing...
how do i change in the script so the text "nick goes to bed and says: Good night all! " comes before the ascii? :)


Thank you again VERY MUCH!!
/deeds
Title:
Post by: GeceBekcisi on 19 November, 2005, 06:13:48
You're welcome mate and here it goes: Just change local filedata ="\r\n\r\n"
for line in io.lines(sFile) do
filedata = filedata..line.."\r\n"
end
SendToAll(sBotName, filedata[COLOR=red]..curUser.sName.." goes to bed and says: Good night all!\r\n"[/COLOR])
to local filedata ="\r\n\r\n"[COLOR=red]..curUser.sName.." goes to bed and says: Good night all!\r\n"[/COLOR]
for line in io.lines(sFile) do
filedata = filedata..line.."\r\n"
end
SendToAll(sBotName, filedata)
I hope you see how easy it is in fact ;)
Best Regards
Title:
Post by: d-deeds on 19 November, 2005, 15:52:11
So if i would use two of them they would look like this:
(but if i use that one, only "+rock" works???)

------------------------------

-- Reads 'sFile' and sends it to main when command
-- '!bed', '+bed', '?bed', '#bed' is sent to main chat
-- by GeceBekcisi

sBotName = frmHub:GetHubBotName()
sFile = "ascii/nn.txt"

function ChatArrival(curUser, data)
   local data = string.sub(data,1, -2)
   local s,e,cmd = string.find(data, "%b<>%s[%!%+%?%#%+](%S+)")
   if cmd == "nn" then
      local filedata ="\r\n\r\n"..curUser.sName.."  Goes to bed, and wish you all.. \r\n"
      for line in io.lines(sFile) do
         filedata = filedata..line.."\r\n"
      end
      SendToAll(sBotName, filedata)
      return 1
   end

end

sBotName = frmHub:GetHubBotName()
sFile = "ascii/rock.txt"

function ChatArrival(curUser, data)
   local data = string.sub(data,1, -2)
   local s,e,cmd = string.find(data, "%b<>%s[%!%+%?%#%+](%S+)")
   if cmd == "rock" then
      local filedata ="\r\n\r\n"..curUser.sName.."  headbangs and hope that the rest of the hub are with him? \r\n"
      for line in io.lines(sFile) do
         filedata = filedata..line.."\r\n"
      end
      SendToAll(sBotName, filedata)
      return 1
   end

end
Title:
Post by: GeceBekcisi on 19 November, 2005, 21:34:00
Hmm first of all, you need to understand you can define unique functions and you must define unique strings only once in a script (unless you need to define a string again), with only one equation mark..

If I typesString = "StringValue1"sString will be equal to "StringValue1" whenever I call it in my script. But if I typesString = "StringValue1"
...
sString = "StringValue2"
sString will be equal to "StringValue2" whenever I call it in my script. And also if I typesString = "StringValue1"
...
sString = "StringValue1"
sString will be equal to "StringValue1" whenever I call it in my script. So there is no need to write it again.


And also, in a script two functions of same name will confuse PtokaX, so here you go:-- Reads files and sends it to main when command typed to main chat
-- by GeceBekcisi

sBotName = frmHub:GetHubBotName()
sBedFile = "ascii/nn.txt"
sRockFile = "ascii/rock.txt"

function ChatArrival(curUser, data)
local data = string.sub(data,1, -2)
local s,e,cmd = string.find(data, "%b<>%s[%!%+%?%#%+](%S+)" )
if cmd == "bed" then
local filedata = "\r\n\r\n"..curUser.sName.." goes to bed and says: Good night all!\r\n"
for line in io.lines(sBedFile) do
filedata = filedata..line.."\r\n"
end
SendToAll(sBotName, filedata)
return 1
end
if cmd == "rock" then
local filedata = "\r\n\r\n"..curUser.sName.." headbangs and hope that the rest of the hub are with him? \r\n"
for line in io.lines(sRockFile) do
filedata = filedata..line.."\r\n"
end
SendToAll(sBotName, filedata)
return 1
end
end

And please use [C0DE] and [/C0DE] (and don't forget to replace C0DE with CODE when posting ;)) to wrap script codes when posting.
Best regards.