Forum

> > CS2D > Scripts > How to make some command
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch How to make some command

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Re: How to make some command

Rainoth
Moderator Off Offline

Zitieren
1
2
3
4
5
6
addhook("say","say_cmd")
function say_cmd(id,t)
	if t:sub(1,4) == "!cmd" then
		msg2(id,"You called a command")
	end
end

Not necessarily for say hook, can be in console too. That's a simple way when you don't want to make complicated commands and just a few of them.

alt Re: How to make some command

GeoB99
Moderator Off Offline

Zitieren
Tip: Never use string.sub() in case if you implement many commands for your script. It makes things slower in terms of time. Pattern matching is way more powerful and it's not required to put patterns on every side of a command.

Unless if you just implement few things such as 3 commands, you're freely to use string.sub(). Here you can find further information and instructions about it below:

> thread cs2d [Tip] Stop using string.sub() for commands

alt Re: How to make some command

Dousea
User Off Offline

Zitieren
I agree with user GeoB99. This is the wrap of everything user VaiN said.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
local function split(s, d)
	local w = {}
	
	s:gsub(("[^%s]+"):format(d or " "), function(v)
		w[#w + 1] = v
	end)
	
	return w
end

function sayhook(i, t)
	local c = t:match("^([!|@][%w]+)[%s]?")
	local d = t:match("[%s](.*)")
	
	if (c and d) then
		-- This is the place where you add commands
		if (c == "kill") then
			-- This is not error-safe due to no checkup for the arguments' type (d)
			parse(("killplayer %d"):format(tonumber((split(d))[1]))")
		end
	end
end

addhook("say", "sayhook")
1× editiert, zuletzt 03.04.16 12:50:02
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht