Discussion: Conditional statements in BF1942

Ask questions, discuss ideas, get answers
Diamondback
Posts: 589
Joined: Mon Oct 01, 2012 3:13 pm
Location: Canada
Contact:

Discussion: Conditional statements in BF1942

Post by Diamondback »

Hi all,

I have been reading a lot about conditional statements in BF1942 lately. Using 4CentShy's website (http://www.velotech.net/battlefield/tutorials.php) has helped me greatly in understanding the basics of using conditional statements in BF1942.

I am now trying to create my own scripts for basic stuff such as verifying mod versions for clients (map side) and stuff. Things like this require basic if/else/elseif statements and are rather simple to do. I however know absolutely nothing about coding and would like to build more complex scripts. The current script I am working on evaluates what the server round time setting has been set to and prints a debug message to the screen (client side) depending on what the time has been set to. Here is the code:

Code: Select all

Var v_time

Const c_time1 = 3600
Const c_time2 = 1800
Const c_time3 = 900
Const c_time4 = 450

game.serverGameTime -> v_time

if v_time < c_time1
debug.debugOutputMessage "Test 1" 1

elseif v_time < c_time2
debug.debugOutputMessage "Test 2" 1

elseif v_time < c_time3
debug.debugOutputMessage "Test 3" 1

elseif v_time < c_time4
debug.debugOutputMessage "Test 4" 1

endIf
The idea behind this script is to create different gaming conditions based on the round time that the server host sets on his/her server. I want to be able, for example, if the round time is set to below 20 minutes, to set an infantry only conversion of the map. If the server hosts sets less than 60 minutes as the round time limit, then a message that says "Test 1" will be printed on the screen. For a round that is less than 30 minutes, the message will be "Test 2" instead, and so on.

I know the coding in the above example is completely wrong, as in all cases, the returned debug message will always be "Test 1", because the first if statement will always be true. Setting the variables to something like c_time1 < v_time < c_time2 is unfortunately not supported by the game (the console says the boolean syntax is incorrect).

There is the option to use the Utils.expr command, but I have no idea how it works even after having read 4CentsShy's explanation about it. Here is a script that he made that uses Utils.expr, which compares variables between them using operators like <, >, <=, =>, &, | and !=:

Code: Select all

Var v_debug
Var v_urg
Var v_spawn
Var v_strat
Var v_sai
Var v_bot
Var v_sense
Var v_areas
Var v_none
Var v_botspawn


game.showAIStats      -> v_debug
ai.showStrategicAreas -> v_areas
ai.showBotStats       -> v_bot
ai.showBotSense       -> v_sense
ai.showBotSpawnCoord  -> v_spawn
ai.showBotUrgencies   -> v_urg
ai.showStrategies     -> v_strat
ai.showSAIStats       -> v_sai

Utils.expr v_urg  | v_spawn   -> v_none
Utils.expr v_none | v_strat   -> v_none
Utils.expr v_none | v_sai     -> v_none
Utils.expr v_none | v_bot     -> v_none
Utils.expr v_none | v_sense   -> v_none
Utils.expr v_none | v_areas   -> v_none
Utils.expr ! v_none           -> v_none 

Utils.expr ! v_spawn -> v_botspawn
Utils.expr v_bot & v_botspawn -> v_botspawn

game.showAIStats 1
game.enableFreeCamera 1

if v_debug == 0
   debug.debugOutputMessage "Show AI Stats is ON" 1
   ai.showBotUrgencies   0
   ai.showBotSpawnCoord  0
   ai.showStrategies     0
   ai.showSAIStats       0
   ai.showBotStats       0
   ai.showBotSense       0
   ai.showStrategicAreas 0
elseif v_none
   debug.debugOutputMessage "AI Strategic Area debugging is ON" 1
   ai.showStrategicAreas 1
elseif v_areas
   debug.debugOutputMessage "AI Bot Stats debugging is      ON" 1
   ai.showStrategicAreas 0
   ai.showBotStats       1
elseif v_botspawn
   debug.debugOutputMessage "AI Bot Spawn debugging is also ON" 1
   ai.showBotSpawnCoord  1
elseif v_spawn
   debug.debugOutputMessage "AI Bot Sense debugging is      ON" 1
   ai.showBotStats       0
   ai.showBotSpawnCoord  0
   ai.showBotSense       1
elseif v_sense 
   debug.debugOutputMessage "AI Bot Urgency debugging is    ON" 1
   ai.showBotSense       0
   ai.showBotUrgencies   1
elseif v_urg
   debug.debugOutputMessage "AI Strategy  debugging is      ON" 1
   ai.showBotUrgencies   0
   ai.showStrategies     1
elseif v_strat
   debug.debugOutputMessage "AI SAI debugging is            ON" 1 
   ai.showStrategies     0
   ai.showSAIStats       1
elseif v_sai
   debug.debugOutputMessage "AI debugging is now            OFF" 1
   game.showAIStats      0
   ai.showSAIStats       0
endif
How can I improve my own script to make it work properly using Utils.expr? I am pretty much lost on what arguments to use and the logic that 4CentsShy used to compare variables between each other.

tl;dr: Just use this thread to share your knowledge about conditionals in BF1942. Apparently there are more possibilities than just using if/else/elseif as commands. The while loop also seems to work (tested in a BF1942 map, it works but I don't know how to use it properly) and return, but I'm not sure what else also works.
See my Strasbourg map project here.
russ
Posts: 73
Joined: Sun Oct 29, 2017 8:12 am

Re: Discussion: Conditional statements in BF1942

Post by russ »

Code: Select all

Var v_time

Const c_time1 = 3600
Const c_time2 = 1800
Const c_time3 = 900
Const c_time4 = 450

game.serverGameTime -> v_time

if v_time < c_time4
debug.debugOutputMessage "Test 4" 1

elseif v_time < c_time3
debug.debugOutputMessage "Test 3" 1

elseif v_time < c_time2
debug.debugOutputMessage "Test 2" 1

elseif v_time < c_time1
debug.debugOutputMessage "Test 1" 1

endIf
Diamondback
Posts: 589
Joined: Mon Oct 01, 2012 3:13 pm
Location: Canada
Contact:

Re: Discussion: Conditional statements in BF1942

Post by Diamondback »

russ wrote:

Code: Select all

Var v_time

Const c_time1 = 3600
Const c_time2 = 1800
Const c_time3 = 900
Const c_time4 = 450

game.serverGameTime -> v_time

if v_time < c_time4
debug.debugOutputMessage "Test 4" 1

elseif v_time < c_time3
debug.debugOutputMessage "Test 3" 1

elseif v_time < c_time2
debug.debugOutputMessage "Test 2" 1

elseif v_time < c_time1
debug.debugOutputMessage "Test 1" 1

endIf
Thx Russ. I’ll try that now and see what happens. Another question, do you know what v_arg1 does? This variable seems to be global and is always set to “host”. It is present in Conquest.con and some other files and I never quite understood what it was for.
See my Strasbourg map project here.
Diamondback
Posts: 589
Joined: Mon Oct 01, 2012 3:13 pm
Location: Canada
Contact:

Re: Discussion: Conditional statements in BF1942

Post by Diamondback »

I tried the modification you posted Russ, and it still only returns "Test 1" because whatever value you set as the round time (that is less than 3600 seconds), the v_time < c_time1 condition is always true, because the time limits will always be lower than one hour. Trying to set == instead of < to see what happens.
See my Strasbourg map project here.
russ
Posts: 73
Joined: Sun Oct 29, 2017 8:12 am

Re: Discussion: Conditional statements in BF1942

Post by russ »

I haven't tested it, but the first condition encountered is:

if v_time < c_time4

Which if true will execute:

debug.debugOutputMessage "Test 4" 1

The other conditionals are 'elseif' so will be ignored. Are you sure of v_time? Try printing that as well.

When using the 'run' command, either internally by the engine, or via a script, the arguments get passed as v_arg1, v_arg2, v_arg3, etc. When the engine calls scripts via run, it typically uses 'host' as the first argument since it's running as a server.
Diamondback
Posts: 589
Joined: Mon Oct 01, 2012 3:13 pm
Location: Canada
Contact:

Re: Discussion: Conditional statements in BF1942

Post by Diamondback »

So with the code you provided, the output is always "Test 4", as you can see in the image below:

Image

I first tried to set the round time to 4 minutes (240 seconds). Logically this should print "Test 4" on my screen and this happened the first time I tried the script.

I then disconnected from the local game I created and set the round time to 27 minutes (1620 seconds) to see if it would output something different than "Test 4". But all it does it output "Test 4" no matter what the round time value is set to. Not really sure what to do at this point. I'll try testing more stuff out.
See my Strasbourg map project here.
russ
Posts: 73
Joined: Sun Oct 29, 2017 8:12 am

Re: Discussion: Conditional statements in BF1942

Post by russ »

...you disconnected from the local game you created. game.debugOutputMessage is a client only message, it has no effect on the server. If you're seeing output from it, the commands are running client side. I'm pretty sure game.serverGameTime is only valid server side.

debug.debugOutputMessage v_time

I'm guessing you'll get either a 0 or a blank line.
Diamondback
Posts: 589
Joined: Mon Oct 01, 2012 3:13 pm
Location: Canada
Contact:

Re: Discussion: Conditional statements in BF1942

Post by Diamondback »

Maybe game.sayAll or admin.servermessage would be better instead of the debug command then? I’ll keep testing. Thanks for all the info btw.
See my Strasbourg map project here.
russ
Posts: 73
Joined: Sun Oct 29, 2017 8:12 am

Re: Discussion: Conditional statements in BF1942

Post by russ »

Also if you are doing server side modding, I'd highly recommend two separate installs. One for the server and one for the client.
Diamondback
Posts: 589
Joined: Mon Oct 01, 2012 3:13 pm
Location: Canada
Contact:

Re: Discussion: Conditional statements in BF1942

Post by Diamondback »

I fixed the problem. I can confirm that the following code works correctly:

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
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).

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.
See my Strasbourg map project here.
Post Reply