Forum

> > CS2D > Scripts > Lua mapchange ?
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua mapchange ?

20 replies
Page
To the start Previous 1 2 Next To the start

old Lua mapchange ?

kch
User Off Offline

Quote
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

old Re: Lua mapchange ?

ohaz
User Off Offline

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

old Re: Lua mapchange ?

kch
User Off Offline

Quote
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
edited 1×, last 21.05.13 09:49:43 pm

old Re: Lua mapchange ?

limonata
User Off Offline

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

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

old Re: Lua mapchange ?

kch
User Off Offline

Quote
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+")

old Re: Lua mapchange ?

Avo
User Off Offline

Quote
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.

old Re: Lua mapchange ?

sheeL
User Off Offline

Quote
user limonata has written
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

old Re: Lua mapchange ?

kch
User Off Offline

Quote
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+")

old Re: Lua mapchange ?

Avo
User Off Offline

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

old Re: Lua mapchange ?

kch
User Off Offline

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

old Re: Lua mapchange ?

Kebabgamer
User Off Offline

Quote
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

old Re: Lua mapchange ?

kch
User Off Offline

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

old Re: Lua mapchange ?

sheeL
User Off Offline

Quote
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

old Re: Lua mapchange ?

kch
User Off Offline

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

old Re: Lua mapchange ?

EP
User Off Offline

Quote
@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.

old Re: Lua mapchange ?

sheeL
User Off Offline

Quote
user kch has written
Thanks sheel it works !!
which program you are using to create a lua.


Notepad++

old Re: Lua mapchange ?

limonata
User Off Offline

Quote
user sheeL has written
user limonata has written
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!

old Re: Lua mapchange ?

sheeL
User Off Offline

Quote
user limonata has written
user sheeL has written
user limonata has written
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

old Re: Lua mapchange ?

lucaSWAT
User Off Offline

Quote
user sheeL has written
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
To the start Previous 1 2 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview