English Read maps for a menu

12 replies
Goto Page
To the start Previous 1 Next To the start
08.11.13 03:20:40 pm
Up
Suprise
BANNED
Offline Off
Hey, yo today i decided to update one of my script (guess which) and I need a function for it. I tried to use this script:
file cs2d Stream functions library for Lua (14)
Not sure if it can do what i need.
Basically i want all maps in the "maps/" folder to be in an infinite menu. Can someone help me? (I have the infinite menu already)
08.11.13 03:27:23 pm
Up
_Yank
User
Offline Off
Ive already tried to do that. The unic problem is that the briefing files (map.txt) appears to.
I cant send you the source code of it because the computer when the file is stored dont turns on. If i get the PC back i tell you.

Admin/mod comment:

Removed the random off-topic message from your post /DC
08.11.13 05:20:50 pm
Up
Suprise
BANNED
Offline Off
@user _Yank: Okay thanks.
08.11.13 05:45:29 pm
Up
sheeL
User
Offline Off
This lua no go help you.
08.11.13 08:59:26 pm
Up
TopNotch
User
Offline Off
@user sheeL I thought you left the website...?
OT: I also made that and encountered the same problem as user _Yank. Maybe there's a way to let the script only read .map?
08.11.13 10:03:17 pm
Up
archmage
User
Offline Off
You'll need to get a table of the files in the map directory. This should work for GNU/Linux or Windows, but it's untested.
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function get_map_table(d)
  local t = {}
  
  -- Detect OS
  if ( os.execute("uname -o") == "GNU/Linux" ) then
    -- We're on a GNU/Linux machine, will list only maps
    local s = os.execute("ls -aX maps/ | grep *.map")
    for w in string.gmatch(s, "[^\n]+") do
       t[#t+1] = w
     end
     return t
  else
     -- Assume Windows, will list all files even if they aren't maps  (you could filter it out by removing any strings that don't end with '.map')
     local s = os.execute("dir /B maps/")
     for w in string.gmatch(s, "[^\n]+") do
       t[#t+1] = w
     end
     return t
  end
end
We must secure the existence of our people and a future for white children. 14/88
08.11.13 10:14:43 pm
Up
sheeL
User
Offline Off
@user _Yank: This interests you? haha
@user archmage: No work's hahha, and he maybe no go try use Linux(maybe).
08.11.13 10:31:25 pm
Up
VADemon
User
Offline Off
The magical all-in-one-line code:
Code:
1
parse("maps")

cs2d cmd maps
08.11.13 10:37:28 pm
Up
Suprise
BANNED
Offline Off
fuck @user VADemon won the party.

That's really shows all the maps, now I'm trying to make all the maps to be shown in the menu.

@user VADemon: Can you help me with a menu example with parse("maps")?
08.11.13 11:02:22 pm
Up
MikuAuahDark
User
Offline Off
thread cs2d Load maps in a lua Menu

io.popen version(Windows)
Code:
1
2
3
4
5
6
7
8
9
10
11
function ScanMap(ext)
     local temp={}
     local lpstr=io.popen("dir /b maps\\")
     for w in lpstr:read("*a"):gmatch("[^\n]+") do
          if w:sub(-4)==".map" then
               table.insert(temp,ext==true and w:sub(1,-5) or w)
          end
     end
     lpstr:close()
     return temp
end
Hello? Are you there, Tae Hanazono?
08.11.13 11:07:35 pm
Up
VADemon
User
Offline Off
1) Getting map list
• addhook cs2d lua hook log > function to save map names
• parse "maps"
• map list is saved by now (log hook), removehook log

2) By now every map name should be in the table, sorting into "official" map types (de_ zm_ etc.), everything else in alphabetical order
3) Use file cs2d [EngiN33R] UniMenu (31) (with caching on server start)
4) PROFIT
I am lazy.
08.11.13 11:11:44 pm
Up
EngiN33R
Moderator
Offline Off
user VADemon has written:
The magical all-in-one-line code:
Code:
1
parse("maps")

cs2d cmd maps

It's all well and good, except you also need to grab the output from the console. Still, it's not that difficult, and it's more universal and generally safer than using the system shell, so user VADemon wins a prize for thinking differently.

Try this, I tested it and it should work well.

EDIT: As per VADemon's suggestion, I shortened the code and generally made it a bit more elegant.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
maplist = {}

function grabmaps(txt)
     if (txt ~= "----- Maps -----") then
          maplist[#maplist+1] = txt
     end
end

function showMaps()
     addhook("log","grabmaps")
     parse("maps")
     freehook("log","grabmaps")
end


Previous version >
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
09.11.13 01:13:50 pm
Up
Suprise
BANNED
Offline Off
It Works like a dream lolz
If anyone want to make something similiar in the future i used this piece of code:
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
26
27
28
29
30
31
32
33
34
os.execute('dir "maps" > tmp')

maps2={}

for file in io.lines("tmp") do
     if file:sub(-4) == ".map" then
          table.insert(maps2,string.sub(file,38,-5))
     end
end

os.execute('del tmp') --windows

addhook("say","_say")
function _say(id,txt)
     if txt == "!lol" then
          for _,map in ipairs(maps2) do
               msg(map) --showing that it works
          end
     end
end

function selectmenu(id, page)
     local page = page or 1
     local pages = math.ceil(#maps2 / 6)
     if page < 1 then page = pages end
     if page > pages then page = 1 end
     local m = 'Start a vote for a new map P'.. page
     for i = 6 * page - 5, 6 * page do
          if maps2[i] then m = m ..', '.. maps2[i] else m = m ..',' end
     end
     if page == pages then m = m ..',,<<- First page' else m = m ..',,Next page -->' end
     if page == 1 then m = m ..',Last page ->>' else m = m ..',<-- Previvius page' end
     menu(id, m)
end


Thanks all for help !
To the start Previous 1 Next To the start