Re: Discussion: Conditional statements in BF1942
Posted: Wed Nov 21, 2018 10:41 pm
Modding templates while the round is running is a bit tricky, but doable.
A website for modding Battlefield 1942, BF2, BFV, and the Battlefield Series
https://bfmods.com/
Is there any command from the game engine that returns the amount of time in seconds remaining in a round? It would make it easier to create time dependent events instead of having an admin change the time limit manually.russ wrote:Modding templates while the round is running is a bit tricky, but doable.
Code: Select all
Var v_start
var v_end
var v_inter
Const c_on = 0
Const c_off = 1
Const c_start = 0
Const c_end = 200
profiler.enable c_off
profiler.enableTimer c_start -> v_start
profiler.disableTimer c_end -> v_end
Utils.mathExprI v_end - v_start -> v_inter
if v_inter < 200
debug.debugOutputMessage "Timer on" 1
elseif v_inter > 200
debug.debugOutputMessage "Timer off" 1
endIf
So this only works on a local server, on an Internet server the console will output an Unknown command or method error when the script is run. Any idea why that might be?Classical Modder wrote:I fixed the problem. I can confirm that the following code works correctly:
This will output the correct message, which will be seen by everyone in the server I think (needs to be tested on an Internet server).Code: Select all
Var v_time Const c_time1 = 3600 Const c_time2 = 1800 Const c_time3 = 900 Const c_time4 = 450 admin.timelimit -> v_time if v_time < c_time4 admin.serverMessage "Test 4" elseif v_time < c_time3 admin.serverMessage "Test 3" elseif v_time < c_time2 admin.serverMessage "Test 2" elseif v_time < c_time1 admin.serverMessage "Test 1" endIf
Even better still, an admin that has in-game rights can change the time limit with an alias like !timeXX, where XX is the amount of minutes (this is how they do it on SiMPLE). In a sense, this means that events can happen in-game depending on the time that is set by the admin.
For example, an admin could set the time to under 7.5 minutes and disable all weapons except zooks and knives, for a short zook and knives round. Of course, this still has to be tested. Working on it atm.
Well that’s disappointing. Thanks for the information though. Out of curiosity, how would one start a timer and end it? Do you have an example of a script?russ wrote:I did some more searching. You can start and stop timers, but the output is not consumable by scripts. There doesn't appear to be any way to get elapsed or remaining round time from within the console. It can only be obtained via the server info query port.
Code: Select all
> ConsoleProfiler.enable 1
> ConsoleProfiler.report
No profiling data available
> ConsoleProfiler.startGlobalTimer
> ConsoleProfiler.report
No profiling data available
> ConsoleProfiler.stopGlobalTimer
> ConsoleProfiler.report
Frames: 1
Seconds: 10.8271
------------------
Average fps: 0.0923611
Min fps: 0.0923611
Max fps: 0.0923611
------------------
Average ms/frame: 10827.1
Min ms/frame: 10827.1
Max ms/frame: 10827.1
------------------
Process 0: userTime/f = 0.00ms [100000000376832.00, 0.00]
, kernelTime/f = 0.00ms [999999986991104.00, 0.00]
Threads:
0 Global timer 10827.0690 ms/f, 100.0000%
0 Global timer 0.00% (sum)
I think these commands could have an interesting use. If one would like to know, for example, how long it takes them to move their tank from their main base to one of the flags on a map in Conquest mode, these commands could be used. This is especially useful in clanwars, where every second counts.russ wrote:Note that this appears to be tied into the renderer, so on dedicated the frames value isn't valid nor are any of the values derived from it.Code: Select all
> ConsoleProfiler.enable 1 > ConsoleProfiler.report No profiling data available > ConsoleProfiler.startGlobalTimer > ConsoleProfiler.report No profiling data available > ConsoleProfiler.stopGlobalTimer > ConsoleProfiler.report Frames: 1 Seconds: 10.8271 ------------------ Average fps: 0.0923611 Min fps: 0.0923611 Max fps: 0.0923611 ------------------ Average ms/frame: 10827.1 Min ms/frame: 10827.1 Max ms/frame: 10827.1 ------------------ Process 0: userTime/f = 0.00ms [100000000376832.00, 0.00] , kernelTime/f = 0.00ms [999999986991104.00, 0.00] Threads: 0 Global timer 10827.0690 ms/f, 100.0000% 0 Global timer 0.00% (sum)
Code: Select all
Var v_start
var v_end
var v_inter
Const c_on = 0
Const c_off = 1
Const c_start = 0
Const c_end = 200
profiler.enable c_off
profiler.enableTimer c_start -> v_start
profiler.disableTimer c_end -> v_end
Utils.mathExprI v_end - v_start -> v_inter
if v_inter < 200
debug.debugOutputMessage "Timer on" 1
elseif v_inter > 200
debug.debugOutputMessage "Timer off" 1
endIf
Code: Select all
Var v_start
var v_end
var v_inter
ConsoleProfiler.enable 1
ConsoleProfiler.report
ConsoleProfiler.startGlobalTimer -> v_start
ConsoleProfiler.stopGlobalTimer -> v_end
Utils.mathExprI v_end - v_start -> v_inter
if v_inter < 200
debug.debugOutputMessage "Timer on" 1
elseif v_inter > 200
debug.debugOutputMessage "Timer off" 1
endIf