|
Post by Quintaxel on Mar 2, 2016 14:08:19 GMT 1
According Calvin's "Guide to Lua functions" it is not possible to switch the shell type of a unit from primary ammo to smokeshells through a script call. Did anyone find a workarround for this ? and if not would it be possible to make a unit that has smokeshells as ammo ? I want to script a retreat by the AI under a smokescreen
|
|
|
Post by keepitsimple on Mar 2, 2016 17:44:21 GMT 1
Calvin's Guide is correct. Is however possible to make a mortar that fires just smoke grenades. A example of this can be found in my Patch14. What I did was to take German 8cm_grwr34 weapon file. I replace the first shell type with the second entry (remove the first didn't work). The first entry is for normal grenades, the second is for smoke grenades. So now I have smoke grenade as normal and alternative ammo. After coping you most change DamageType="2" (as given in second entry) to DamageType="0" in the first. The weaponfile in the patch is called MortarSmoke.XML
|
|
|
Post by Quintaxel on Mar 2, 2016 19:38:47 GMT 1
Thanks, Keepitsimple. I'm not very familiar with weapon xml files but I'll try do do as you explained.
|
|
|
Post by Quintaxel on Mar 3, 2016 15:06:13 GMT 1
I’ve been playing around with scripting for a while now and I’m still a bit frustrated with the limitations of the BK functions and the behaviour of the AI. One of the conclusions I come to is that each unit on the map should have its own unique ScriptID to give better control over the way units behave through scripting.
I use a numbering system as below.
First digit for the party 1 for AI party 0 for Player Party 2 for Neutral Part
2 next digits for the unit type For example Vehicles are coded as follows
-- 10 = trn_civilian_auto -- 11 = trn_military_auto -- 12 = trn_tractor -- 13 = trn_medicine -- 14 = trn_support -- 15 = trn_carrier
Finally more 2 digits for the actual number of the unit.
So eg. unit with ScripID 11255 is
11255 a unit belonging to the AI side 11255 is a tractor type of unit 11255 is tractor 55
This means that the behaviour of a unit can be better controlled
For example: You could script a function that make entrenched units leave their trenches an take a run for it when they are under attack by one or more heavy tanks. However when it is a medium or light tank that is attacking the trenches then the script could decide to make the units their trenches, attack the tank, and get back to the trenches.
The question now is: Is it all worth the effort?
I enjoyed playing great maps that did not have a complex script behind it. So in my opinion scripting is one of the easier parts of making a map. The map layout, scenario, choice of units, knowing what you want the AI to do is far more difficult than the scripting itself. Anyway, I enjoy experimenting to see what is possible.
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,112
|
Post by kaoz on Mar 3, 2016 23:22:23 GMT 1
Good thinking Quin. In later maps, i also tried to give more units different ID's. The only problem is indeed, when you stop working on a map and restart after a long period, you forgot which is who. Therefore, i started creating simple txt-files that hold the ID information, so i can go back to it and see who's who.
|
|
|
Post by keepitsimple on Mar 4, 2016 10:43:18 GMT 1
Hi Quintaxel , Linking unit number to function is good idea. Tanks, Gun, Trucks, Repair, AA and infantry have different function and behavior and hence need different approach in script. For example a truck will not move if give the command (Cmd,3 If numbering all unit uniquely helps, I would question. What you need to know from a unit is: - party
- on the map or in a reinforcement (number of reinforcement)
- function/type
- an unique number of unit (optional)
When do need an unique number? In cases that units are linked. For example a truck and its gun. The number to identify the truck uniquely should then be the same as number to identify the gun it pulls. 10201 10321 10 is an unit from AI (from the start) 11 is the first reinforcement 20 is basic truck 2 is truck, 0 is basic 32 a anti-tank gun 3 is gun, 2 is anti-tank 1 is truck number 1 that pulls gun 1 Quintaxel if you could make a full list function\type and publish it here then mappers and scriptwriters could use this numbering. Why is the helpful? In scripting this helps a lot because if you need to know if attack has run out of steam (in other words the AI has no tanks left) you only need to count the number of tanks (GetNScriptUnitsInGroup(1110,1) and not number in the reinforcement. That there are still a few officers or a trucks around on the map is now not important. 11 reinforcement 1 for AI 10 is basic tank Similar need to know how many repair trucks the player has (GetNScriptUnitsInGroup(2023,0) + GetNScriptUnitsInGroup(2123,0) 20 is player form the start 21 is player from reinforcement 1, 23 is a repair truck. I assume that Quitaxel already thinking about a special function to make even more simple
|
|
|
Post by Quintaxel on Mar 4, 2016 14:44:11 GMT 1
Good thinking Quin. In later maps, i also tried to give more units different ID's. The only problem is indeed, when you stop working on a map and restart after a long period, you forgot which is who. Therefore, i started creating simple txt-files that hold the ID information, so i can go back to it and see who's who. Correct, it is not easy to keep track of all units when they all have a unique ScriptID. However I make a distinction between 2 categories of units; a) for which the a scripID is required for the script (these would be the units that get a ScriptID in the conventional lua scripts) and b) units for which the ScriptID is mainly used to retrieve information about that unit that then can be used for the AI behaviour or for creating new functions (this would be all other units that have no ScriptID in the conventional Lua script) You do not have to bother too much about units in the case the fall under category b. I hope this makes sense. I also use comments in the Lua script file to keep track of units that are used in the script. Recently I also take a mapshot (CTRL-SHIFT-ALT-F9) and add notes, comments, tactical movements, unit ID’s etc. on an extra alpha-layer.
|
|
|
Post by ariete on Mar 4, 2016 14:52:08 GMT 1
quin the idea improve surely the quality of play. but my knowledge about lua-script is basically very basic, so for me it's the hard part that me i'm primitive, i just needed to identify if unit is of the player or of the AI, and number of reinforcement. anyway more the meanings, more long is the number, so necessity to be short/essential and cover the maximun of the aspect possible AI/player start/reinforcement type of unit ... and then you know better than me which could be the others, which could be classed as essentials for the use. then if there's a universal method would be better, anyway, as usual different minds could look in different ways for different purposes. for example, me i'm not understand why focus so much the number about the type of unit: 12 tractor type, ok, and then 55? tractor .. again?! i understood better the second 10201 10321 10 is an unit from AI (from the start) 11 is the first reinforcement 20 is basic truck 2 is truck, 0 is basic 32 a anti-tank gun 3 is gun, 2 is anti-tank 1 is truck number 1 that pulls gun 1
|
|
|
Post by Quintaxel on Mar 4, 2016 15:04:45 GMT 1
Hi keepitsimple , Thanks for the valuable feedback. Much appreciated. I did not yet consider reinforcements. This is food for thought. Right now I’m testing some things to see if I can write a new function. The idea is to find out how many units of a certain type are within a certain “script area”. Something along the line of; GetNUnitsInAreaOfType (strUnitType)As long as Lua can keep up with the calculations it should be no problem to do this. I probably said this before but Lua for BK is limited as it cannot access the libraries for math and string manipulation. If it could then things could become interesting. There is hope that the MP can upgrade BK to Lua 5.1 but still not sure if that would include the standard libraries.
|
|
|
Post by Quintaxel on Mar 4, 2016 16:15:46 GMT 1
for example, me i'm not understand why focus so much the number about the type of unit: 12 tractor type, ok, and then 55? tractor .. again?! The type of unit is required because it gives information about the capabilities of the unit. Imagine the following situation in real life. WWII, You are a British commander driving around in the desert of Libya in a light tank . All of the sudden you see a Tiger tank on the horizon. What are you going to do? Are you going to take on the Tiger tank? I guess not because a Tiger is no match for your light tank. Intelligent move! Now what will the AI in your case. He will attack the Tiger tank. Brave…maybe but not so intelligent. I want make the AI to behave more like a human opponent would do. Unlike you the AI does not seem to know that a Tiger tank is no match for a light tank. So by giving the Tiger tank a ScriptID that gives information about its unit-type you could let the AI make smarter decisions. In the Lua script the type for a Heavy tank (Tiger) would be 51. So if the Tiger belongs to the AI side I would put 1 in front of the Unit Type. So the script ID would be 151xx where xx is just a number (eg 15101) Using Lua I can now retrieve the Unit type from the ScriptID and do something with that information. This will not always be that easy because sometimes the Lua would have to overwrite the AI of the BK engine. Eg. A truck connected to a warehouse will supply units, even if these units are under attack. So the script must prevent the AI form doing something stupid. I hope this explains better why I need unique ScriptID's
|
|
|
Post by Quintaxel on Mar 6, 2016 22:19:01 GMT 1
I did some scripting today and came up with this new function.
GetNUnitsInAreaOfType (UnitType, iPlayer,strScriptAreaName)
The function returns the number of units of a iPlayer party (Player, AI, Neutral) of specific type that are found in a ScriptAreaZone. As I explained earlier there are a number of prerequisites that need to be taken into account.
Units need to have a unique Id number. For the unit numbering a syntax has to be respected
xyyzz
Where; x is party the unit belongs to (0 for player, 1 for AI, 2 for neutral) yy is UnitType see below. zz = actual number of the unit ranging from 00 to 99. So you can use 100 units of a specific unittype per player.
I would reserve numbers for reinforcements eg unit number from 81 to 99 could be used for reinforcements only.
Lets take an example.
UnitType 53 = arm_medium (medium armour)
15300 to 15380 are used as for medium armour that is place on the map at the start of the game. 15381 to 15399 are used for medium armour in reinforcement groups.
Remember, the most significant digit 1 is used because the unit belongs to the party AI.
I could make this flexible (I think) so you would only have to declare this once in the script.
The Unit types I use so far are.
-- 10 = trn_civilian_auto -- 11 = trn_military_auto -- 12 = trn_tractor -- 13 = trn_medicine -- 14 = trn_support -- 15 = trn_carrier
-- 21 = train_armor -- 22 = train_super -- 23 = train_carrier -- 24 = train_cargo -- 25 = train_locomotive
-- 31 = art_heavy_mg -- 32 = art_mortar -- 33 = art_super -- 34 = art_rocket -- 35 = art_aagun -- 36 = art_heavy_gun -- 37 = art_howitzer -- 38 = art_gun
-- 41 = spg_aagun -- 42 = spg_super -- 43 = spg_antitank -- 44 = spg_assault -- 51 = arm_heavy -- 52 = arm_super -- 53 = arm_medium -- 54 = arm_light
-- 61= Soldier -- 62 = Engineer -- 63 = Sniper -- 64 = Officer
-- 91 = avia_lander -- 92 = avia_super -- 93 = avia_fighter -- 94 = avia_attack -- 95 = avia_bomber -- 96 = avia_scout
I hope that mappers see the same possibilities as I do. The AI could now find areas on the map that are poorly defended and do something with that information. Or to be more specific, this information could be used in a script.
Imagine an AI scout that not only can spot your units but can also 'report' the type of unit it sees. This is possible and maybe my next challenge.
Other function like a function to find out the number of units of a type within a circle with a given diameter or a function that returns the scriptId's of units that are within a circle or scriparea should not be to dificult to make.
I continue further testing and see what it leads to.
Should anyone be interested in how this function can be used or how it is scripted then let me know.
Q.
|
|
|
Post by Quintaxel on Mar 8, 2016 13:10:19 GMT 1
Assigning all units with a unique scriptID requires quite some additional work if you do this using the mapeditor. However there is a quicker way. 1)Assign the ScripId's for units as you would normally do when you make a map using the mapeditor. Just use the numbering that includes the unit types. This should be no extra work. 2)Import the objects from the map in Excel and add the remaining scripID's in Excel. This is a bit of extra work but is doable. I should be possible to even further automate this using some macros. I'm working on a map to proof the concept but I will not put much effort in developing tools for now.
|
|
|
Post by Quintaxel on Mar 13, 2016 20:13:33 GMT 1
I wrote another function this afternoon.
function GetNUnitsInCircleOfType (UnitType, iPlayer,xc,yc,radius,UnitsTable)
This function will return the number of units of certain type (UnitType) of party (Player, AI, neutral) that are within a circle with centre coordinates xc, yc and a given radius (radius).
This function makes it possible fot the AI to get information about the type of units that are within its viewing range. AI scouts can report what kind of units they are spotting.
Next challenge is to use these functions in an actual map.
|
|
|
Post by Quintaxel on Apr 20, 2016 16:29:00 GMT 1
Some time ago I had the idea for a function that gives better control of the movement of units. I thought that if I could use units to create somekind of waypoints on the map this would save me the frustration of units running into a minefield or move within the firing range of the enemy (see previous page of this thread) Last year a started to write some code on a paper napkin while I was enjoying my vacation in Ténérife but then I somehow lost "my notes". Now recently I found the notes and finished the function. This is how it works. The function has the syntax DynamicWaypoints (TiggerRadius,...) Finding a good name for a function is not easy.
The variable TriggerRadius is optional the radius of a circle with the x,y coordinates of the unit that is given as the first argument of the function . Units that are placed within this circle will trigger the function and move along a path that is set by the units for with the scripID is given as arguments. Take the following example DynamicWaypoint (300,1,2,3,4,5,6)
The circle made by object coordinates x,y of unit with scriptID 1 and a radius of 400 will trigger the function. Units with scriptID can be placed on the map in random order to create what I call "dynamic waypoints". In the image below the units are place in the order 1 - 6 - 4 - 5 - 3 - 2. When a unit comes close to the unit with scriptID 1 it will trigger the script and start moving to unit with scriptID 6 , the unit that is closest to the unit with scriptID 1. From there it will be moving to the unit with scriptID 4 because this unit is now the next closest unit to its position. The unit will continue to the next unit until it reaches the unit with ScriptID 2. The video should demonstrate what I mean. The prerequisite is that units have again a unique scriptID. I’m afraid that this will always be the price to pay for getting better control of the AI. I still want to polish and tweak the code (it is never good enough for me). I plan to add the movement mode of the unit as an option and make the variable “TriggerRadius” optional. I would also like to add a maximum distance between "waypoint" units. This would make it possible only to use some of the waypoint units.
|
|
|
Post by Quintaxel on Oct 14, 2016 11:32:03 GMT 1
I want to execute functions that are stored in a table. This would give more flexibility in calling these function. Anyone seen this being done in the map scripts ?
|
|