Home   Help Search Login Register  

Author Topic: Artillery Script - Using the fired projectile  (Read 1627 times)

0 Members and 1 Guest are viewing this topic.

Offline ryankaplan

  • Members
  • *
  • yeah...
Artillery Script - Using the fired projectile
« on: 27 Jun 2008, 10:44:37 »
Hi, I have a map click artillery script created by a bavarian friend of mine, which is part of a bigger dialog system.
In the script, The script catches what type of shell is fired, gets a few values from the config and does a bit of maths to calculate the 'time of landing after firing' and then spawns a shell of the same type as the one fired over the target area. Here it is:
Code: [Select]
_u = _this select 0;
if(local _u && alive _u) then {
_b = false;
_var = (_u getVariable "esp_RADabusy");
call {if(IsNil "_var") then {_b = true} else {if(!_var) then {_b = true}};if(_b) then {_u setVariable ["esp_RADabusy",true]}};
if(_b) then {
_w = (weapons _u) select 0;
_m = _this select 1;
_r = _this select 2;
_p = _this select 3;
_a = getText(configFile >> "CfgMagazines" >> _m >> "ammo");
_s = getNumber(configFile >> "CfgMagazines" >> _m >> "initSpeed");
_s = _s / 2;
_rt = getNumber(configFile >> "CfgWeapons" >> _w >> "reloadTime");
_ind = _u addEventHandler ["fired","_s = nearestobject [_this select 0,_this select 4];_s setpos [0,0,0];(_this select 0) setVariable ['esp_RADafired',true];"];

for[{_i = 0},{_i < _r},{_i = _i + 1}] do {
_am = (_u ammo _w);
_tm = time;
_u setVariable ["esp_RADafired",false];
_u fire [_w,_w,_m];

waitUntil {_u getVariable "esp_RADafired" || !(alive _u) || ((_u ammo _w) <= 0) || ((_u ammo _w) > _am) || IsNull(gunner _u) || ((time - _tm) > (_rt * 2))};
if(!(alive _u) || ((_u ammo _w) <= 0) || ((_u ammo _w) > _am) || IsNull(gunner _u) || ((time - _tm) > (_rt * 2))) then {
_r = (_i + 1);
_i = _r;
};
};

_u removeEventHandler ["fired",_ind];
_u setVariable ["esp_RADabusy",false];

sleep ((_u distance _p) / _s);

for[{_i = 0},{_i < _r},{_i = _i + 1}] do {
_a createVehicle [(_p select 0) - (random 80) + (random 80),(_p select 1) - (random 80) + (random 80),200];
sleep _rt;
};
};
};

Now, as we can see the shell which lands at the target area is NOT the one that was fired by the howitzer itself.
What I would like to do is somehow have the shell which was fired by the howitzer to land at the target area. NOT through the use of complicated maths and flight paths but 'simply' setposing the same shell, while keeping all the functionality of the original script. which is way over my head.

Why do i want this: It is so that with the use of a configed howitzer addon with different shell types and eventhandlers, i can simulate round types such as ICM, Flares, Mines, etc.

How I envision the problem can possibly be solved:

-->get the fired shell, setpos is to 5000 height, somehow add it to an array.
-->do the same maths junk the script does about wait time etc
-->After the time is up, get the array, and setpos its contents over the mapclick area (_p) in a First in First Out Basis.

Now, i lack the scripting knowledge to do this, so i would be very greatful if someone could help me with this..
« Last Edit: 27 Jun 2008, 23:00:49 by ryankaplan »

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
Re: Artillery Script - Using the fired projectile
« Reply #1 on: 18 Jul 2008, 22:26:54 »
My scripting knowledge is a bit rusty, but every weapon has a muzzle. Using the fire event's muzzle (it's included in it's params) to get the weapon it was fired from, check for the object nearest to that muzzle this. This is how I've done it myself in the past, I'm not sure about the details again, you'll have to work them out yourself.  :yes:

(I'm a veteran for a reason ;) )
Get those missions out there you morons!