|
Post by Quintaxel on Jun 11, 2014 14:26:23 GMT 1
I searched the forum but could not really find a thread about scripting. So feel free to post any discussions about scripting in this thread. Let me start at what I'm good at, asking questions I want to know the ammunition level of a unit. For this the function GetNAmmo(iScripID) could be used as shown in the script below. function Ammo()
prim_ammo, sec_ammo = GetNAmmo (1300); --Unit with Script ID 1300 DisplayTrace ("Unit's Primary Ammo = %g",prim_ammo); -- Show primary ammo level DisplayTrace ("Unit's Secondary Ammo = %g",sec_ammo); --Show secondary ammo level Suicide();
end;
Now this function works fine for armoured units but does not seem to work for human units like a sniper (scout). Does anyone know if there's a way to find out how much ammo a scout or sniper is carrying ?
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jun 11, 2014 14:46:30 GMT 1
Short question here, are "prim_ammo" and "sec_ammo" variables or intrisic functions? If they are variables, how do you get a different for every single kind of ammo?
|
|
|
Post by Quintaxel on Jun 11, 2014 15:16:22 GMT 1
Kevin, they are variables. The function GetNAmmo (iScriptID) gets the ammo values of the unit with iScripID 1300 and assigns the primary ammo to the variable prim_ammo and the secondary ammo to the variable sec_ammo.
So for units as tanks the primary ammo will be the armour piercing shells and the secundary ammo will give the ammunition level of the tank's machine guns.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jun 11, 2014 17:54:35 GMT 1
Oh, oh, I see, that function can asign different values to two different variables if they are separated by a coma. I suppose it will always assign the primary one to the first variable and the secondary to the second variable.
|
|
|
Post by Quintaxel on Jun 11, 2014 22:14:14 GMT 1
That's correct, but as said this function does not seem to work with human units
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jun 11, 2014 23:12:47 GMT 1
I am afraid I can't help you since it's been a really long time since the last time I scripted in LUA.
|
|
|
Post by Major Pain on Jun 11, 2014 23:18:14 GMT 1
The issue is the number of Soldiers in a squad, usually 9 to 13. The Command can only handle single units.
You would have to first break the squad down to individual soldiers, and assign new ScriptID to each. Then use the Formation command to rebuild the squad.
Immediately you can an issue with this since there is no way to assign a ScriptID to individual soldiers after they have been assigned a Squad ScriptID. It is possible to assign a unit a Script unit within the Script, usually para units, but does have a couple of other applications.
These cmd actions have a bug. Once units are disbanded or reformed they become unstable or inaccessible.
iAction = 34 – DISBAND SQUAD : Cmd(34, iScriptID)
Each soldier is now independent and cannot be checked by the script since no ScriptID subset assignment exists. i.e. Squad ScriptID = 1000. If you disband the squad, each should still have the ScriptID = 1000, but they don't. The correction would be to assign them a new ScriptID in the order they appear in the members list -> 1000 (SquadID), 1001 = First units in members list in the 1.xml, 1002 = second unit, etc...
iAction = 35 – FORM FORMATION : Cmd(35, iScriptID, ...)
The issue with Form Formation is apparent. How do you Form a Squad out of various independent soldiers. Well it can be done, but this command does not work correctly.
Cmd(35, ScriptArea) You can only assign Soldiers within a Script Area to a Squad. No other combination will work. Once assigned, the squad cannot be moved by the player or script.
Try the GetNAmmo(iScriptID) on a sniper or officer and see what you get.
You can also get a Squads status or state.
GetSquadInfo(iScriptID)
This only tells you the formation, defense, offense, moving, etc...
Consider using
GetUnitState(iScriptID)
This returns a value which advises what action is underway... refer to Calvin's
|
|
|
Post by Quintaxel on Jun 12, 2014 12:44:30 GMT 1
Major, thanks for the explanation. I did not know about the command Cmd(35, ScriptArea). It is not mentioned in Calvin's guide It would be an interesting function but as you pointed out, pretty useless if there is no way to control the squad after assigning it to a group.
I tried the GetNAmmo(iScriptID) with a scout or officer but the game crashes so I presume now that the this function is not working with human units.
The idea was to have a unit (type scout) to trigger an event. I will have to find a workaround for this.
|
|
|
Post by Major Pain on Jun 12, 2014 20:45:41 GMT 1
I'll think about this as well... BK uses Lua 4.0. It is important to know this. There are many commands and keys that are not documented. Once you get into the LUA Key Tables, where the definitions are and functions are established, you can find out a lot about what you can do. I've used commands and global/local variable subsets that is not documented and it works fine. Once you break down the code, it's possible to create new definitions. The underlying code is C and Lua easily functions using C codes, and vice versa. Also, it is possible to get to the BK code to access other data that is passed between maps in Chapters and Campaigns. In the BK code they are called elements. Not all of these elements are evident as to what they are or the contents. I'm in the process of studying exactly what each element contains. If you look at the cut screens between maps, you see the element data... how you are doing as the commander, your losses and the number of enemy killed, captured guns, amount of resource (resupply) used and how many aircraft sorties. All of this data is maintained within a TABLE. A table is kind of like an array, but much easier to use. If you have worked around spreadsheets very much, you already know how tables are used. Sometimes these are called Look-up tables. It is the same thing. Lua can utilize metatables and coroutines easily. A metatable example might be a variable (or key) that performs a function or command... we call this a 'key' variable. When you need the data from that command you simply call the metatable key variable rather than the entire line of code. These work on the GetNxxx() commands and the most cmd codes. The structure is a bit tricky, but once you understand it, you can reduce the number of lines in your script. Faster access and processing. I recommend reading this -----> h ttp://www.lua.org/manual/4.0/and this ----> www.lua.org/pil/contents.html#P1 (This is Lua 5.0 but still relavent)
|
|
|
Post by Quintaxel on Jun 13, 2014 11:34:43 GMT 1
This is what I find strange. BK uses Lua 4.0 but still there are differences in syntax between BK Lua and Standard LUA 4.0. Besides that the Lua in BK does not have the Math library nor can it handle the functions for string manipulation ? Would it be somehow possible to add these functions by to BK ? I played around with tables in Lua to keep track of unit types, there position on a map and their status using using the functions GetObjCoord (iScriptID] and GetUnitState(iScriptID). I find these tables very powerful but the tables you are referring to, the ones containing data that is passed between maps and chapters, that is something else. I would not have a clue how this works so I'm afraid this is stuff for "code guys" only Major. It would be interesting if it were possible to create a library with custom made functions and to be able to call these functions from the lua file that is connected to a map. Has someone ever considered this ?
|
|
|
Post by Major Pain on Jun 13, 2014 17:52:11 GMT 1
Yep... I'm working on it...
|
|
|
Post by Quintaxel on May 4, 2015 11:30:56 GMT 1
I was playing with Lua script when I stumbled upon the following problem. This is what I want to do. Suppose there are 2 vehicles on the map, vehicle(a) and vehicle(b). Both vehicles need to swap places. That’s easy to do but here comes the tricky part. Both vehicles also need to have their front in the same direction of the vehicle they swapped places with. Now the function GetFrontDir(iScriptId) will return the direction of the front of a unit on the map. The returned value should be divided by 360 to get the value in degrees. So suppose vehicle(a) has a iScriptId 100 and vehicle(b) has a iScriptID(110) then the code below will get the front of the respective vehicles in degrees. Local FrontA = GetFrontDir (100)/65536*360; Local FrontB = GetFrontDir (110)/65536*360; Cmd (8, iScriptID, x,y) will rotate a vehicle in the direction of the coordinates x,y but this is not very helpful as I only know the original front direction of vehicle(a) and vehicle(b) in degrees. I’ll find a solution, but I was just wondering if there’s someone who has already solved this problem ?
|
|
|
Post by Major Pain on May 4, 2015 13:16:16 GMT 1
Are you replacing vehicle A with vehicle B on the map?
I'm was a little confused by your explanation.
If that is what you wish to do... the issue is going to be that one needs to be turned to the proper direction before the swap takes place. With the LandReinforcement command, this can be problematic if the direction of Vehicle A is incorrect.
So what should happen is Vehicle A should be turned to the correct direction before the swap, that way they both point the same direction.
But there is one more issue that needs to be handled. You must also make sure they occupy the same exact spot. So vehicle A should be moved to the correct location and then turned to the correct direction in that order. Both can be performed using cmd().
IF you do not know the direction that Vehicle B is pointed to (in degrees).... you can get this by using the same Command Function when the unit has been turned on in a test script, then store the value to plug in to the Rotation Script for Vehicle A. You can also collect the Location Data doing the same thing.
This requires some front end work on your Script, but when you do collect the values, you should have the issue licked.
If I am making an incorrect assumption on your requirement, please explain a bit more and I'll look it over.
|
|
|
Post by Quintaxel on May 4, 2015 20:44:39 GMT 1
Sorry for the poor explaination. Let me try again with some pictures. Both units are already placed somewhere on the map and may already have moved during the game. At the moment the script starts both units are not moving. This could be checked by the script. Let's call this the 'starting position' of the unit. In their starting position the front of Unit A and Unit B both have a direction on the map that can be found out with the funtion GetFrontDir (iScriptID)/65536*360; Call this the 'starting angle'. The script should; 1) move unit A to the 'starting position' of unit B and rotate to the 'starting angle' of Unit B and 2) move Unit B to the 'starting position' of Unit A and rotate to the 'starting angle' of Unit A and When the script end both units should have switched positions like in the image below. If there was a function to rotate a unit to a given angle then this would be simple but units can only be rotated to x,y coordinates. So this is the problem.
|
|
|
Post by Major Pain on May 4, 2015 22:32:47 GMT 1
Let me do some research and testing...
If you can collect the location data for each starting point, it seems to me you can use the ROTATE command to make them face it.
But you suggest that you cannot do this. That just doesn't seem logical to me. I have seen this in use before in BH-Rommel (I think). I'll go back and look at it.
The problem you outline now should be easier than what I incorrectly described earlier.
|
|