help
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

help

Started by Yahoo, 10 April, 2007, 15:37:24

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Yahoo

what do this mean??
local s,e,msg = string.find(data, "%b<>%s+%S+%s(.*)")
"BoRN FIGhTEr"

Thor

The second and the other words in a chat message.
%b<> - This will search for the next following two signs (in chat messages the nick is like <Hungarista>)
%s+ - one, or more whitespace character (so at least one)
%S+ - one, or more non-space character
%s - just one whitespace
(.*) - . means this character can be everything, so whitespace, number, letter, ASCII char, everything. * indicates that it will be there or not, so 0 or more. The braces put the found value(s) into the variable called 'msg'. The first two return value of string.find is two number, the first and the last index of the string where the match found.
For more details check the lua.org page, it's pure lua.

achiever

s,e,cmd = string.find(data,"%b<>%s+(%S+)|")
	if (cmd=="+help") then

now i need to work this command with all prefix so what do i need to add. i mean how can 1 detect prefix alone other than the word followed.
thks,
achiever.

bastya_elvtars

Everything could have been anything else and it would have just as much meaning.

achiever

#4
thanks for that bastya :P but i was not able to comprehend much from that sorry for my unintelligence.
so is some 1 willing to answer what i had asked more clearly.
thks,
achiever.

bastya_elvtars

Decided to give you hints. You need to grab ANY punctuation character that is right in the beginning of the text from the user, or you may want to specify the set of characters wanted directly.
Everything could have been anything else and it would have just as much meaning.

Yahoo

thanks you all for all ur help
"BoRN FIGhTEr"

Cêñoßy†ê

#7
meaned like this ?
Code: lua
local _,_,prefix,cmd = data:find("%b<>%s+(%p)(%S+)")
if cmd == "help" then


it reacts to !help  +help  /help etc..
Powered By Leviathan™ 2nd Generation v. 1.9

bastya_elvtars

Now this is what I wanted him to find out by himself.
Everything could have been anything else and it would have just as much meaning.

Cêñoßy†ê

Quote from: bastya_elvtars on 10 April, 2007, 20:59:31
Now this is what I wanted him to find out by himself.

sry :P
Powered By Leviathan™ 2nd Generation v. 1.9

achiever

thks for help cenobyte but i m not sure this line is working as it should
here is the code i had
function ChatArrival( user , data )
	s,e,cmd = string.find(data,"%b<>%s+(%S+)|")
	if cmd == "+show" then
		--SendToAll(user.sName, prefix)
		SendToAll("<Fusion>Type prefix-show to show this line")
		return 1
	end
end


this is what it looked like after change
function ChatArrival( user , data )
	local _,_,prefix,cmd = data:find("%b<>%s+(%p)(%S+)")
	if cmd == "show" then
		--SendToAll(user.sName, prefix)
		SendToAll("<Fusion>Type prefix-show to show this line")
		return 1
	end
end


but it stops to work entirely after the change.

bastya a bit of help at the start of learning, does help to learn faster.

thks,
achiever.
thks,
achiever.

speedX

function ChatArrival( user , data )
	local _,_,prefix,cmd = data:find("%b<>%s+(%p)(%S+)|")
	if cmd == "show" then
		--SendToAll(user.sName, prefix)
		SendToAll("<Fusion>Type prefix-show to show this line")
		return 1
	end
end
Thanking You,

speedX

bastya_elvtars

Quote from: achiever on 11 April, 2007, 17:38:14
but it stops to work entirely after the change.

bastya a bit of help at the start of learning, does help to learn faster.

I think giving hints makes learning even faster. Anyway, in the second chunk there is a | missing.
Everything could have been anything else and it would have just as much meaning.

achiever

well i think it depends on person to person how they learn things.
thks for ur hint, understood it this time.
achiever.
thks,
achiever.

bastya_elvtars

Quote from: achiever on 11 April, 2007, 18:09:12
well i think it depends on person to person how they learn things.
thks for ur hint, understood it this time.

Sure, and pattern matching is not the most straightforward aspect of Lua.
You're welcome. :-)
Everything could have been anything else and it would have just as much meaning.

achiever

now moving on...

sBot = "Bot name"
function ChatArrival( user , data )
	local _,_,prefix,cmd = data:find("%b<>%s+(%p)(%S+)|")
	if prefix == "+" then
		SendToAll(user.sName, cmd)
		SendToAll(sBot, "Type prefix-help for list of commands available to ur profile")
		return 1
	end
end


this works when there is a command with '+' as prefix with an unkown command (if script is placed last of all scripts) and gives the output, but how can add it to work with all perfixes
and also it returns only the command and not the prefix used, so what should it be?
SendToAll(user.sName, prefix,cmd)
this did not work.
thks,
achiever.

speedX

What is the difference between
local s,e,prefix,cmd and local _,_,prefix,cmd  ??
Thanking You,

speedX

bastya_elvtars

Quote from: achiever on 11 April, 2007, 18:38:48
now moving on...
this works when there is a command with '+' as prefix with an unkown command (if script is placed last of all scripts) and gives the output, but how can add it to work with all perfixes
and also it returns only the command and not the prefix used, so what should it be?
SendToAll(user.sName, prefix,cmd)
this did not work.

It ONLY works with the + prefix. Remove that restriction from the code.
SendToAll(user.sName, prefix,cmd) - this won't work as SendToAll() accepts only 1 or 2 arguments. With 1, it sends the argument out as rew data, with 2 arguments, the first one is the nick sending the stuff, the second is the stuff itself (sending it as <nick> stuff|)
Quote from: speedX on 11 April, 2007, 18:54:17
What is the difference between
local s,e,prefix,cmd and local _,_,prefix,cmd  ??

Nothing, it does the same. Underscores are variable placeholders, s and e are true variables but very few use that two when capturing a pattern. This needs further explanation:
A function returns 4 values but you only want the last 2. If you simply do a,b=dothis() then you get the first 2 values. So if you do _,_,a,b=dothis() then you declare that you only want the last 2 values.
Usage example: dothat() returns 5 values.
Getting the first one: x=dothat()
Getting the first and secod one: x,y=dothat()
Getting the second, third and fifth: x,_,y,_,z=dothat()
Getting the second, third and fourth: _,x,y,z=dothat()
Getting all but the fourth: x,y,z,_,w=dothat()
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

Oh, and in Lua 5.1 you can also use string.gmatch, when the start and end positions aren't returned at all. :-)
Everything could have been anything else and it would have just as much meaning.

achiever

Quote from: Mutor on 11 April, 2007, 18:49:23
local sBot = "BotName"
function ChatArrival( user , data )
	local s,e,prefix,cmd = data:find("%b<>%s+(%p)(%S+)|")
	if prefix and cmd then
		SendToAll(user.sName, prefix..cmd)
		SendToAll(sBot, "Type prefix-help for list of commands available to ur profile")
		return 1
	end
end


this code is stoping me to use basic pxcommands, ne way arround???
thks,
achiever.

Naithif

#20
Quote from: achiever on 12 April, 2007, 18:26:10
this code is stoping me to use basic pxcommands, ne way arround???


You should have another condition requiring your command to be something specific, in the above case it reacts to every punct. char + word combination.

(just a hint ;))

achiever

so should there be a list of commads which this should ignore?
thks,
achiever.

Naithif

Quote from: achiever on 12 April, 2007, 18:42:17
so should there be a list of commads which this should ignore?

If you want it to react to every unrecognized command, then well, yes.

bastya_elvtars

Or do not return 1 (but then the command will show up).
Everything could have been anything else and it would have just as much meaning.

Naithif

Quote from: bastya_elvtars on 12 April, 2007, 18:48:53
Or do not return 1 (but then the command will show up).

Yes, every time, even when a command was specified in a good way :D
And since it's SendToAll it would result in some spam on an actively used hub :)

Anyway why don't you send it to just the user who entered the command?

SMF spam blocked by CleanTalk