|
Post by Quintaxel on Aug 24, 2015 21:05:18 GMT 1
bb, this is the script you requested. It's quite straightforward I guess. I calculate the distance between the 2 units using the function GetDistBetwUnits(unit1, unit2) and compare it with a set distance. Make sure to add the function sqrt() to the script. I do not consider myself a scripter so there may be better solutions but this does the job. To test the script; Create a map with 2 units ScriptID 100 and ScriptId 200 Put a reinforcementgroup 300 on the map. Move the units close to eachother to get the reinforcements. You can play with the variable <close> to determine the best distance between the units. copy the script to a Lua file and link it to the map. Here it goes. --------------------------------------------- Startup Message ----------------- DisplayTrace ("Sending in reinforcements when 2 units ScriptId's come together"); DisplayTrace ("Scripting by Quintaxel"); DisplayTrace ("24-08-2015 R1"); -------------------------------------------------------------------------------- function BB1() local close = 150; -- The maximum distance between units to get reinforcements (in scriptpoints)
local distance = GetDistBetwUnits(100, 200); -- Actual distance between both units
if distance < close then -- if the distance between bot units is smaller then the minimum distance
RunScript ("ReinforceGroup300", 3000); --This could be any script that you want to trigger.
Suicide(); end; end; function ReinforceGroup300 () LandReinforcement ("300"); -- Obvious
Suicide(); end; function Init() RunScript ("BB1", 3000); end; ------------------------------------Metafunctions------------------------------ function GetDistBetwUnits(unit1, unit2) -- Script by Quintaxel 24-08-2015 (R1)
-- Calculates the distance between 2 units in scriptpoints.
-- Requires sqrt ()
-- Input parameters: unit1, unit2 ScripId's of units
-- Output parameters: dist, distance between 2 units
-- Callingprotocol: GetDistBetwUnits(unit1, unit2);
local dist; local x1,y1 = GetObjCoord (unit1); local x2,y2 = GetObjCoord (unit2); local x = x1-x2; local y = y1-y2; dist = sqrt ((x*x) + (y*y)); return dist; end; function sqrt(x) -- Insert the function sqrt(x) here !!!!!!!!!!
|
|
bb
General
Blitzkrieg junkie (tried to quit several times).
Posts: 1,344
|
Post by bb on Aug 25, 2015 5:48:09 GMT 1
thats it! But meaby is not necessary to get so close because the idea is to link to groups. Hey Quintaxel, as you know so much about script, why dont you make one?
|
|
|
Post by Quintaxel on Aug 25, 2015 7:49:10 GMT 1
I'm afraid I do not quite understand what you mean with 'link to groups'. Could you please explain this a bit more ?
|
|
bb
General
Blitzkrieg junkie (tried to quit several times).
Posts: 1,344
|
Post by bb on Aug 26, 2015 6:14:16 GMT 1
I'm afraid I do not quite understand what you mean with 'link to groups'. Could you please explain this a bit more ? I mean, the player begin with two diferent groups in diferent places of the maps, when the two groups encounter which other the player receive a reinforcement.
|
|
|
Post by Quintaxel on Aug 26, 2015 8:31:26 GMT 1
This is what the script does. You can have the 2 units with SciptId 200 and ScriptID 300 anywhere on the map. The moment they encounter each other, so if the distance between the units is less than 150 scriptpoints, then you will get the reinforcementgroup 300. I set the variable close to 150 scriptpoints but you can increase this value to so the units will not have to move so close to each other to get the reinforcements. You can test this in the demo map below. Demo map
|
|
|
Post by Quintaxel on Aug 26, 2015 18:41:38 GMT 1
Another wild idea.
What about programming a kind of a wheather forecast in BK? Imagine a function that gives a weather forecast for the next 15 or 30 minutes ? You could set the timeframe and the chance for bad weather. Maybe also the type of airplanes that are available or unavailable.
BK only knows 2 types of weather that influence the gameplay, clear or raining/snowing/desert storm and the type of weather is set in the Lua code. What I have in mind is that the player gets a forecast for bad weather in the coming timeframe. An extra weather type could be created thta disables only certain types of air support.
E.g "Forecast rain is 30%. This would mean that the change that the weather turns bad in the next timefame eg. a timeframe 20 minutes) is 30%. So the player would have to take this into account as the changes that he will have to do without airsupport are about 1 in 3.
Would this make sense ?
|
|
bb
General
Blitzkrieg junkie (tried to quit several times).
Posts: 1,344
|
Post by bb on Aug 29, 2015 6:26:41 GMT 1
hm, meaby I messed the stuff, but is not running in my map 
|
|
|
Post by Quintaxel on Aug 29, 2015 8:18:11 GMT 1
hm, meaby I messed the stuff, but is not running in my map  Do you mean not running in the demo map ornot running in the map you are making ?
|
|
bb
General
Blitzkrieg junkie (tried to quit several times).
Posts: 1,344
|
Post by bb on Aug 29, 2015 16:24:52 GMT 1
is not running in the map I'm making. 
|
|
|
Post by Quintaxel on Aug 29, 2015 17:30:18 GMT 1
Strange? If you send me the script then I can check it for you.
|
|
|
Post by Quintaxel on Sept 18, 2015 11:38:11 GMT 1
Here I go again I now have this idea for somekind of a road system in BK. The concept is that you create a couple of "drop points" on the map. You could then place units like a truck on these drop points and then call the unit from another point on the map. The unit will then move to the the other drop point but will stay on the road. The video below should make clear what I mean. This is only the proof of concept.
With a bit of Lua script a whole road system cold be build. Question is, is this idea any good ?
|
|
|
Post by Stanenberg on Sept 18, 2015 13:06:27 GMT 1
It is amazing! I always hated the AI driving over gardens and other details on the map. I always wanted a stay on the road function 
|
|
|
|
Post by feldgrau on Sept 18, 2015 17:44:07 GMT 1
Hallo..It is amazing! I always hated the AI driving over gardens and other details on the map. I always wanted a stay on the road function  It is possible that the wheeled vehicles "only" on the street can go. In Terrain / sets / 1 ... 4 / tileset.xml the AIClasses may have to be changed, I do not remember exactly what, but can Discover the back. I did this once done in Plain, Dark Grass, Dark Ground, Garden and Forest, I did not like. The Map was unplayable. I have then a new "Difficult Ground" terrain tile (and other stuff) is not made passable for wheeled vehicles. The "Difficult Ground" is for special areas eg. crossings, bridges, train-transitions etc. Just not as much, otherwise the "Spielerchen" is no longer fun.
---> drück
Here I go again... With a bit of Lua script a whole road system cold be build. Question is, is this idea any good ? For a very important convoy which this is a very good idea. Explore street and back up, call trucks brought, trucks traveling independently, brings something very important, drives away or something similar. But for a whole map the vehicles with wheels (or many) to be limited to the streets... and if something does not work ...
Which Screen Recording Software uses you?
mbkg Feldgrau
|
|
|
Post by Major Pain on Sept 18, 2015 19:53:16 GMT 1
Quin
Thanks for the demo.
I'm certain you are using the CMD/QCMD commands to accomplish this... which is exactly what they are designed to do, whether it is a truck on a road or a guard on patrol.
The process or function can be used several times in various (Different) places on map just by reading the coordinates from a look up table or array set up at the beginning of the script.
Your illustration was superb, even despite a few coordinates that could be adjusted slightly to make the truck movement a little smother. having said that, even with those little issues, I think most players will be more impressed with how the truck moves along the road and not pay attention to slight issues... these are not even errors.... it just needs a little correction in the coordinates.
Correct me if I am wrong but I think I'm seeing about 14 different coordinates.
----------Discussion--------------------------------------------------------
You can use an array or look up table for the coordinate values, rather than having to list all of them within each part of the script. Once defined, you can run the script forward or backward by changing a few [local] variables.
function move()
Cmd(0, ScriptID, x(a), y(a)) -- rem The first 0 means 'to move'. a = 1 right now to get the first set of coordinates.
-- You could add a loop here to read from a look up table or array. a = the coordinates number in the series; i.e. 1, 2, 3, 4, etc...
If a <= Coord {a, 0} do -- the last value that ends the move at destination. The total number of coordinates needed.
QCmd(0, ScriptID, Coord(a,0), Coord(a,1))
a=a+1 -- Increase the Coordinates number in the series. You could change this with a = a+(-1) as well to reverse the order.
end
return
The truck moves through the script from coordinate to coordinate until it reaches the destination.
The array setup would look something like this.
Coord = {14, 1} -- We are setting up the array coordinates for 14 sets of x and y. x = 0 // y = 1. -- Think of streets in a typical town. Each street has homes with mailboxes. -- Think of the first digit (14) as the mailboxes on a street. -- Think of the 2nd digit as each mailbox contents -- Each mailbox has two letters in it. -- The first letter is the x value in the coordinates, the second letter is the y value in the coordinates. -- So Coord (a, 0) = the x value // Coord (a, 1) = the y value. -- We'll set the number of coordinates in the first entree into the array (table). -- The first Coordinate will be Coord (1, 0) for x; and Coord (1, 1) for y. Coord = { 14, 0, -- The Number of coordinates in this series. So the 0 place in the series is the number of coordinates. 14 total. 500, 700, 500, 710, 510, 725, etc.... another 11 coordinates.
...... }
Discussion
Now if we need several different sets of coordinates to keep trucks and vehicles on roads, we can change the two-dimensional array to a three dimensional array.
You can think of this in terms of the earlier description as adding all of the streets in a town,
Coord {Number of street, number of mailbox on each street, number of letters in each mailbox}
Coord = { 10, 14, 1) -- This gives us 10 streets with 14 mailboxes on each street and two letters in each mailbox.
So the above can be used for 10 different coordinate situations.
Now we can create a powerful set of dynamic data sets, that a single function can run. You just have to enter a street number, and which mailbox to get the coordinates. The execution time is about 2 seconds faster for 10 values from a lookup and saves many lines of script. The Cmd/ Qcmd Function is stored in memory for the vehicle until it reaches its destination. The script does not wait to execute a coordinate before it continues in the script to the next one. So in theory, you could start several trucks or tanks one after the next one by changing the ScriptID, which also could be maintained in a Lookup table or array.
Or, you could use the Follow Command for the 2nd, 3rd and 4th, (etc...) vehicles since they will mimic exactly what the first vehicle does.
So in this way, the script is very powerful and many things can be exploited that have not been done before.
*******Back to the distance calculator for a second... look at this.....
-- ======================================================================================== -- Function CalculDistance(...) -- Calculate the distance between two points A & B on the map -- following the mathematical expression : distance = SQRT((Bx-Ax)² + (By-Ay)²) -- the coordinates can be given in VIS points or SCRIPT points -- Note : 1x1 VIS square is equal to 64x64 SCRIPT points -- Input parameters : -- the coordinates of point A and point B -- arg[1] x coordinate A -- arg[2] y coordinate A -- arg[3] x coordinate B -- arg[4] y coordinate B -- Output parameters : -- returns the distance between the points A & B -- Calling protocol : -- CalculDistance(Ax, Ay, Bx, By); -- function CalculDistance(...) return sqrt(((arg[3]-arg[1])*(arg[3]-arg[1])) + ((arg[4]-arg[2])*(arg[4]-arg[2]))); end;
-- ======================================================================================== -- Function sqrt() -- Calculate the square of the x value -- from the official map Secure_area.lua -- -- Input parameters : -- x integer value -- Output parameters : -- returns the square ofx -- Calling protocol : -- sqrt(x); -- function sqrt( x) local ITNUM = 4; local sp = 0 local i = ITNUM; local inv = 0; local a, b; if ( x <= 0) then return 0; end; if ( x < 1) then x = 1 / x; inv = 1; end; while ( x > 16) do sp = sp + 1; x = x / 16; end; a = 2;
-- Newtonian algorithm -- ------------------
while (i > 0) do b = x / a; a = a + b; a = a * 0.5; i = i - 1; end; -- while ( sp > 0) do sp = sp - 1; a = a * 4; end; if ( inv == 1) then a = 1 / a; end; return a; end; --------------------------------------------------------------------------------------------------
I hope this makes sense... Scripts are tough at times. Whenever we show a new type of function, it just makes the situation worse.
Quin, test what I posted and let's discuss creating some kind of book.
|
|