Forum

> > CS2D > Servers > mp_luamap and server.lua together
Forums overviewCS2D overview Servers overviewLog in to reply

English mp_luamap and server.lua together

9 replies
To the start Previous 1 Next To the start

old mp_luamap and server.lua together

Quattro
GAME BANNED Off Offline

Quote
How to enable a default script on all maps but if you open a map with its own lua script, the main server.lua would be disabled?

old Re: mp_luamap and server.lua together

Masea
Super User Off Offline

Quote
Putting a line like
parse('mp_luaserver ""')
to the head of the map script would probably do the trick however I don't know whether the map scripts run firstly or not. You have to try it yourself in order to see if there's an easier way to do so.

old Re: mp_luamap and server.lua together

Talented Doge
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
mapnames = {}
NOTMATCH = false

for a in io.popen([[dir "D:\SteamLibrary\steamapps\common\CS2D\maps\" /b /o:e]]):lines() do
	if string.sub(a, -3) == "lua" then table.insert(mapnames, a)
	else break end
end

for i = 1, #mapnames do if map("name")..".lua" == mapnames[i] then NOTMATCH = true break end end

if NOTMATCH == false then
	msg("OH FUCK YOU NO LUA FOR THIS MAP?")
endd

Here you go. Do note that the directory needs to be an absolute path.
edited 1×, last 16.05.18 11:28:30 am

old Re: mp_luamap and server.lua together

Yates
Reviewer Off Offline

Quote
@user Talented Doge: What are you doing? Just check the current map. Why build a table with all maps in the map directory?

@user Quattro: Put a
msg
in the map Lua file and
server.lua
, see which one appears first. If the map one appears first just set a variable and return at the top of the
server.lua
if the variable is set.

mapname.lua:
1
eyy = true

server.lua:
1
2
3
4
5
if eyy then
    return
end

-- your code

If that doesn't work because
server.lua
is loaded before the map Lua, use a timeout to check the value and cs2d cmd luareset

old Re: mp_luamap and server.lua together

Cure Pikachu
User Off Offline

Quote
@user Bowlinghead: And you are right.
sys/lua/autorun/Readme.txt has written
Execution order of Lua scripts is
• Server Lua file (default: "sys/lua/server.lua")
• All Lua files in "sys/lua/autorun" (in alphabetic order)
• Map Lua file (default: "maps/<NAME OF MAP>.lua")

old Re: mp_luamap and server.lua together

Quattro
GAME BANNED Off Offline

Quote
user Yates has written
@user Talented Doge: What are you doing? Just check the current map. Why build a table with all maps in the map directory?

@user Quattro: Put a
msg
in the map Lua file and
server.lua
, see which one appears first. If the map one appears first just set a variable and return at the top of the
server.lua
if the variable is set.

mapname.lua:
1
eyy = true

server.lua:
1
2
3
4
5
if eyy then
    return
end

-- your code

If that doesn't work because
server.lua
is loaded before the map Lua, use a timeout to check the value and cs2d cmd luareset


How to use the timeout method? That is the case according to load sequence
To the start Previous 1 Next To the start
Log in to reply Servers overviewCS2D overviewForums overview