Author Topic: help  (Read 10499 times)

0 Members and 1 Guest are viewing this topic.

Offline Yahoo

  • Triple Ace
  • **
  • Posts: 225
  • Karma: +32/-14
  • People Say "I Dont Know English"
    • Yahoo
help
« on: 10 April, 2007, 15:37:24 »
what do this mean??
local s,e,msg = string.find(data, "%b<>%s+%S+%s(.*)")
"BoRN FIGhTEr"

PtokaX forum

help
« on: 10 April, 2007, 15:37:24 »

Offline Thor

  • Scripter
  • Lord
  • ******
  • Posts: 290
  • Karma: +45/-5
    • Hungarian Direct Connect Site
Re: help
« Reply #1 on: 10 April, 2007, 16:04:08 »
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.

Offline achiever

  • Lord
  • ***
  • Posts: 260
  • Karma: +25/-22
Re: help
« Reply #2 on: 10 April, 2007, 18:11:42 »
Code: [Select]
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.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: help
« Reply #3 on: 10 April, 2007, 18:24:34 »
Everything could have been anything else and it would have just as much meaning.

Offline achiever

  • Lord
  • ***
  • Posts: 260
  • Karma: +25/-22
Re: help
« Reply #4 on: 10 April, 2007, 18:55:06 »
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.
« Last Edit: 10 April, 2007, 18:56:38 by achiever »
thks,
achiever.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: help
« Reply #5 on: 10 April, 2007, 20:33:58 »
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.

Offline Yahoo

  • Triple Ace
  • **
  • Posts: 225
  • Karma: +32/-14
  • People Say "I Dont Know English"
    • Yahoo
Re: help
« Reply #6 on: 10 April, 2007, 20:54:07 »
thanks you all for all ur help
"BoRN FIGhTEr"

Offline Cêñoßy†ê

  • Scripter
  • Triple Ace
  • ******
  • Posts: 190
  • Karma: +31/-3
Re: help
« Reply #7 on: 10 April, 2007, 20:58:30 »
meaned like this ?
Code: Lua
  1. local _,_,prefix,cmd = data:find("%b<>%s+(%p)(%S+)")
  2. if cmd == "help" then
  3.  

it reacts to !help  +help  /help etc..
« Last Edit: 10 April, 2007, 21:12:07 by C??o?y? »
***********************
Powered By Leviathan v5.2 ;)

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: help
« Reply #8 on: 10 April, 2007, 20:59:31 »
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.

Offline Cêñoßy†ê

  • Scripter
  • Triple Ace
  • ******
  • Posts: 190
  • Karma: +31/-3
Re: help
« Reply #9 on: 10 April, 2007, 21:02:22 »
Now this is what I wanted him to find out by himself.

sry :P
***********************
Powered By Leviathan v5.2 ;)

Offline achiever

  • Lord
  • ***
  • Posts: 260
  • Karma: +25/-22
Re: help
« Reply #10 on: 11 April, 2007, 17:38:14 »
thks for help cenobyte but i m not sure this line is working as it should
here is the code i had
Code: [Select]
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
Code: [Select]
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.

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: help
« Reply #11 on: 11 April, 2007, 17:48:17 »
Code: [Select]
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

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: help
« Reply #12 on: 11 April, 2007, 17:49:58 »
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.

Offline achiever

  • Lord
  • ***
  • Posts: 260
  • Karma: +25/-22
Re: help
« Reply #13 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.
achiever.
thks,
achiever.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: help
« Reply #14 on: 11 April, 2007, 18:12:16 »
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.

Offline achiever

  • Lord
  • ***
  • Posts: 260
  • Karma: +25/-22
Re: help
« Reply #15 on: 11 April, 2007, 18:38:48 »
now moving on...

Code: [Select]
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.

Offline speedX

  • Lord
  • ***
  • Posts: 437
  • Karma: +59/-19
Re: help
« Reply #16 on: 11 April, 2007, 18:54:17 »
What is the difference between
local s,e,prefix,cmd and local _,_,prefix,cmd  ??
Thanking You,

speedX

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: help
« Reply #17 on: 11 April, 2007, 19:00:04 »
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|)
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.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: help
« Reply #18 on: 11 April, 2007, 23:50:22 »
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.

Offline achiever

  • Lord
  • ***
  • Posts: 260
  • Karma: +25/-22
Re: help
« Reply #19 on: 12 April, 2007, 18:26:10 »
Code: [Select]
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.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: help
« Reply #20 on: 12 April, 2007, 18:29:56 »
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 ;))
« Last Edit: 12 April, 2007, 18:33:28 by Naithif »

Offline achiever

  • Lord
  • ***
  • Posts: 260
  • Karma: +25/-22
Re: help
« Reply #21 on: 12 April, 2007, 18:42:17 »
so should there be a list of commads which this should ignore?
thks,
achiever.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: help
« Reply #22 on: 12 April, 2007, 18:45:43 »
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.

Offline bastya_elvtars

  • Forum God
  • ****
  • Posts: 3 730
  • Karma: +173/-7
  • The rock n' roll doctor
    • The FreshStuff3 Site
Re: help
« Reply #23 on: 12 April, 2007, 18:48:53 »
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.

Offline Naithif

  • Triple Ace
  • **
  • Posts: 199
  • Karma: +32/-13
Re: help
« Reply #24 on: 12 April, 2007, 18:52:52 »
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?

PtokaX forum

Re: help
« Reply #24 on: 12 April, 2007, 18:52:52 »