Grot
General
J-23 znowu nadaje
Posts: 4,049
|
Post by Grot on Aug 3, 2017 12:57:07 GMT 1
introducing Grot the sniper doesn't make it easier for me but thank you for what you're doing here
|
|
|
Post by Quintaxel on Aug 3, 2017 12:57:20 GMT 1
|
|
|
Post by Quintaxel on Aug 8, 2017 12:12:22 GMT 1
Before I continue I would briefly like to discuss the BK function RandomInt(n) function. This function will return a random number between 0 and n-1. eg. RandomInt (5); wil return the value 0,1,2,3 or 4 Now what is this function good for ? Well it's a very useful function to let the outcome of a decision depend on the odds of getting a value from randomly generated number. Hmmm......sounds complicated. But let me give an example. Suppose we let reinforcements depend on the outcome of rolling a die. The outcome could be used to decide the number of reinforcement and/or type of reinforcements we put on the map. Other possibilities would be to take other factors like the number of units on the map, the loss of units, the time in which an objective is reached into the equation for calculating the odds of getting the reinforcements So the RandomInt(n) function is BK's virtual rolling die. A simple script to simulate the rolling of a dice would be; Function RollDice ()
local p = RandomInt (6)+1;
DisplayTrace ("Result = %g",p);
end; Possible results of the BK function p = RandomInt (6); are the integers 0,1,2,3,4,5 so we need to add 1 to get a result between 1 and 6 If you look at the DisplayTrace (); function then you will notice the use of %g in the text string "Result = %g". The function will replace %g with the value of variable that follows the text. In this case the variable p. Note: It may seem that I'm skipping from one subject to another but I want to keep these Lua lessons as practical as possible by using real BK scripting examples. Therefore it's sometime necessary to briefly explain the use of a BK functions. Hence these little sidesteps. In the next post we'll have a look at putting reinforcements on the map. After that we get back to the if...then else statement and combine everything in a script.
|
|
|
Post by Quintaxel on Aug 8, 2017 21:14:49 GMT 1
Let' s go back to the if [condition] then statement as shown in the flowchart below. If the condition is true then the script following then will be executed. flowchart if....then statement.In Lua the if...then statement can be followed by an optional else statement. In case the condition is false the script following the else statement will be executed as shown in the flowchart below. flowchart if...then...else statement.The syntax for using the if then else statement in Lua is if (condition) then --script that will be execute if the condition is true else script that will be execute if the condition is false. end;The if then else statement can be demonstrated through a script that simulates rolling 2 dice (die1 and die2) every 3 seconds until the total on the dice is 12. If the total is 12 then stop rolling the dice and display the number of rolls that were required to get 12. Don't worry, I don't want to introduce the use of dice to play BK, just demonstrate the use of the RandomInt (n) function and the if...then...else statement.
I'll show how this is done in the next post.
|
|
|
Post by Quintaxel on Aug 9, 2017 21:25:51 GMT 1
Here you can find the script. I added comments but with was explained in the previous it should be easy to understand. The odds of having when rolling 2 dice = 1/36 or about 2,8%. The script is useless in a BK map unless you change the code following then and else statement. This will be clear in the next posts. For those who are following these lesson. You should be able to read and understand the script above. Now to complete the lesson about the if...then..else statement there is just on more thing you should know. Suppose that we add another condition to our dice rolling script; - If the result of rolling the dice is 2 then we have to reset the counter. - The script should also count the number of times the counter was reset before the result of rolling the dice is 12. Edit: Here's the link to map and script of lesson 6a I'm afraid this will be for tomorrow. Bewaren
|
|
|
Post by Quintaxel on Aug 10, 2017 21:12:32 GMT 1
If the script needs to look a different conditions then the if...then statement can be followed by an optional elseif...else statement The syntax is; ------------------ if [condition1] then--excute script if [condition1] = TRUE elseif [condition2] then-- execute if [condition1] = FALSE but condition2 = TRUE elseif [condition3] then-- execute if [condition1] and [condition2] are FALSE but [condition3] = TRUE else-- execute if [condition1], [condition2] and [condition3] are all FALSE end;------------------ Below you can find the script that counts the number of times two dice have to be rolled to get a total of 12 before rolling a total of 2. Just added an extra condition to check if the result of rolling the two dice = 2. If this condition is TRUE then the variable ' attempts' is increased by 1 and the variable 'rol' is set back to 1. I increased the interval to run the script to 300 milliseconds to speed things up a bit. With what we have learned so far we can now get to a more practical use of the if..then..else statement. In the next exercise we will look at how we can make the AI attack a player unit from the left flank, the right flank or head-on depending on the odds. 20 % chance of attacking heads-on 30 % chance of attacking from the left flank 40 % chance of attacking from the right-flank 10 % chance of not attacking at all. After taking these "Lua lessons for absolute beginners" you should now be able to write a script that does this Here's the link to the map and script
|
|
|
Post by Quintaxel on Aug 11, 2017 12:23:38 GMT 1
Below a map shot showing what needs to be scripted.- The two AI tanks will attack the unit. The AI will choose a random path. - There's a 10 % chance that the AI will not attack. In this case the player should get a message. - The odds of choosing a path is indicated in the map shot. Optional (for those who want a bit of a challenge)- The attack shall be triggered by moving the player tank in the position shown on the map. This means that the player tank will be in another position on the map at the start of the game. - When the AI does not attack (10 % chance) then the script will run once again. More option (More challenging)- Units will return after the attack. - In case the AI does not attack then then the delay for running the script should be doubled. Remember, this can be scripted by what was learned in the previous lesson. Yes you can ! Here's the map in case you want to give it a try. Feel free to discuss possible approaches, ideas, thoughts,..... After all this is a discussion forum, right. Otherwise I would have called this thread 'The Lua Monologues'
|
|
|
Post by Quintaxel on Aug 12, 2017 17:30:56 GMT 1
I may have been over enthusiastic when I said that the case shown above can be scripted with what was learned in the previous lessons. I may have overlooked something. Let me expplain. It's clear or should be that the BK function RandomInt(n) will be used to decide where the direction of the attack by the AI. If by using the function RandomInt(n) we create a random number between 1 and 10. Then we can check if that number. The odds that the number is; 1 is 1 out of 10 or 10%.2,3 is 2 out of 10 or 20%.4,5,6 is 3 out of 10 or 30 %any other possible numbers will be 7,8, 9 or 10, so the odds of here are 4 out of 10 or 40 %
To explain this I made a little drawing. Let say that each colour represents a group of numbers. We can check if a number falls within a certain group by using the if...then...elseif...else statement but for some groups we will need to check 2 conditions. This can be done by using the and, or idioms. To check if a number n falls into the red group ( the number is 4,5 or 6) the if....then statement could look like this if n > 3 and n < 7 then ... ... end;
any number greater then 3 and less then 7 will be 4,5 or 6. That's it. So by using the and idiom you can easily check multiple conditions. Remember the script following the then statement will only be executed when both conditions are TRUE.In case the or idiom is used in in an if...then statement then the script following the then statement will be executed if one of the conditions is TRUEif n > 3 or n < 7 then ... ... end;
In the example above n can be 4 to 10 (condition1 n>3) or 1 to 6 (condition2 n<7). This condition will always be TRUE in our case but this statement doe not make sense. Bewaren
|
|
|
Post by Quintaxel on Aug 12, 2017 20:43:22 GMT 1
Below you can find a script to let the odds decide if and how a the AI will attack a player unit. Because this is a demo the AI units are shown in their staring position. To do this another BK function is used, namely; ViewZone ("ScriptAreaName",1);
This function will remove 'the fog of war' from the script area on the map called 'Lights' The argument 1 will remove the fog of war, the argument 0 turns the fog of war back on. ViewZone ("Lights",0); Note: that this only works with script areas that are circular.Here the script then, as said nothing new here: The map and script can be downloaded hereBewaren
|
|
|
Post by feldgrau on Aug 29, 2017 19:48:34 GMT 1
Hi...
Task Map "test01"
Build a defensive position between the palm trees (Zone_01 / Zone_02). The enemy attacks when the officer goes to the desert house. The enemy attacks the weaker zone. Download Map "test01" for Blitzkrieg1 without anything
Task Map "test02"
Conquer the villages (Village_01 / Village_02). The enemy starts a counter-attack in the direction Village_01 if in Village_01 Player0 bigger than Player1 or in direction Village_02 if in Village_02 Player0 larger than Player1. Download Map "test02" for Blitzkrieg1 without anything
If you want to see everything, just place Player1 on Side 0.
mbkg Feldgrau
|
|
|
Post by Quintaxel on Dec 8, 2017 17:22:01 GMT 1
For those interested. Here you have the latest update of Geany (Geany 1.32) IMO Geany is the best free IDE for scripting Lua. I have included the BK functions so there are highlighted as functions in the IDE. To install, just extract the zip file in a directory of your choice. If you open Geany and type a Blitzkrieg function (eg. DisplayTrace ("hello Geany"); then you should see the syntax highlighting. If not then go to the menu tools and select: Tools\Configuration Files\File Type Configuration\Scripting Languages\Filetypes Lua Download Geany 1.32 including BK functions here.
|
|
|
Post by Quintaxel on Dec 9, 2017 12:33:00 GMT 1
Challenge: Make a script that does the following For 3 units (Heavy armour) and for each unit; a) keep track of the distance the unit has moved on the map. b) Each unit can only travel a set value of distance. (Variable fuel value) c) I the fuel value drops to zero then the unit cannot be moved any further. more; d) When a fueltruck (can be any truck) comes close to the unit then its fuel value is restored. Sounds like fun to script
|
|
BigJoe
General-major
Posts: 538
|
Post by BigJoe on Dec 9, 2017 22:59:04 GMT 1
It is very nice to see that you are very busy.
|
|
|
Post by Quintaxel on Dec 10, 2017 0:05:04 GMT 1
Good to see you back BJ. Busy,....well I like to script every now and then.
I managed to script something quick and dirty this afternoon. The script measures the distance each unit travels and make the unit stop after 'it run out of fuel'. I do this by checking the coordinates of each unit at intervals. If a unit moved then I calculate the distance it moved and subtract that form the units fuel value. The moment the fuel value drops to zero the unit comes to a halt and cannot be moved any more by the player.
The problem is that the player gets no information about the amount of fuel the unit has left until it actually stops. Now I could give each unit a unique name and then display (DisplayTrace) some information about the amount of fuel that is left.
I think I can make this work but it would not be practical for more then lets say 5 units. Not so much because the script could not handle it but because it would be too difficult for the player to manage the units.
|
|
|
Post by Quintaxel on Dec 18, 2017 12:55:19 GMT 1
For those interested. I made a movie to demonstrate the management of fuel for units. This is just intended as a proof of concept. The current script is quite simple. Each unit is given a certain amount of fuel. This amount of fuel is in fact the number of script points the unit is allowed to move. The script checks the movement of the unit and subtracts the movement of the fuel value.
The player cannot monitor the fuel level. If the script works with named units (each unit with fuel management has a unique name) then it would be possible to feedback (DisplayTrace) a units is running low on fuel.
If anyone is interested then the script could be improved and expanded. I still would have to script refuelling of the units. As I said, I just made this for fun.
|
|