root/cafu/trunk/config.lua

Revision 72, 2.8 KB (checked in by Carsten, 21 months ago)

Added in-game console function pts2csv() to config.lua as documented at <http://www.cafu.de/wiki/appendix:pts2csv>.

Line 
1print=function(s)
2    Console.Print(tostring(s) .. "\n");
3end;
4
5exit=function()
6    quit=true;
7end
8
9-- Just for debugging the new physics code...
10function ph(grav)
11    grav=grav or -9.81;
12    runMapCmd("wait(3); crate_001:SetGravity(0, 0, "..grav..");");
13end
14
15-- Load the console variables with persistent values.
16do
17    CleanupPersistentConfig("config_p.lua");
18    local Result, ErrorMsg=loadfile("config_p.lua");
19
20    if (Result) then
21        Result();
22    else
23        print("\nWarning: Error when running config_p.lua ("..ErrorMsg..").\n");
24    end
25end
26
27
28-- Get the (sorted) list of files available as level intro music.
29MusicFiles=Console.GetDir("Games/DeathMatch/Music", "f");
30table.sort(MusicFiles, function (s1, s2) return s1:lower()<s2:lower(); end);  -- Sort the titles regardless of case.
31
32-- Filter the list (not every file is a good candidate for level intro music) and add the full path.
33LevelIntroTitles={};
34for FileNr, FileName in ipairs(MusicFiles) do
35    if ((FileName:sub(-4, -1)==".ogg" or FileName:sub(-4, -1)==".mp3") and FileName:find("Franka Jones, Track3")==nil) then
36        LevelIntroTitles[#LevelIntroTitles+1]="Games/DeathMatch/Music/"..FileName;
37    end
38end
39
40-- The client calls this function whenever the player enters a new level.
41function StartLevelIntroMusic()
42    if (#LevelIntroTitles==0) then return end;
43
44    local NextTitleNr=0;
45
46    -- Read the index number of the next title to play.
47    local File=io.open("Games/DeathMatch/Music/NextTitle.txt", "rt");
48
49    if (File) then
50        NextTitleNr=(File:read("*number") or 0) % #LevelIntroTitles;
51        File:close();
52    end
53
54    -- Update the next index number count.
55    local File=io.open("Games/DeathMatch/Music/NextTitle.txt", "wt");
56
57    if (File) then
58        File:write((NextTitleNr+1) % #LevelIntroTitles);
59        File:close();
60    end
61
62    MusicLoad(LevelIntroTitles[NextTitleNr+1]);     -- First array index is 1, not 0.
63    MusicSetVolume(0.5);
64    MusicPlay();
65end
66
67
68function pts2csv(fileName)
69    if fileName:sub(-4, -1):lower()==".pts" then
70        -- Strip the .pts suffix, if present.
71        fileName=fileName:sub(1, -5);
72    end
73
74    -- Load and run the point file in order to obtain the Points table.
75    dofile(fileName .. ".pts");
76
77    -- Write all points into a new csv file.
78    local csvFile=assert(io.open(fileName .. ".csv", "wt"));
79
80    csvFile:write('"time","x","y","z","heading","info"\n');
81    for i=1, #Points do
82        csvFile:write("\"", table.concat(Points[i], "\",\""), "\"\n");
83    end
84
85    csvFile:close();
86end
87
88
89-- sv_AutoAddCompanyBot=true;
90-- cl_maxLights=20;
91
92
93sv_rc_password="ca3de";     -- Change this for your own (dedicated) servers!
94cl_rc_password="ca3de";
95
96
97print("config.lua processed.");
Note: See TracBrowser for help on using the browser.