English Lua mapchange ?

20 replies
Goto Page
To the start Previous 1 2 Next To the start
21.05.13 09:32:26 pm
Up
eyez
User
Offline Off
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 :
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 :

Code:
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
21.05.13 09:35:56 pm
Up
Avo
User
Offline Off
I'll give you an advice, young learner of lua. Use tabs.
Trust me, I'm an engineer | user DC approved file cs2d Super extra mod for CS2D (64), yeah!
21.05.13 09:37:46 pm
Up
ohaz
User
Offline Off
Code:
1
2
3
if (string.gmatch(env, "%S+") == "!map")
     parse("sv_map "..string.gmatch(env, "%S+"))
end
https://ohaz.engineer - Software Engineering
21.05.13 09:39:13 pm
Up
eyez
User
Offline Off
where i need to add this :

Code:
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
21.05.13 10:20:30 pm
Up
limonata
User
Offline Off
Code:
1
2
addhook("say","map")
function makespec
-- Dude, it should be map. like this

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

...
21.05.13 10:32:08 pm
Up
eyez
User
Offline Off
All the time it says that i made something wrong :

Code:
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 :
Code:
1
parse("sv_map "..string.gmatch(env, "%S+")
21.05.13 10:47:32 pm
Up
Avo
User
Offline Off
You changed "env" to "txt".


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


-->


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


and anywhere where there're "env"s in that function.
Trust me, I'm an engineer | user DC approved file cs2d Super extra mod for CS2D (64), yeah!
21.05.13 10:58:56 pm
Up
user limonata has written:
Code:
1
2
addhook("say","map")
function makespec
-- Dude, it should be map. like this

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

...


You are stupid?...

@edit²

Like this?
Code:
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
21.05.13 11:03:55 pm
Up
eyez
User
Offline Off
all the time in the consol :
it says Error at the line 137.

Here is the line 137 :
Code:
1
parse("sv_map "..string.gmatch(text, "%S+")
21.05.13 11:06:08 pm
Up
Avo
User
Offline Off
You would say at least, what error message you're having in the console, you know.
Trust me, I'm an engineer | user DC approved file cs2d Super extra mod for CS2D (64), yeah!
21.05.13 11:09:20 pm
Up
eyez
User
Offline Off
LUA ERROR: sys/lua/autorun/Server.lua:137: 'then' expected near 'parse'
21.05.13 11:11:03 pm
Up
Kebabgamer
User
Offline Off
Code:
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
21.05.13 11:13:33 pm
Up
eyez
User
Offline Off
yea it works but if i write !map de_dust it does not change the map.
21.05.13 11:53:13 pm
Up
Fixed. Works now !

Code:
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
21.05.13 11:55:30 pm
Up
eyez
User
Offline Off
Thanks sheel it works !!
which program you are using to create a lua.
22.05.13 01:52:12 am
Up
EP
User
Offline Off
@user eyez: 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.
22.05.13 04:34:37 am
Up
user eyez has written:
Thanks sheel it works !!
which program you are using to create a lua.


Notepad++
22.05.13 03:33:28 pm
Up
limonata
User
Offline Off
user sheeL has written:
user limonata has written:
Code:
1
2
addhook("say","map")
function makespec
-- Dude, it should be map. like this

Code:
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.

Code:
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!
22.05.13 07:08:10 pm
Up
user limonata has written:
user sheeL has written:
user limonata has written:
Code:
1
2
addhook("say","map")
function makespec
-- Dude, it should be map. like this

Code:
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.

Code:
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
22.05.13 07:17:31 pm
Up
lucaSWAT
User
Offline Off
user sheeL has written:
Fixed. Works now !

Code:
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


Code:
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
IMG:http://steamsignature.com/status/default/76561198053665521.png
IMG:http://steamsignature.com/AddFriend.png
To the start Previous 1 2 Next To the start