Forum

> > CS2D > Scripts > Lua mapchange ?
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Lua mapchange ?

20 Antworten
Seite
Zum Anfang Vorherige 1 2 Nächste Zum Anfang

alt Lua mapchange ?

kch
User Off Offline

Zitieren
I need help guys,
im learning lua scripting and i have some problems, everything is working but on my eyes map change takes a lot of time for me.

this is my lua code :
1
2
3
4
5
6
7
8
9
10
addhook("say","map")
function makespec(id,env)
for _, usgn in ipairs(admlist) do
if player(id,'usgn') == usgn then
if (env=="!map de_dust") then
parse("sv_map de_dust")
end
end
end
end

always if i want to change the map, i need to add this one :

1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("say","map")
function makespec(id,env)
for _, usgn in ipairs(admlist) do
if player(id,'usgn') == usgn then
if (env=="!map de_dust") then
parse("sv_map de_dust")
end
if (env=="!map de_dust2") then
parse("sv_map de_dust2")
end
end
end
end

alt Re: Lua mapchange ?

ohaz
User Off Offline

Zitieren
1
2
3
if (string.gmatch(env, "%S+") == "!map")
	parse("sv_map "..string.gmatch(env, "%S+"))
end

alt Re: Lua mapchange ?

kch
User Off Offline

Zitieren
where i need to add this :

1
2
3
if (string.gmatch(env, "%S+") == "!map")
     parse("sv_map "..string.gmatch(env, "%S+"))
end

please help :3
1× editiert, zuletzt 21.05.13 21:49:43

alt Re: Lua mapchange ?

limonata
User Off Offline

Zitieren
1
2
addhook("say","map")
function makespec
-- Dude, it should be map. like this

1
2
3
addhook("say","map")
function map(id,txt)
...
...

alt Re: Lua mapchange ?

kch
User Off Offline

Zitieren
All the time it says that i made something wrong :

1
2
3
4
5
6
7
8
9
10
addhook("say","map")
function map(id,txt)
for _, usgn in ipairs(admlist) do
if player(id,'usgn') == usgn then
if (string.gmatch(env, "%S+") == "!map")
     parse("sv_map "..string.gmatch(env, "%S+")
	 end
	 end
	 end
	 end

in console it says that this code is wrong :
1
parse("sv_map "..string.gmatch(env, "%S+")

alt Re: Lua mapchange ?

Avo
User Off Offline

Zitieren
You changed "env" to "txt".


1
parse("sv_map "..string.gmatch(env, "%S+")

-->


1
parse("sv_map "..string.gmatch(txt, "%S+")

and anywhere where there're "env"s in that function.

alt Re: Lua mapchange ?

sheeL
User Spielt CS2D

Zitieren
user limonata hat geschrieben
1
2
addhook("say","map")
function makespec
-- Dude, it should be map. like this

1
2
3
addhook("say","map")
function map(id,txt)
...
...


You are stupid?...

@edit²

Like this?
1
2
3
4
5
6
7
8
9
10
11
addhook("say","OnMapChange")
function OnMapChange(id,text)
	for _, usgn in ipairs(admlist) do
		if player(id,'usgn') == usgn then
			if (string.gmatch(text, "%S+") == "!map")
     			parse("sv_map "..string.gmatch(text, "%S+"))
			return 1
			end
		end
	end
end

not tested

alt Re: Lua mapchange ?

kch
User Off Offline

Zitieren
all the time in the consol :
it says Error at the line 137.

Here is the line 137 :
1
parse("sv_map "..string.gmatch(text, "%S+")

alt Re: Lua mapchange ?

Avo
User Off Offline

Zitieren
You would say at least, what error message you're having in the console, you know.

alt Re: Lua mapchange ?

kch
User Off Offline

Zitieren
LUA ERROR: sys/lua/autorun/Server.lua:137: 'then' expected near 'parse'

alt Re: Lua mapchange ?

Kebabgamer
User Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
Admin = {usgn in here}

addhook("say","OnMapChange")
function OnMapChange(id,text)
for _, usgn in ipairs(Admin) do
if player(id,'usgn') == usgn then
               if (string.gmatch(text, "%S+") == "!map")
               then parse ("sv_map "..string.gmatch(text, "%S+"))
               return 1
               end
          end
     end
end

this should work

alt Re: Lua mapchange ?

kch
User Off Offline

Zitieren
yea it works but if i write !map de_dust it does not change the map.

alt Re: Lua mapchange ?

sheeL
User Spielt CS2D

Zitieren
Fixed. Works now !

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Admin = {your usgn here,xxxxx,xxxxx}

addhook("say","OnSayP")
function OnSayP(id,text)
	for _, usgn in ipairs(Admin) do
		if player(id,'usgn') == usgn then
			if string.sub(text, 1, 4) == "!map" then
				local txt=text:sub(5)
				parse("sv_map "..txt);
			return 1
			end
		end
	end
end

alt Re: Lua mapchange ?

kch
User Off Offline

Zitieren
Thanks sheel it works !!
which program you are using to create a lua.

alt Re: Lua mapchange ?

EP
User Off Offline

Zitieren
@user kch: He has code it for his own. Because he knows programming (we say scripting because CS2D runs scripts that we code, so basically you're just scripting for CS2D, not programming). At first, you should know what's an algorythm, search for it if you don't know.

After learning the basics of programming, you should know that CS2D runs Lua scripts (Lua is a programming language with primitive variables and blablabla).

There are many manuals about Lua, you can find these on this site or by googling them.

I recommend you to make your CS2D scripts on Notepad++, it has an option to highlight programming languages keywords, operations, etc, and that helps you very much with coding scripts for CS2D.

alt Re: Lua mapchange ?

limonata
User Off Offline

Zitieren
user sheeL hat geschrieben
user limonata hat geschrieben
1
2
addhook("say","map")
function makespec
-- Dude, it should be map. like this

1
2
3
addhook("say","map")
function map(id,txt)
...
...


You are stupid?...


No, But i'm suspecting you about this. I told him the correct thing.

1
2
3
4
5
6
addhook("say","map")
function makespec(id,txt) -- should be map
if txt == "hi" then
msg("hi")
end
end
This is wrong code. Like him script. Read carefully before your post!

alt Re: Lua mapchange ?

sheeL
User Spielt CS2D

Zitieren
user limonata hat geschrieben
user sheeL hat geschrieben
user limonata hat geschrieben
1
2
addhook("say","map")
function makespec
-- Dude, it should be map. like this

1
2
3
addhook("say","map")
function map(id,txt)
...
...


You are stupid?...


No, But i'm suspecting you about this. I told him the correct thing.

1
2
3
4
5
6
addhook("say","map")
function makespec(id,txt) -- should be map
if txt == "hi" then
msg("hi")
end
end
This is wrong code. Like him script. Read carefully before your post!


what?, what does this have to do with the topic?, go learn lua ,fuck

alt Re: Lua mapchange ?

lucaSWAT
User Off Offline

Zitieren
user sheeL hat geschrieben
Fixed. Works now !

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Admin = {your usgn here,xxxxx,xxxxx}

addhook("say","OnSayP")
function OnSayP(id,text)
	for _, usgn in ipairs(Admin) do
		if player(id,'usgn') == usgn then
			if string.sub(text, 1, 4) == "!map" then
				local txt=text:sub(5)
				parse("sv_map "..txt);
			return 1
			end
		end
	end
end


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function totable(t,match)
     local cmd = {}
     if not match then
          match = "[^%s]+"
     else
          match = "[^"..match.."]+"
     end
     for word in string.gmatch(t,match) do
          table.insert(cmd,word)
     end
     return cmd
end

addhook("say","map_test")
function map_test(id,txt)
local p = totable(txt)
local cmd = tostring(p[1])
local name = tostring(p[2])
local dela = tonumber(p[3])
if cmd:lower() == "@map" then
msg("©123456789 "..player(id,"name").." use ©255170000"..cmd.." , ©000255000Change Map in : "..dela.." secs , MapName : "..name)
timer(""..dela.."000","parse","map "..name)
return 1
end
end
Zum Anfang Vorherige 1 2 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht