|
Post by Quintaxel on Aug 22, 2019 16:33:15 GMT 1
I think it's good practice to use a "sandbox map" to work out a script. The "sandbox map"only contains objects and features that are relevant for the script. So we need a map with the following. 1 scriptarea called "Start" 1 scriptarea Called "Arrival" 1 depot 1 truck (iScriptID 100) 1 road between scriptarea "Start" and scriptarea "Arrival" Waypoints (on the road) for the truck to follow. Now we also need to create a new Lua script file and link it to the map.
|
|
|
Post by Quintaxel on Aug 22, 2019 17:00:49 GMT 1
If we now translate what we want to do into structured English then we would have something like
MOVE TRUCK TO DEPOT
IF the truck 100 is on the map THEN *checking if unit exists.
IF the truck is in the Scriptarea "Start" THEN move the truck to Scriptarea "Arrival" ELSE Display message "The truck is no longer on the map" STOP function *from running again ENDIF
ENDIF
END *end of the function
Note: text after asterix is comment.
To be continued
|
|
|
Post by Quintaxel on Aug 22, 2019 20:17:12 GMT 1
Once we have written the function in Structured English it's quite easy to make a translation to Lua. The tricky part is that there is no standard BK function to make a unit follow waypoints. However, I created a custom function FollowWayPoints(...) for this a while ago. Below you can find the function in Lua script. function TruckToDepot_100 ()
if GetUnitState (100) ~= -1 then
if GetNScriptUnitsInArea (100, "Start") == 1 then
DisplayTrace ("The truck will now move to the depot");
FollowWayPoints (0,100, "w1","w2","w3","w4","w5", "w6", "w7", "w8", "w9", "w11", "Arrival");
end;
else
DisplayTrace ("The truck is no longer on the map");
Suicide ()
end;
end;
As you can see the function is just takes 11 lines including the of script of lines. Of course the function will have to be called in the Init () function or from another function. The complete working script can be found below. DisplayTrace ("Script to move supply truck to warehouse"); DisplayTrace ("Includes custom functions."); DisplayTrace ("Scripting by Quintaxel"); DisplayTrace ("Last revision 20-08-2019");
function TruckToDepot_100 ()
if GetUnitState (100) ~= -1 then
if GetNScriptUnitsInArea (100, "Start") == 1 then DisplayTrace ("The truck will now move to the depot"); FollowWayPoints (0,100, "w1","w2","w3","w4","w5", "w6", "w7", "w8", "w9", "w11", "Arrival"); end; else
DisplayTrace ("The truck is no longer on the map"); Suicide () end; end;
function Init () RunScript ("TruckToDepot_100", 3000); end;
---META functions---
function FollowWayPoints(...) local i = 3; if arg[2] ~= -1 then while arg[i] ~= nil do
QCmd (arg[1],arg[2],GetScriptAreaParams (arg[i])); i = i + 1; end; end; end;
For those interested. The map and script can be found here.
|
|
|
Post by Quintaxel on Dec 11, 2019 14:48:12 GMT 1
Using plugins for scripting in Notepad++ can safe a lot of time. With snippets you can keep chunks of Lua as 'snippets'. By double clicking on such 'snippet' the chunk of Lua script will be inserted in your scripting project. This also can be used for functions so you do not have to worry about syntax errors too much. Let me explain. The syntax of the BK function for calling a paratroopers is Cmd (22, Avion_iScriptID, iParty, x, y); Now with the notepad++ plugin Snippets you just copy this syntax as a snippet and call it 'Call Paratroopers' Whenever you need the function then just double-click on the snippet and the function will be pasted in your code. Just put the variables in the code and your done. Cmd(22, Avion_iScriptID, iParty, x, y);
You can of course keep larger chunks of code, like custom functions or frequently used functions. The plugin can be installed using the plugin manager. Hope this is helpful to someone
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,112
|
Post by kaoz on Dec 17, 2019 22:52:03 GMT 1
The plugin can be installed using the plugin manager. Hope this is helpful to someone I'm still using that old SciTE Editor for bk lua scripts... but i do use Notepad++ for html and css and i usually copy/paste from earlier stuff. It's probably a habit, but your tip could save a 10.000 clicks/year maybe, therefor i should give it a look!
|
|
|
Post by Quintaxel on Dec 17, 2019 23:41:24 GMT 1
If you want I can share a dark color scheme for KK Lua. It includes the syntax highlighting for BK functions. Take a look at page 23 of this thread to see what I mean.
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,112
|
Post by kaoz on Dec 18, 2019 0:12:53 GMT 1
a dark color scheme for KK Lua. It includes the syntax highlighting for BK functions. I know how to change colors thru Style Configurator in Notepad++ and get more or less the same as on page 23, but i'm unsure if that's what you mean. Is that KK lua a file that has to be put in a Notepad++ directory or...?
|
|
|
Post by Quintaxel on Dec 18, 2019 7:40:54 GMT 1
Notepad++ has syntax highlighting for different programming and scripting languages, including LUA. However, BK functions are not highlighted. So if you want also BK functions to be highlighted then you need to do some customization.
|
|
kaoz
General
inter faesces et urinam nascimur
Posts: 1,112
|
Post by kaoz on Dec 20, 2019 20:48:43 GMT 1
So if I understand correctly, your KK Lua is some sort of customized language, which can be chosen under 'languages' in the Notepad++ menu? Sure, if you want to share it, I might give it a try.
|
|
|
Post by Quintaxel on Dec 20, 2019 21:53:45 GMT 1
Sort of, right. The difference is that unlike the standard LUA you will see that BK functions are also highlighted. See the imaage below. All BK functions are highlighted in this blueish colour. I will send it to you.
|
|
|
Post by [BMG]Neutro on Dec 21, 2019 17:26:28 GMT 1
Please upload it here for everyone
thank you
|
|
|
Post by Quintaxel on Dec 23, 2019 12:14:12 GMT 1
Here's the Notepad++ theme for BK Lua.Just unzip the xml into the <Themes> folder of you Notepad++ installation. Then select the theme. Note that you a new file needs to be saved as a LUA file in order to activate the theme. The theme is based upon the Zenburn theme, a dark theme with soft pastel colours. Easy on the eyes.
|
|
|
Post by Quintaxel on Jan 11, 2020 13:23:53 GMT 1
What if a kind of reliability factor was added to mechanized units?
Take the Tiger for example. A great an powerful unit but prone to technical failure. What if a player would have to take into account that his units are vulnerable to technical failure. Like in real life a unit could fail on the battlefield.
Imagine that run hours increase the probability of a sudden breakdown. I thinks it's feasible to put a script together to manage the reliability of units. The algorithm to calculate the chances of a technical failure based upon the reliability of a unit and the time it operates on the battlefield may be a bit of a challenge.
You would need a reliability factor. A units that is a 100 % reliable does not will never fail in the game. = Standard BK rules. If a Tiger tank is half as reliable as a PzKpfw III then the chance of a technical failure of a Tiger would be twice as high.
In other words, the Tiger would probably fail after moving half the distance it travels on the map compared to the PzKpfw III.
Technical failures would be limited to movement. Units could be repaired by engineering units on battlefield.
This is just an idea and I do not even know if this feature would add some value to the game, but I'm pretty sure it's possible.
|
|
|
Post by Quintaxel on Jan 25, 2020 14:42:33 GMT 1
I'm re-scripting a map and learning a lot. Scripting is only a small part of mapping. The placement of units, unit balancing, writing a scenario and most important keeping track of it all. It happens that I do not remember where I placed units on the map, especially unis with a iScriptId. One of the things I do now is to use the 'Map Tools' to tag the units on the map. In the example below you can see a sniper with iScriptId 16303 and a group of light armour with iScriptId's 15405 to 15407. This works for me. It still happens that I miss a unit or I lost track if a unit exists or not so I wrote this little function CheckIfScripIdexists (iScriptId)
This function will return if a unit exists and it's coordinates. I use it as debug function. function CheckIfScripIdexists (iScriptId)
local state = GetUnitState (iScriptId);
local x,y = GetObjCoord (iScriptId);
if state ~= -1 then
DisplayTrace ("The unit with ScriptId %g is placed on the map at coordinates %g , %g", iScriptId,x,y);
else
DisplayTrace ("There is no unit with ScriptId %g on the map, sorry", iScriptId);
end;
end; In the example below you can see an example of how the function is used. function CheckUnits ()
CheckIfScripIdexists (16201);
CheckIfScripIdexists (16301);
Suicide ();
end; I take an in game screenshot after the information is displayed and then return to the map editor. Hope this is useful.
|
|
|
Post by keepitsimple on Jan 25, 2020 17:23:52 GMT 1
If you would use AskClient ("SetCamera (x,y)"); you might be in right part of map to spot it.
As x,y will be the viewpoint of the camera you might need to correct the x,y slightly to get right view on the object/unit.
You could of course do both DisplayTrace with coordinates and use AskClient to move in close to this point.
|
|