bb
General
Blitzkrieg junkie (tried to quit several times).
Posts: 1,362
|
Post by bb on Jun 4, 2017 20:54:14 GMT 1
I'm working in this idea and I'll comment later.
|
|
|
Post by Quintaxel on Jun 4, 2017 22:15:53 GMT 1
I have it running but there's still a glitch. The function should not run when there are no units 'pinned' to a circle, so when the array is empty. I'll check it out tomorrow.
|
|
|
Post by Quintaxel on Jul 22, 2017 16:56:59 GMT 1
It's been a while but I found some time to work out a function to keep a unit within a circle with a given radius. The function PinUnitToCircle (ScriptId,radius) will store the current x,y position of the unit and keep the unit within a circle with the given radius. eg. PinUnitToCircle (1200, 300); will keep the unit with ScriptId 1200 within a circle with a radius of 300 script points. When the unit moves outside the circle it will return to its original position. PinUnitToCircle (1200, -1); will 'release' the unit and make it possible to move outside the circle again.
In the script below 10 units can be kept within a circle.
For those who are interested, just create a map with 3 units with scriptID 100, 200 and 300 and link the script blow to that map.
DisplayTrace ("PinnedLua V2.0"); DisplayTrace ("22-07-2017"); DisplayTrace ("Test of function PinUnitsToCircle");
Array = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
function CheckBreak() RunScript ("K",3000); Suicide(); end;
function Pin200() PinUnitToCircle (300,300); PinUnitToCircle (200,300); PinUnitToCircle (100,300); Suicide(); end;
function Unpin100() PinUnitToCircle (100,-1); Suicide(); end;
function Pin100() PinUnitToCircle (100,200); Suicide(); end;
function Unpin_all() PinUnitToCircle (200,-1); PinUnitToCircle (300,-1); Suicide(); end;
--Check free position in Array --Fill in unit --Run Script to keep units inside the circle ---------------------------------------------- function PinUnitToCircle (ScriptId,radius) --Variables
local i; local x,y; ----Remove a unit from the array if radius == -1 then for i = 1,10 do if Array[i][1]== ScriptId or Array[i][1]== -1 then --or function to remove killed units Array[i] = {0,0,0,0}; end; end; else ----Add a unit to the array x,y = GetObjCoord (ScriptId); for i = 1,10 do if Array[i][1]== 0 then Array [i][1] = ScriptId; Array [i][2] = x; Array [i][3] = y; Array [i][4] = radius; break; end; end; RunScript ("CheckBreak",3000); Suicide(); end; Suicide(); end;
function K() local unit,x,y,r; local t = 0;
local i; for i = 1,10 do local var = Array[i][1];
if var > 0 then -- If the array at pos contains a unit t = 1; -- iterate through the table starting from position 1 x = Array [i][2]; -- stored x position of unit y = Array [i][3]; -- stored y position of unit r = Array [i][4]; -- radius that can move away from x,y position check = IsUnitInCircle (var, x,y,r); -- Check if the unit is within the circle with radius r if check == 0 then -- if the unit is outside the circle with radius r then return units to pso x,y Cmd (8,var,x,y); QCmd (0,var,x,y); t = 1 + 1; end; end; end; DisplayTrace ("t = %g",t);
if t == 0 then Suicide(); end; end; function Init() DisplayTrace ("Init is running"); RunScript ("Pin200",2000); RunScript ("Unpin100",5000); RunScript ("Unpin_all",15000); RunScript ("Pin100",20000); end;
-------------------------------------------------------------- function IsUnitInCircle (iScriptID, xc,yc,Radius) -- By Quintaxel 15-06-15 -- Requires: None -- Function checks if the ScriptId unit is within a circle with xc,yc coordinates and radius -- Input parameters: UnitId, x,y coordinates and radius of circle. -- Output parameters: 1 if unit is within circle, 0 if unit is outside circle -1 if unit does not exist.
local isin = 0; if GetUnitState (iScriptID) == -1 then return -1; end; local xp, yp = GetObjCoord (iScriptID); if ((xc - xp)*(xc - xp)) + ((yc -yp)*(yc -yp)) < Radius*Radius then isin = 1; end; return isin; end;
|
|
|
Post by Quintaxel on Jul 24, 2017 19:12:40 GMT 1
For those who like to script I can recommend the IDE "Geany". I customized the portable version so the BK functions are highlighted. Just download the program and extract it into a directory of your choice. Give it a try, you will not be disappointed. link to Geany PortableI'm aware there's a more recent version than the version 1.29 I uploaded. Maybe I'll upload the newer version later. Bewaren
|
|
BigJoe
General-major
Posts: 538
|
Post by BigJoe on Jul 24, 2017 23:16:48 GMT 1
We are aware that their work is very hard. Thank you very much.
|
|
|
Post by Quintaxel on Jul 25, 2017 19:16:19 GMT 1
It seems that scripting is considered the hardest part of creating maps. In my opinion scripting itself is the easy part and I believe anyone can learn how to write a basic script. The difficult part of making a map is putting together the different scenarios, so knowing what you want the script to do.
Lua, the programming language used in BK, is a so called scripting language so the code does not need to be compiled into an exe file before it can be run. Scripting languages are, in general, easier to learn and faster to code than compiled languages. In fact, a Lua script is nothing more than a text file with the extension .lua instead of .txt.
The computer, in our case the BK Engine, will interpret the txt (or instructions) of the Lua file on the fly. So the Lua script makes it possible to communicate with the game engine. You could use any text editor to write a script but it's more convenient to use a so called IDE or Integrated Development Environment. I posted a link to 'Geany' in the post above.
So basically, through Lua we can get information from a map and give instructions to the game engine to control events on the map. Most of the instructions used in BK map are functions that have been included by the developers of BK. In fact you do not need really need to learn Lua to write a map script. Basically all you need to do is to learn to use these instructions. In the next posts I will give some examples of how to use BK Lua in a script.
No prior knowledge of Lua or programming is required but you should have some basic knowledge of using the map editor.
|
|
|
Post by Quintaxel on Jul 25, 2017 19:21:32 GMT 1
In the map below I have place a German Officer on the map. In order to control this unit through script it should be given a Script ID This is done by double clicking on the unit to make a window with the unit's properties pop-up. The original value for the unit's Script ID is -1 (equals no specific Script ID) The Script ID of the officer has been changed to 100. There's also a tree on the map. This tree has been placed at the map x,y coordinates 1288, 1250 This is what we want to do; Move the German officer under the tree.Now we need to create the script and link it to the map. To do so open 'Geany', create a new file and save it as <Lesson_1.lua> You must not forget the extension .lua Both the map and the Lua file should be placed in the folder \DATA\MAPS\ Linking the Lua file to the map is done by clicking the icon and selecting the lua file.
|
|
|
Post by Quintaxel on Jul 25, 2017 20:21:04 GMT 1
The script to make the unit move looks like this Let's go through the code step-by-step Lines 1,2,3The function DisplayTrace ("text"); is used to display a text on the map. DisplayTrace is an interesting function to give feedback about the script. Lines 5 to 9 is the function to move the unit to the tree. A function is simply a chunk of Lua script that starts with function and ends with end;The function can be given any name but it's good practice to give a function a name that gives information about what the function does. Line 7The actual command to move a unit Cmd (0,100, x coord, y coord);
Gives the order to move (= 0) the unit with iScriptID 100 to move to the position x =1288, y = 1255 script points on the map. Line 8Suicide ();After this function is executed it is no longer needed. It only needs to run once. This is the reason for the Suidide(); command. Line 9end;
Line 13 function Init ()
This is a very special BK function. Without it the script will not work. The function Init () starts to run when the moment the game is started. Line 14RunScript ("MoveUnit100", 5000);Runs the function MoveUnit100 exactly 5000 miliseconds after the game starts.
Line 15 end;
Every function ends with end;
The function Init () is no exception
You will notice that the function Init () does not have Suicide (); before end;This is because the this function should keep running through the course of the game. I'll elaborate on the Suicide (); later. link to the map
|
|
Grot
General
J-23 znowu nadaje
Posts: 4,049
|
Post by Grot on Jul 25, 2017 20:25:33 GMT 1
more
|
|
|
Post by Quintaxel on Jul 25, 2017 20:45:13 GMT 1
More tomorrow. Teraz czas na piwo
|
|
Grot
General
J-23 znowu nadaje
Posts: 4,049
|
Post by Grot on Jul 25, 2017 21:06:28 GMT 1
Niech Nam Żyje Żywca full ..gul gul gul
|
|
BigJoe
General-major
Posts: 538
|
Post by BigJoe on Jul 25, 2017 21:09:02 GMT 1
Przykro mi, nie piję alkoholu. Tomorrow more, I will be here.
|
|
Grot
General
J-23 znowu nadaje
Posts: 4,049
|
Post by Grot on Jul 26, 2017 7:26:29 GMT 1
I'll be coming drunk to class ..that's the only way I can understand this shit . Big Joe you can sit next to me in class I will chronically steal your lunch money.
|
|
BigJoe
General-major
Posts: 538
|
Post by BigJoe on Jul 26, 2017 14:14:32 GMT 1
I'll be coming drunk to class ..that's the only way I can understand this shit . Big Joe you can sit next to me in class I will chronically steal your lunch money. ......
|
|
|
Post by Quintaxel on Jul 26, 2017 17:25:39 GMT 1
Let's move on to the next lesson We have seen the command to move a unit to x,y coordinates on the map. Cmd(0, iScriptID, x, y);
Now BK lua also makes it possible to put commands in a queue. To do this we use QCmd(0, iScriptID, x, y); Let's look a the screenshot below. I've put a sniper on the map with the Script ID 110 I want the sniper to 1) Move to the tree but unlike the officer the sniper should move from barrel to barrel along the path. 2) When the sniper reaches his destination then he should use his spyglasses to watch the farm. This is how it looks in script. The image below should explain how the script works. The first command Cmd (0,110,555,575); is followed with QCmd (0,110,530,958); and so on. The BK engine will read the queue of commands and execute them in order. The last command in the queue is not a command to move (code 0) but a command to use the spyglasses or binoculars (code 29)
So the Cmd command will trigger a unit to take a certain action. Commands can be queued by using QCmd.Map of lesson 2 link
|
|