|
Post by feldgrau on Dec 14, 2018 22:24:29 GMT 1
A wonderful piece of lua. As far as I am concerned, you have opened a new big door for the battle presentation in BK, thank you. Ein wundervolles Stück lua. Was mich betrifft hast Du da eine neue große Tür für die Gefechtsdarstellung in BK aufgestoßen, danke dafür. and now all the more
|
|
|
Post by Quintaxel on Dec 14, 2018 23:27:59 GMT 1
It's me who should thank you for inspiring me. Ich sollte dir danken dass du mich inspiriert hast. Check this new custom function function SetNGlobalUnitsOfType(strUnitType, iParty) local totalunitsoftype; totalunitsoftype = GetNUnitsOfType (strUnitType, iParty); SetIGlobalVar (strUnitType, totalunitsoftype); end; The function will store the number of units of strUnitType belonging to iPlayer into a global variable. This number can then be called like in the example below. carrier_party0 = GetIGlobalVar ("trn_carrier",0);
Make sure to use the same variable names as the ones known in BK. See below. Trains
train_armor train_super train_carrier train_cargo train_locomotive Aviaavia_lander avia_super avia_fighter avia_attack avia_bomber avia_scout Armourarm_heavy arm_super arm_medium arm_light SPGspg_aagun spg_super spg_antitank spg_assault Artillery art_heavy_mg art_mortar art_super art_rocket art_aagun art_heavy_gun art_howitzer art_gun Transporttrn_civilian_auto trn_military_auto trn_tractor trn_medicine trn_support trn_carrier Squadsofficer sniper engineer soldier Here's a small map that explains funtion.
|
|
|
Post by ranjid on Dec 29, 2018 11:36:15 GMT 1
At the moment I want to add in the lua scripts a special feature.
I need a command that fix each mission on "normal". So the player can not change difficult.
I asked that in past but can not find the thread anymore.
|
|
|
Post by Quintaxel on Mar 11, 2019 14:14:05 GMT 1
The resupply of squads inside a buidling or trench seems to be a shortcoming in the AI of BK. This could probably solved by scripting a function that makes the AI bring in fresh troops from behind the frontline. The idea is that the AI would send a truck to replace the squads inside a bunker with a fresh squad (100 % health and 100% ammo). The squad in the bunker would then be brought back behind the front. The function could look something like; ReupplyPosition (iScriptId_a, iScriptId_b, iScriptTrnsprt, strAreaLoad, strAreaUnload, iObject)A function to do this would need the following arguments. - iScriptId_a: The iScriptId of the squad in the bunker/building. - iScriptId_b: The iScriptId of the squad that will replace the squad inside the bunker/building. - i ScriptTrnsprt: The iScriptId of unit bringing the units to and back from the front. - strAreaLoad: The name of the scriptarea where the truck picks up the squad to bring them to the front. - strAreaUnload: The name of the scriptarea where squads leave the truck to move inside the bunker and where troops leaving the bunker are picked up. - iObject: The iScriptId of the buidling of bunker in which the squad is placed To resupply units inside a bunker the function would have to; - Check if units inside the bunker need to be reinforced (replaced) - Check if it's safe for the supply truck to move towards the bunker. - Check the IScriptId of units inside the bunker. - Put the reinforcement squad(s) on the map - Load them into a truck - Move the truck to the bunker (strAreaUnload) - Unload the Squad - Move the units inside the bunker to the area where they will be picked up by the truck. - Move these units inside the truck - Move the truck back behind the front. - Move the reinforcement squad inside the bunker. To make the truck between the resupply point and the bunker it would be desirable that the truck follows a path instead of moving in a straight line towards the bunker. The challenge is that the AI should move squads to there initial positions, at least if you want them to be resupplied. So the bunker would be empty when the game starts. I see it as doable to script such function but maybe I'm overlooking something crucial. Trucks are vulnerable during this operation but this is also the case when the AI resupplies troops. Besides, maybe it could be possible to have the trucks escorted by armoured vehicles. Food for thought
|
|
|
Post by Quintaxel on Apr 11, 2019 10:40:03 GMT 1
I found some time to write out the script as mentioned above but I noticed something strange.
If the game is saved while the script is running and then loaded again the script just continues where it left. This is how it should be.
However if I end the game and then restart the game from the menu something strange happens. At the start of the game a unit is placed on he map as LandReinforcement. When the game is started from the map editor then the unit appears on the map as it should.
If then the game is ended and started again from the menu the unit does not appear. Moreover the script runs as if the unit is on the map but it has become invisible.
Does anyone have a clue what could be causing this or ever experiences something a similar ? I looks like a bug to me because, regardless of the script, restarting the game should reset all variables.
Edit: Seems that variables that have been declared as global reside in memory when the game is restarted from the menu. Something to take into account when scripting.
|
|
|
Post by Quintaxel on Apr 11, 2019 21:01:08 GMT 1
Crappy movie of a Lua function to bring troops from behind the front and put them in a bunker. I will try to post a better movie later. Movie starts with a black screen, so have a little patience.
Next step would be to replace units in the bunker (or any building) with fresh units. The function will check if there are units in the bunker. If yes he will replace them. If no the AI will simply bring the units to the bunker. Let me know if this interesting. The current function works but I would like to do some more tweaking.
|
|
|
Post by Quintaxel on Apr 12, 2019 15:14:32 GMT 1
The current function looks like;
ResupplyInit (iSquada, iSquadb, iTransp, strLoad, strUnload, iTarget, ...)
iSquada and iSquadb are the iscriptId of squads.
iTransp is the iScriptId of the truck
strLoad is the name of the scriptarea where the squad(s) get into the truck.
strUnload is the name of the scriptarea where the squad(s) leaves the truck, in the vicinity of the bunker
iTarget is the iScriptId of the bunker.
... are the arguments for the waypoints (scriptarea names) that the truck will follow when bringing the squads to and back from the bunker. No need to define the number of arguments because the script will find out.
The function could be used as in the example below
ResupplyInit (100,110,500,"Load","Unload",1,"W1","W2","W3","W4","W5","W6","W7","W8","W9","W10","W11","W12","W13");
Thats all a mapper scripter has to worry about.
The function still need some work and could be improved further, but it's a start.
|
|
|
Post by Quintaxel on May 10, 2019 12:31:07 GMT 1
Just finished a working version of a function to resupply squads that are in a building (bunker).
The function will load a squad into a truck, move the truck to the front, unload the squad en move them to the bunker. If there are any units left in the building then these units are brought back behind the front line. If not then the truck just moves back and is removed from the map.
I made a movie to demonstrate this (sorry for the poor quality)
This is what happens: - an officer will be moved to a building. (This unit is needed to trigger an action) - A squad is moved to the bunker. - The officer will 'trigger' reinforcements, so a fresh squad will be moved to the bunker. The units that are left in the bunker are brought back.
The function uses a number of arguments. I tried to keep the use of the function simple so it can be used by mappers having basic knowledge of BK scripting. (The function itself is still basic Lua, but you need not to worry about the code)
The syntax of the function is;
ResupplySquad (iSquada,iSquadb,iTransp,strLoad, strUnload, iTarget, wpIndex, ...)
To use the function is a script a mapper should;
a) Create the following script areas
- Loading point: Scriptarea where the squad will move into a truck. ("Load") - unloading point: Scriptarea where the squad will move out of the truck. ("Unload") - Waypoints: Scripareas that the truck will follow to move between the 2 script areas mentioned above.
b) Put the following units on the map a reinforcement groups
- unit used for the transport of the squad. - 2 squads
c) add a building with a scriptID. This is the building or bunker that the squad will enter.
I still would need to script special conditions, like in case the building/bunker is destroyed after the function was started or in case the truck was destroyed.
This function should also work to resupply units in trenches but I have not yet tested this.
|
|
|
Post by Quintaxel on Jun 13, 2019 13:01:45 GMT 1
A word about global variables.
When using global variables in a script then know that values stored in these variables will be stored when the game is saved. This is an important property of global variables.
Suppose, for whatever reason, you want to keep track of the number of times a given unit crossed a bridge during a game. If the bridge is crossed 3 times then an action should be triggered. Let's say that the bridge has already been crossed 2 times during the course of the game. You could store this value in a global variable named "timescrossedbridge", using the instruction;
SetIGlobalVariable ("timescrossedbridge", 2);
When the game is then saved and loaded again the variable "timescrossedbridge" will still contain the value 2. This is exactly what you want. Should you not use a global variables to store "timescrossedbridge" the variable would be reset at 0 after reloading the game.
However, suppose you want to restart the game from the menu, then know that the global variables will not be set back to their initial values (0). So if you restart a game then the value stored in "timescrossedbridge" will be 2 and not 0.
Therfore it's important to initialise global variables (set their value to 0) when a script is run for the firt time.
Should someone be interested then I can explain how this can be done.
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,112
|
Post by kaoz on Jul 3, 2019 19:54:06 GMT 1
At the moment I want to add in the lua scripts a special feature. I need a command that fix each mission on "normal". So the player can not change difficult. I asked that in past but can not find the thread anymore. SetDifficultyLevel(1); 0=easy, 1=normal, 2=hard I usually put that in the init function so it works thru the whole map. Never tried to use it for just one single mission, but I guess you can jump from hard to easy and back in one single script/map.
|
|
|
Post by Quintaxel on Jul 30, 2019 12:56:56 GMT 1
One of the things I miss in BK is that the AI does not have scouts. In fact the only recon units that the AI uses are recon planes. When a player uses a sniper as a scout then he will move the sniper around the map looking for enemy units. If an enemy units is withing range then the player will stop or move back the sniper to avoid that the sniper gets within the viewing range of an AI unit. This makes the sniper a very powerful unit. So I thought it would be nice if the AI could more or less use a sniper (or snipers) in the same way. The role of the sniper would be mainly to scout, so I prefer to call the unit a scout rather then a sniper. Such sniper behaviour can be scripted but there are some challenges that have to be taken into account. - The limitation of BK Lua - The script itself should be fast enough not to cause trouble during the game. - Simple an hassle free to use for mappers. - Postions and status of the scout must be saved during savegame. Furthermore I have some requirements for a sniper script. - It should be possible to drop scouts from a plane and let the scout do his work once he's on the ground. - When the scout reaches a destination point then the there should be the option to trigger another function. - If the option to trigger a function is not used then the scout should use his binoculars With this in mind I scripted a function for such an AI scout. So far everything works as expected. I just need to add the script for using the binoculars when the scout reaches his destination and the option to trigger an external function is not used. The picture below explains the basics of the function. - The scout starts from a stating point and will move to the first point on the map. (Scout stating Point) - The scout will remember this position. - The scout will move from one point on the map to the next. (Red points). These point have to be put on the map by the mapper as scriptarea points. - The scout will continiously check its position against the position of player units. - When a player unit comes within a given range (R2) then he will stop and go into sneak mode. - If a player units comes within closer range (R1) then the scout will move back to a previous point. - The scout will move back and forth along the points until he's killed or the script ends.
|
|
|
Post by Quintaxel on Jul 30, 2019 13:16:30 GMT 1
Now imagine the following simple implementation of using these scouts in a map The yellow squares are Player units on the map. The AI has 2 scouts, AI Scout 1 and AI Scout 2, who can move along there respective paths indicated with red and cyan dots. Player positions are within range of an AI artillery. The moment a scout detects a player unit he will hold his position (or move back if necessary). The AI's artillery will fire at the player unit that was detected by the scout. If the player unit is destroyed then the scout will move forward until another player unit is spotted. In this way these AI scouts can make life more difficult for the player. I'm now running some further tests to see how this function can be put to use on an actual map. In most maps I have played so far (not too many) I have rarely had to defend the parts of the map I had conquered on the AI. This makes it possible to use all remaining units for the next objective. Now imagine AI scouts snooping around the map, giving information about the player's position. This could be done as follows without too much effort. When the AI scout reaches the last point on his path then this means that there's a safe path for the AI to move it's units along the same path the Scout used. So once the scout has reached his destination then a simple function could be called to move some units along the path of the scout and take in a position or attack the player from behind. The function can easily be called from the scout function as the called function can be given as an argument of the scout function. Ideas, thoughts are welcomed.
|
|
|
Post by Quintaxel on Aug 18, 2019 9:58:14 GMT 1
Does anyone know which value is stored in the global variable <Weather.TimeToFadeOff> ? I found this in a script and as the variable is not declared in the script it must be variable that is already known to BK. I assume that there are more variables in the table "weather"
RunScript("Paradrop", GetIGlobalVar("Weather.TimeToFadeOff", 0));
The variable is used as an interval to run the function "Paradrop" so my guess is that Weather.TimeToFadeOff is the delay between calling the instruction SwitchWeather(0); and the time the weather is actually switched off.
So in case it's raining the variable Weather.TimeToFadeOff would be the time in ms between the instruction SwitchWeather(0); and the moment the rain actually stops.
|
|
|
Post by Quintaxel on Aug 21, 2019 21:41:35 GMT 1
Although the syntax of (BK) Lua is quite simple (compared to other programming languages) it still requires some basic understanding of programming. However, scripting seems to be the major reason why potential mappers give up there ambitions to create good maps. Now scripting is only aspect of mapping and not even the most important one. What you should be able to do as a mapper is write down your ideas in such a format that it can be translated into actual LUA.
There are several tools/techniques to do this but but I would like to suggest to use what is called 'Structured English' This 'Structured English' uses only a couple of statements and as it is not actual programming or scripting language it can be used by people who do not know how to script or program.
This is basically how it works;
- Write the statements in plain English statements that need to be executed top down. - Use keywords for indicating conditional blocks like IF THEN and ELSE - Use of keywords for indicating repeated operation WHILE, DO UNTIL - Write keywords in capitals.
Sounds complicated already ? Let me illustrate with an example that it is not.
On a map there are 2 ScriptAreas called, "Defence1" and "Defence2" Also 2 reinforcement groups have been defined, 220 and 230
Now the mapper wants the script to do the following.
If the number of AIunits within ScriptArea "Defence1" is less than 5 and the number of AIunits in ScriptArea "Defence2" is less than 10 then he want to put reinforcemengroups 220 and 230 on the map. If the number of AIunits within ScriptArea "Defence1" is less than 5 but the number of AIunits in ScriptArea "Defence2" is more than 10 then the player should get a message.
It's important to know what you expect from the script. Now putting this down in structured English would look something like.
----- SEND REINFORCEMENTS
IF number of AIunits in the Scriptarea "Defence1" < 5 THEN IF number of AIunits in the ScriptArea "Defence2" < 10 THEN put reinforcementgroups 220 and 230 on the map STOP running this function ELSE Show the message "There are still more then 10 AIunits in Scriptarea Defence2" ENDIF ENDIF END FUNCTION
---- Translating this 'Structured English" into Lua the script would be something like;
function Reinforce_220_230 ()
if GetNUnitsInArea ("Defence1") < 5 then
if GetNUnitsInArea ("Defence2") < 10 then LandReinforcement (220); LandReinforcement (230); Suicide (); end;
else DisplayTrace ("There are still more then 10 AIunits in ScriptArea Defence2"); end;
end; You would still need someone who can do the translation from the 'Structured English' to BK Lua but this is no big deal for a scripter. Now people who are familiar with the use of structured English may remark that there are some more conventions for syntax that should be taken into account but for the purpose of map scripts this should not be an issue
If anyone is interested we could agree or own version of structured English for BK.
|
|
|
Post by Quintaxel on Aug 22, 2019 12:41:51 GMT 1
Let's look at a practical example to demonstrate the process of putting an idea into script.
The concept The player's objective is to control a road between a given point on the map and a supply depot.
The mapper has made a large map with few warehouses/depots. This means that the player will have to move his supply units over a longer distance across the map. The supply truck should only move along the road when going to a depot/warehouse. The player idea is that the supply truck will move to the depot when the player places the truck in a certain place on the map.
Therefore a script is required that will automatically move the supply truck from a point "A" to a point "B", the depot the moment the truck is placed on point "A" Point "A" will be called "Start" Point "B" will be called "Arrival"
|
|