|
Post by Quintaxel on Jan 25, 2020 18:10:51 GMT 1
This was the initial idea for putting the AskClient (x,y) function to use. The correction of the x,y coordinates is the problem. Both x and y have to be integers so if you divide x or y you will most likely will get a rational number. There's no function in BK Lua to lose the fractional part. In Lua you could do this using the function math.floor (x). BK Lua only includes a fraction of the Lua instructions. I could try to write a function to get the Integer part of a number but I doubt it would be worth the effort.
Then also note that the function ASkClient calls another function "SetCamera (x,y)". This is in fact a string. This means that you need to concatenate the x, and y function into a string. However, this no big deal
|
|
|
Post by feldgrau on Apr 4, 2020 19:21:00 GMT 1
Hi..., With this script it is possible that the script maker can make the V-1 disappear after the bombing. Film ---> not here anymore <--- the V-1 comes in the upper left corner and disappears after the bombing over the bridge. I still have to work on the "Effects / Particles / Sprites". Is it possible if the player selects the bomber in the game that the bomber (V-1) receives a ScripID after the start or is can be addressed in some other way?
|
|
|
Post by Quintaxel on Apr 5, 2020 12:05:54 GMT 1
Hi feldgrau , I do not think it's possible to assign any other iScriptID to the V1 then 999. The trick is to make the V1 disappear after the object is destroyed. So maybe you could check the status of the bridge first before removing the V1. Please look at the script below, maybe this is a solution. I have not tested it. ------ function V1_ex_999() if (GetNUnitsOfType("avia_super", 0) == 0) then DisplayTrace("nix"); Suicide() else if (GetNAmmo(999) < 1) + (GetNUnitsInScriptGroup(999) == 1) then DamageObject(800, 450); RunScript ("kill_V1", 200") -- 200 ms, you can play with the timing to get it right. --DeleteReinforcement(999); Suicide(); end; end; end; function Kill_V1 () if GetObjectHPs(800) < initial_hp then DeleteReinforcement(999); Suicide (); end; end;
----
Remark: You would have to set the variable <initial_hp> before the V1 hits the target. That could be done when the unit with iScriptID 999 is created.
|
|
|
Post by feldgrau on Apr 5, 2020 14:35:19 GMT 1
Hi feldgrau , I do not think it's possible to assign any other iScriptID to the V1 then 999. The trick is to make the V1 disappear after the object is destroyed. So maybe you could check the status of the bridge first before removing the V1. Please look at the script below, maybe this is a solution. I have not tested it. ------ function V1_ex_999() if (GetNUnitsOfType("avia_super", 0) == 0) then DisplayTrace("nix"); Suicide() else if (GetNAmmo(999) < 1) + (GetNUnitsInScriptGroup(999) == 1) then DamageObject(800, 450); RunScript ("kill_V1", 200") -- 200 ms, you can play with the timing to get it right. --DeleteReinforcement(999); Suicide(); end; end; end; function Kill_V1 () if GetObjectHPs(800) < initial_hp then DeleteReinforcement(999); Suicide (); end; end;
----
Remark: You would have to set the variable <initial_hp> before the V1 hits the target. That could be done when the unit with iScriptID 999 is created. HI Q, I almost thought that. Then there will probably only be the V-1 with: "go with the officers (your name) to point X then the bridge will be bombarded with V-1 rockets or go to point Y, then... or go to point Z... "etc. The V-1 is said to "explode" at the point where the V-1 was sent to, whether the target was hit or not. I try to do that with "Effects / Particles / Sprites". This is then inserted at <EffectGunFire></EffectGunFire> or at <EffectTrajectory>/EffectTrajectory>
|
|
|
Post by feldgrau on Apr 10, 2020 12:47:13 GMT 1
Hi..., With this script it is possible that the script maker can make the V-1 disappear after the bombing. Film ---> not here anymore <--- the V-1 comes in the upper left corner and disappears after the bombing over the bridge. I still have to work on the "Effects / Particles / Sprites". Is it possible if the player selects the bomber in the game that the bomber (V-1) receives a ScripID after the start or is can be addressed in some other way?
new movie ---> V-1<--- will be in "Heeresgruppe_additions003" Effects, Sprites etc.
|
|
|
Post by Kevin on Apr 10, 2020 13:08:19 GMT 1
Hi..., With this script it is possible that the script maker can make the V-1 disappear after the bombing. Film ---> not here anymore <--- the V-1 comes in the upper left corner and disappears after the bombing over the bridge. I still have to work on the "Effects / Particles / Sprites". Is it possible if the player selects the bomber in the game that the bomber (V-1) receives a ScripID after the start or is can be addressed in some other way?
new movie ---> V-1<--- will be in "Heeresgruppe_additions003" Effects, Sprites etc. That's so impressive, actually! I love those tricks in which we take the Enigma engine one step further by "fooling" the player. I am actually missing some of the sprites, as the V1 seems to disappear in some of the frames. Is that right?
|
|
|
Post by feldgrau on Apr 10, 2020 15:25:19 GMT 1
The sprites are all there. The sprites cannot be seen without "ViewZones". With several "appear points" it is a bit difficult to coordinate the V-1 (sprites) at the point where it is at the moment and the "view zones". If there are only one or two "appear points" this is not a big problem. Excerpt from the script
|
|
|
Post by Kevin on Apr 10, 2020 15:42:22 GMT 1
Very interesting, feldgrau. Thanks for sharing this with us. Did you use the 3D model to produce the 2D views?
|
|
|
Post by feldgrau on Apr 10, 2020 16:43:13 GMT 1
Pause on, F9, pause off, pause on, F9, pause off ... etc. ... etc. ... and when the time has finally come you're using a Humans-current.unt and fumble it all into the idle folder.
|
|
|
Post by Kevin on Apr 10, 2020 17:00:28 GMT 1
That makes your work more impressive then. Congratulations!!! I tried something similar for CSLA but I was not able to achieve a result good enough (I did not use the sprites though). Well, let's stick to the topic's theme: Lua scripting Thanks again, feldgrau
|
|
|
Post by Quintaxel on Apr 14, 2020 11:51:12 GMT 1
Hut ab vor dem, was Sie hier machen feldgrau . Impressive work !
|
|
|
Post by Quintaxel on Sept 28, 2020 20:21:18 GMT 1
I wrote a function to mange fuel consumption of units. This function makes it possible to limit the action radius of units by assigning a number of script points the unit can move. So a unit with, let's say 8000 fuel units, can move 8000 script points before it runs out of fuel and thus wont be able to move any further. So all that mappers/scripters need to do is add the arguments to the function and call the UnitFuelManagment (...) function.
eg. if you want to mange units below:
iScripId max Fuel capacity Fuel left
3001 15000 5000 3002 15000 10000 3003 10000 2500 3004 12000 8000 3005 12000 3000 then the function could be:
UnitFuelManagement (3001,15000,5000, 3002,15000,10000, 3003,10000,2500, 3004,12000,8000, 3005,12000,3000)
That's all you have to worry about, the function takes care of the rest.
The interval for calling the function should be relatively short. I use 1000 ms. I have tested the function with only 4 units so I have no idea how the function will cope with 10 or more units.
I tried to keep things as simple as possible and calculations to a minimum. Fuel consumption is a function of distance only. So the terrain the unit travels on is not taken in to consideration. However the calculation of the distance uses simple triogonemetry to calculate the travelled distance now which is more precise than in a previous version.
If a units travels on a road then it will use the same amount of fuel as if it were moving through muddy terrain. This is not realistic, I know. This could be changed in a later versions.
If you're interested then just copy the script below and put some unit on the map. (scripId 1010,1020,1030)
DisplayTrace ("UnitFuelManagement Rev. 1");
DisplayTrace ("Quintaxel 28-09-2020");
function Init()
RunScript ("Start",1000);
end;
function Start ()
UnitFuelManagement (1010,4000,3000, 1020,4000,2000, 1030,8000,3000);
end;
function UnitFuelManagement (...)
-- function UnitFuelManagement (...) Rev. 1
-- By Quintaxel 18-09-2020
-- Syntax FuelManagement (iScripId1,iMaxFuel1,iCurrentFuel1,iScripId2, iMaxFuel2,iCurrentFuel ,.., iScripIdn,iMaxFueln,iCurrentFueln);
-- Dependencies: Sqrt (x);
-- variables
local xs, ys; -- last known position of unit.
local xe, ye; -- Current position of unit.
local distance; -- travelled distance
local xmov, ymov; -- Movement of unit along the respective x,y axis.
local i; -- iteration
local x0,y0 -- initial position of unit.
local xpos, ypos; -- Variable name for x,y position of unit.
local str_fuel; -- variable fuel level of unit.
local fuel; --fuel level of unit.
-- Initialize values
if GetIGlobalVar ("init_fuel",0) == 0 then
i = 1;
--DisplayTrace ("Variables not set"); --Debug
while arg [i+1] ~= nil do
xpos = "x." ..arg[i];
ypos = "y." ..arg[i];
str_fuel = "fuel." ..arg[i];
x0,y0 = GetObjCoord (arg[i]);
SetIGlobalVar (xpos, x0);
SetIGlobalVar (ypos, y0);
SetIGlobalVar (str_fuel,arg[i+2]);
SetIGlobalVar ("init_fuel",1);
i = i+3;
end;
-- Calculate travelled distance
else
i = 1;
while arg [i+1] ~= nil do
if GetUnitState (arg[i]) ~= -1 then
xpos = "x." ..arg[i];
ypos = "y." ..arg[i];
str_fuel = "fuel." ..arg[i];
xs = GetIGlobalVar(xpos,0);
ys = GetIGlobalVar (ypos,0);
xe,ye = GetObjCoord (arg[i]);
xmov, ymov = xs-xe, ys-ye ;
SetIGlobalVar (xpos,xe);
SetIGlobalVar (ypos,ye);
distance = Sqrt (xmov*xmov + ymov*ymov);
fuel = GetIGlobalVar (str_fuel,0);
--DisplayTrace ("Fuel remaining %g is %g",arg[i], fuel);
if distance > 5 then
--DisplayTrace ("Distance of unit %g is %g ", arg[i], distance);
fuel = fuel - distance;
if fuel < 0 then
DisplayTrace ("Commander, unit %g is out of fuel!!", arg[i]);
SetIGlobalVar (str_fuel,0);
Cmd (9,arg[i]);
else
SetIGlobalVar (str_fuel,fuel);
end;
end;
end;
i = i+3;
end;
end;
end;
You will also need to add the function below to your script as it is called by the UnitFuelManagement function (...)
function Sqrt(x)
--function Sqrt()
--Calculates the square of the x value
--Input parameters: x integer value
--Output parameters: returns the square of x
--Calling protocol: sqrt(x);
-- 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 of x
-- Callingprotocol : 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;
|
|
|
Post by Quintaxel on Nov 15, 2020 23:41:34 GMT 1
Need some help here.
What is the script instruction to make an AI artillery unit fire at coordinates x, y on the map ?
I tried Cmd (15, iScriptID, x, y) to make a mortar fire at coordinates x,y but this does not seem to work.
|
|
|
Post by keepitsimple on Nov 16, 2020 17:37:19 GMT 1
Hi Quintaxel , Can it be that shot is out of range of the unit? I tried Cmd(15,10,GetScriptAreaParams("City")); it works for me.
|
|
|
Post by Quintaxel on Nov 16, 2020 17:42:32 GMT 1
Hi Quintaxel , Can it be that shot is out of range of the unit? I tried Cmd(15,10,GetScriptAreaParams("City")); it works for me. Hi keepitsimple, you are correct. The target was out of range. Now it works like a charm. Thanks for your reply.
|
|