Forum

> > CS2D > Scripts > Parsing player message
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Parsing player message

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Parsing player message

Kisses
User Off Offline

Zitieren
I was thinking what is easiest and the most efficient way to parse player messages. Lua's patterns are pretty limited and they don't support OR-statements like regexp does. So I came up with doing it hard way.

This is how far I got:

> input
1
!kick hacker "reason: calling me \"noob\""
> output
1
2
3
4
5
{
	[1] = !kick
	[2] = hacker
	[3] = reason: calling me "noob"
}

source code >

If you have any ideas how I could improve this, please share them!
4× editiert, zuletzt 11.06.12 19:34:51

alt Re: Parsing player message

Apache uwu
User Off Offline

Zitieren
I believe kick even works with the player's name instead of the id.

Try

1
2
3
4
5
kiss.say = function(id, message)
	local cmd = kiss.parseCommand(message)
	parse("kick "..cmd[2])
	msg(string.char(169).."255255255"..player(id,"name").." has kicked "..cmd[2])
end

However you should add additional checks such as the player's existance as well as if the target is another administrator or not.

alt Re: Parsing player message

Kisses
User Off Offline

Zitieren
I'm not trying to create admin mod. Kicking somebody was only an example of how the script parses strings.

alt Re: Parsing player message

Apache uwu
User Off Offline

Zitieren
Does this work for a message like...

!kick_____________________hacker_______________________________calling me noob

_ = space

alt Re: Parsing player message

Kisses
User Off Offline

Zitieren
user Apache uwu hat geschrieben
Does this work for a message like...

!kick_____________________hacker_______________________________calling me noob

_ = space


Thank you for pointing that out. It's now fixed

alt Re: Parsing player message

omg
User Off Offline

Zitieren
this is copy and pasted, but its a good piece of code for strings
1
2
3
4
5
6
7
8
function totable(t,match)
	local cmd = {}
	if not match then match = "[^%s]+" end
	for word in string.gmatch(t, match) do
		table.insert(cmd, word)
	end 
	return cmd 
end
it chunks up each word (no spaces) in the string into the table in order. used like this:
1
2
totable(string)--returns table of strings
totable(string)[1]--first word of string, provided it exists
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht