English mp_luamap and server.lua together

9 replies
Goto Page
To the start Previous 1 Next To the start
Up
Quattro
User
Offline Off
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?
16.05.18 08:14:58 am
Up
NanuPlayer
User
Offline Off
@user Quattro:

go to lua folder, make a new folder and name it "autorun", and put the scripts you want in it
Bad Life
16.05.18 08:32:48 am
Up
Bowlinghead
User
Offline Off
Make an array list of all map names with LUA;
Then check wether one of these maps has been loaded. (cs2d lua cmd mapchange)
Then you do cs2d cmd luareset and then dofile the map´s lua. There are probably better ways
Share time limited free games here
16.05.18 10:53:01 am
Up
Quattro
User
Offline Off
Isn't there an easier way?
16.05.18 11:14:28 am
Up
Masea
Super User
Offline Off
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.
Create and design your GUI easy and fast: file cs2d GUI Framework (12) | Go deep of the darkness and try your intrepidity: file cs2d Outlast 2 Modification (25)
16.05.18 11:20:53 am
Up
Talented Doge
User
Offline Off
Code:
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
Talented Doge
16.05.18 11:22:59 am
Up
Yates
Reviewer
Offline Off
@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:
Code:
1
eyy = true


server.lua:
Code:
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
16.05.18 12:57:53 pm
Up
Bowlinghead
User
Offline Off
The order was documented somewhere.
I believe in the autorun folder
edited 1×, last 16.05.18 03:23:53 pm
Share time limited free games here
16.05.18 02:05:22 pm
Up
Cure Pikachu
User
Offline Off
@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")
IMG:https://i.imgur.com/5UWPaft.png
IMG:https://i.imgur.com/xpsyQRX.png
16.05.18 05:07:27 pm
Up
Quattro
User
Offline Off
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:
Code:
1
eyy = true


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