OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Goullou on 21 Nov 2007, 06:58:05
-
Hi all,
I'm working on different things to similulate traps, tripwires by script.
To make the final explosion i use to create ammo projectiles found here on the viki http://community.bistudio.com/wiki/ArmA:_Weapons (http://community.bistudio.com/wiki/ArmA:_Weapons).
In order to simulate a claymore mine i'm trying to create a round of 700 bullets from the position of the mine.
I have a loop somewhere in my script which do that:
while {_n<700} do
{
_shrpnl = "B_9x19_Ball" createvehicle [position _visualobject select 0,position _visualobject select 1,0.30+(random 1)];//This to make a random height
_shrpnl setDir (((direction _visualobject)-30)+(round random 60));//this to make a random projection in a 60° angle
_n=_n+1;
//sleep 0.005;
};
This makes all the bullets going verticaly to the ground. Then i've tried to apply a vectordir to each bullet but nothing happened.
I loose my hair trying to handle those bullets. I need help !!
-
I am far from having any substantive knowledge on the topic but I believe you need to use the setVelocity (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=s#setVelocity) command in lieu of or in addition to setDir. I am not sure how to implement it in your script though.
-
You are quite right about setVelocity, since script created objects always start being stationary. Although just a stylistic thing, I've converted the loop to use for since that is more elegant in this situation:
_speed = 1200; // 1200 ms.
for "_n" from 1 to 700 do
{
_shrpnl = "B_9x19_Ball" createvehicle [position _visualobject select 0,position _visualobject select 1,0.30+(random 1)];//This to make a random height
_dir = (((direction _visualobject)-30)+(round random 60));//this to make a random projection in a 60° angle
_shrpnl setDir _dir;
_shrpnl setVelocity [(sin _dir) * _speed, (cos _dir) * _speed, 0];
};
I'm pretty sure that 700 projectiles at 1200ms is overkill in the game, even if it is realistic (based on what Wikipedia (http://en.wikipedia.org/wiki/M18A1_Claymore_Antipersonnel_Mine)lies tells us), and would be laggy on a low-end machine. This is due to both the use of lots of createVehicles and that every projectile would be tracked until it hit something. I think you could get away with a lot less fragments, since a one or two bullets will kill anybody; you don't need to shred them!
-
You need to change setDir by SetVectorDir and use also the Z component to create a reliable projection of the bullets. You may use a 60 degree horizontal arc and a 30 degree vertical arc. So, if you are just quite close to the Claymore when it detonates, you will have only your legs damaged, if not, you may suffer also direct hits in the head.
-
Thanks a lot Spooner, it's works. :good:
I'll stay with a simulation using only 200 bullets because more makes lag. I've changed the random horizontal projection to fixed distribution degree/degree. The only think i kept randomly is the height. I reduced the speed of the bullets because fast bullets are noisy and the total sound makes lag too. Anyway for the player there's no visual difference. Otherwise the original shrapnels are steel balls and not so efficient beyond 100m. Using M9 bullets at 1200m/s makes it always lethal beyond 500m.
You need to change setDir by SetVectorDir and use also the Z component to create a reliable projection of the bullets. You may use a 60 degree horizontal arc and a 30 degree vertical arc. So, if you are just quite close to the Claymore when it detonates, you will have only your legs damaged, if not, you may suffer also direct hits in the head.
Good idea but I don't really know how to set a right value to SetVectorDir and as i told above there's no visual difference for the player for that too.
You said "if you are just quite close to the Claymore...", in reality this mine is a true shit. When the mine explode you have 700 balls leaving forward in an angle of 60°, you have something around 350gr of C4 localy exploding and you have the rest of the bottom support and feeth (800gr) flying away backward. If you think you can survive "just quite close" of it ... :D
In my script i create a handgrenade to simultate the local explosion so if someone stays close he die.
Thanks to all for you help !
-
What Mandoble says makes a lot of sense, once I considered how claymores actually work, rather than just answering your direct question. The claymore blast pattern is +-30 degrees horizontally and 0 to 2.4 degrees vertically, based purely on the statement "The spherical steel balls are projected in a 60 degree fan-shaped pattern that is two meters high (6 ft, 8 in) and 50 meters (165 ft) wide at a range of 50 meters (165 ft)."@Wikipedia (http://en.wikipedia.org/wiki/M18A1_Claymore_Antipersonnel_Mine)). I know you weren't too bothered about the shape, but I thought that there could be situations where this could matter (for example, using vertical angles further diffuses the fragments making it much less deadly at longer ranges. Also, it means that people who are slightly elevated can be hit at the longer ranges). Maths might come in useful for someone else, even if you don't use it, so I thought I'd give it a go.
To correctly simulate the vertical as well as horizontal element of the blast pattern, use something like:
_speed = 320; // 320 ms, the same as subsonic ammo.
_pos = [position _visualobject select 0, position _visualobject select 1, 0.1];
_minDir = (direction _visualobject) - 30;
for "_n" from 1 to 200 do
{
_shrpnl = "B_9x19_Ball" createvehicle _pos;
_hAngle = _minDir + (random 60); // +-30 degrees from straight ahead
_vAngle = random 2.4; // 0 to 2.4 degrees up from hoizontal
_velocity = [(sin _hAngle) * (cos _vAngle) * _speed, (cos _hAngle) * (cos _vAngle) * _speed, (sin _vAngle) * _speed];
_shrpnl setVectorDir _velocity;
_shrpnl setVelocity _velocity;
};
(I also removed the rounding on the "random 60", since it isn't necessary, and took out some repeated calculations to speed up the loop).
I'm not sure that you necessarily have to set the vectorDir, since I don't think ArmA really cares about it for ammo flying at "invisible" speeds (and I'm pretty sure it doesn't update this during flight for normal weapon ammo). Removing the setVectorDir could, therefore, save a little extra bandwidth and CPU, though you might want to experiment with that.
EDIT: Changed the speed of the shrapnel to that of subsonic ammo.
-
Ok Spooner, that's working as well. May be the loop begins to be heavy for low end CPU. I can't know it, mine is fast.
Now there's another issue which is going to make it more complicated.
When the Claymore is placed standing on a flat area the explosion is correct and all shrapnels fly normaly. When on the side of a hill (anywhere having a ground angle) this makes the mine keep on working horizontaly. The good thing would be to change the axes orientation.
-
The best way to test something if you have a fast PC is to do it with more than you intend to use. Thus, if you can happily run with 1000 fragments, then a lower end PC should cope with 200 (you need to judge this by...guessing ;P). The thing is though, that creating and manipulating lots of global ammo objects could use a lot of bandwidth too, so you need to test it in MP if you intend to use it there as well as SP.
Oops! I hadn't considered slopes, but I go more daft the more I am made to think about maths! To sort this out, all we need to do is work out the angle the claymore is facing and then add the vertical spread onto that:
_speed = 320; // 320 ms, the same as subsonic ammo.
_pos = [position _visualobject select 0, position _visualobject select 1, 0.1];
_minDir = (direction _visualobject) - 30;
_claymoreVAngle = asin ((vectorDir _visualobject) select 2);
for "_n" from 1 to 200 do
{
_shrpnl = "B_9x19_Ball" createvehicle _pos;
_hAngle = _minDir + (random 60); // +-30 degrees from straight ahead
_vAngle = _claymoreVAngle + (random 2.4); // 0 to 2.4 degrees up from the direction that the claymore is facing.
_velocity = [(sin _hAngle) * (cos _vAngle) * _speed, (cos _hAngle) * (cos _vAngle) * _speed, (sin _vAngle) * _speed];
_shrpnl setVectorDir _velocity;
_shrpnl setVelocity _velocity;
};
-
Hi,
I like the idea of this script and tried Sponner's code form his last post in this topic in a sqf script called Claymore, but with no results at all, not even any errors!
Not sure if I'm missing something here, I've placed an object in the map (in this case a barrel for testing) and called it visualobject, I've then added a trigger to execute the script but nothing happens, Any idea what I'm doing wrong?
Regards,
Turk.
-
The code that I gave originally wasn't a full script, so try this:
// Create an appropriate small object in the editor and give it an appropriate facing (azimuth),
// naming it "claymore1".
// Add a ANY PRESENT ONCE trigger on the "dangerous" side with an OnAct
// (e.g. for 200 balls fired with 60 degrees horiztonal and 2.4 degrees vertical spread):
// [claymore1, 200, 60, 2.4] execVM "claymore.sqf";
private ["_claymore", "_height", "_pos", "_minDir", "_claymoreVAngle",
"_shrapnel", "_hAngle", "_vAngle", "_velocity"];
_claymore = _this select 0; // Object acting as claymore. The balls will shoot out of this.
_numBalls = _this select 1; // Number of balls to generate.
_horSpread = _this select 2; // Total angle of spread (_horSpread / 2 on each side of centre).
_vertSpread = _this select 3; // Total angle of spread up from horizontal.
_speed = 320; // 320 ms, the same as subsonic ammo.
_height = (((boundingBox _claymore) select 1) select 2) + 0.1;
_pos = _claymore modelToWorld [0, 0, _height];
_minDir = (direction _claymore) - (_horSpread / 2);
_claymoreVAngle = asin ((vectorDir _claymore) select 2);
for "_i" from 1 to _numBalls do
{
_shrapnel = "B_9x19_Ball" createVehicle _pos;
_hAngle = _minDir + (random _horSpread);
_vAngle = _claymoreVAngle + (random _vertSpread);
_velocity = [(sin _hAngle) * (cos _vAngle) * _speed, (cos _hAngle) * (cos _vAngle) * _speed, (sin _vAngle) * _speed];
_shrapnel setVelocity _velocity;
};
EDIT: Pingu has released a full claymore addon (http://www.flashpoint1985.com/cgi-bin/ikonboard311/ikonboard.cgi?act=ST&f=70&t=72048&) if you'd prefer to use that.
-
Hi,
Thanks for that Spooner its works a treat and looks great, I've reduced the the amount of bullets due to a short spike lag, which can be expected at 200, and changed the ammo type to B_762x54_Ball so you see green tracer, plus added explosion code to the script.
_bang = "G_40mm_HE" createVehicle _pos;
Again, Thanks for taking the time to do that for me, its much appreciated.
Turk
-
Yeah 200 balls is fine on my machine in SP, but probably not on other people's and definitely not on anyone's in MP ;P You could possibly reduce the lag by creating the balls over a few frames (at an altitude of 10,000 m so they don't bother anyone ;P) and then moving them to the explosion position. Probably more fiddling about than you need though, since I'm sure 50 (or even less) would be plenty in most circumstances anyway.
It is nice to put the claymore near a wall and watch all the balls hit in a big rectangle. Good for judging just how big the blast really is. Tracers is another way of making it more obvious; hadn't thought of that!
Ah yes, a little explosion would help make it look and sound a lot better. Not that I've seen a real one...but...
-
Can't wait to try this out! Any suggestions on wagt default object could be used to make it look good? Also what about the tripwire? Can a tiny tiny wire object be created. As well a wire to simulate radio detonation?
-
You can't create a wire object (without making your own 3d object, but if you want to go as far as using addons, just use Pingu's claymore!). The best you could probably do would be to create a line of particles, I suppose. The most appropriate vanilla ArmA object is probably the portable radio (class: "Radio"), based on its size and shape.
As well a wire to simulate radio detonation?
You don't need a wire for radio detonation. Were you asking about radio detonation? If so, you'd just need to give the player an action that ran "claymore.sqf", rather than using a trigger. If you were talking about having a wire from the player to the device, then you'd have an action, but only let it work when the player is within a certain distance to the claymore object. Again, the wire could be simulated with a row of particles.
-
Yeah I guess it would be pretty hardcore to simulate the Radio detonated claymore. Cause then you have to add an action to cover it up anyway, then make is so it acts like a wire attached to something (would be cool though) :dunno:
-
Hello,
I've played around with this code Sponner provided to make the required effect/s more customisable from within the game editor by making alterations to the trigger rather then altering the code within the script itself, this will allow me and others to use multiple triggers with variable effects using just the one script.
I've added the ability to the trigger to set the speed of the projectiles, the height at which the projectiles start at, the type of ammo used and whether to add an explosion at the point at which the projectiles start, I also wanted to add a True/False statement within the trigger itself for the explosion effect. So if true then create explosion effect at start of projectiles, or if false then ignore.
This is where I'm stuck, I've looked at other scripts to see how if statements works and although I get the general idea I have no clue how to get the script to recognize that there is, or should be, a true/false statement within the trigger itself.
Here's what I've altered so far, it all works fine except for the True/False bit which I have no idea how to go about it.
// Create an appropriate small object in the editor and give it an appropriate facing (azimuth),
// naming it "A-NameHere".
// Add a ANY PRESENT ONCE trigger on the "dangerous" side with an OnAct
//
// e.g. for 200 projectiles fired with 60 degrees horiztonal and 2.4 degrees vertical spread
// at a speed of 320ms using B_762x54_Ball ammo class name starting at a height of 10 meters
// above the object with an explsion effect (At start height of projectiles) "True/False" and
// Ammo class name of explosion effect "M_TOW_AT"
//
// Null = [A-NameHere, 200, 60, 2.4, 320, "B_762x54_Ball", 10, "True", "M_TOW_AT"] execVM "claymore.sqf";
private ["_claymore", "_height", "_pos", "_minDir", "_claymoreVAngle",
"_shrapnel", "_hAngle", "_vAngle", "_velocity"];
_claymore = _this select 0; // Object acting as claymore. The projectiles will shoot out of this.
_projectiles = _this select 1; // Number of projectiles to generate.
_horSpread = _this select 2; // Total angle of spread (_horSpread / 2 on each side of centre).
_vertSpread = _this select 3; // Total angle of spread up from horizontal.
_speed = _this select 4; // Speed of projectile.(e.g 320 ms, the same as subsonic ammo.)
_AmmoType = _this select 5; // Ammo class name.
_height = _this select 6; // Height of projectile from object.
_explosion = _this select 7; //To create an explosion at object TRUE/FALSE.
_explosionType = _this select 8; //Type of ammo class explosion effect.
_height = (((boundingBox _claymore) select 1) select 2)+ _height;
_pos = _claymore modelToWorld [0, 0, _height];
_minDir = (direction _claymore) - (_horSpread / 2);
_claymoreVAngle = asin ((vectorDir _claymore) select 2);
//==================================================
// Only want this part to play if line 22 is (true from the trigger) (_explosion = _this select 7;)
_bang = "Bomb" createVehicle _pos;
_bang setPos _pos;
_bang1 = _explosionType createVehicle _pos;
sleep 0.1;
deleteVehicle _bang1;
deletevehicle _bang;
//==================================================
// If line 22 is false then skip above code and play from here.
for "_i" from 1 to _projectiles do
{
_shrapnel = _AmmoType createVehicle _pos;
_hAngle = _minDir + (random _horSpread);
_vAngle = _claymoreVAngle + (random _vertSpread);
_velocity = [(sin _hAngle) * (cos _vAngle) * _speed, (cos _hAngle) * (cos _vAngle) * _speed, (sin _vAngle) * _speed];
_shrapnel setVelocity _velocity;
};
Regards,
Turk.
-
You don't need to delete something that is going to explode anyway. Not sure at all why you are creating a "bomb", which is a large unexploded round, since it won't automatically explode (though it is the only explosive that explodes on request when you "_bomb setDamage 1" it).
_explosionType = _this select 7; // Type of ammo class explosion effect; "" for no explosion effect.
...
if (_explosionType != "") then
{
_explosionType createVehicle _pos;
};
-
Thanks Spooner that did the trick, I must have tried everything except that :)
The scripts is working perfectly for me now, here's the finished product along with a demo mission to show some of the effects that can be created using this script.
Once again thanks.
Turk.
//==================================================================
// FireForEffect. V1.00b
//==================================================================
//
// Thanks to Spooner who practaly wrote this script for me,I just added a few more options
// to the trigger so it can be customsied to create many different effects from within
// the editor.
// ============
// Turk
//=============
// Description:
// This script started out as a Claymore effect, but now with the added customization to
// triggers within the editor you can create many different effects i.e Claymore/Airburst/Splash/
// Artie/Carpetbombing/Smoke/flares etc etc. The script is now called "FireForEffect.sqf"
// as the name is more appropriate... A demo map is included with this script.
//
// Create an appropriate small object in the editor and give it an appropriate facing (azimuth),
// naming it "A-NameHere".
//
// e.g. for 200 projectiles fired with 60 degrees horiztonal and 2.4 degrees vertical spread
// at a speed of 320ms using B_762x54_Ball ammo class name starting at a height of 1 meter
// above the object with an explsion effect "M_TOW_AT". /"" for no explosion effect
//
// Null = [A-NameHere, 200, 60, 2.4, 320, "B_762x54_Ball", 1, "M_TOW_AT"] execVM "FireForEffect.sqf";
//
//==================================================================
private ["_claymore", "_height", "_pos", "_minDir", "_claymoreVAngle",
"_shrapnel", "_hAngle", "_vAngle", "_velocity"];
//==================================================================
_claymore = _this select 0; // Object acting as claymore. The projectiles will shoot out of this.
_projectiles = _this select 1; // Number of projectiles to generate.
_horSpread = _this select 2; // Total angle of spread (_horSpread / 2 on each side of centre).
_vertSpread = _this select 3; // Total angle of spread up from horizontal.
_speed = _this select 4; // Speed of projectile.(e.g 320 ms, the same as subsonic ammo.)
_AmmoType = _this select 5; // Ammo class name.
_height = _this select 6; // Height of projectile from object.
_explosionType = _this select 7; //Type of ammo class explosion.
//==================================================================
_height = (((boundingBox _claymore) select 1) select 2)+ _height;
_pos = _claymore modelToWorld [0, 0, _height];
_minDir = (direction _claymore) - (_horSpread / 2);
_claymoreVAngle = asin ((vectorDir _claymore) select 2);
//==================================================================
if (_explosionType != "") then
{
_bang = "Bomb" createVehicle _pos;
_bang setPos _pos;
_bang1 = _explosionType createVehicle _pos;
sleep 0.1;
deleteVehicle _bang1;
deletevehicle _bang;
};
//==================================================================
for "_i" from 1 to _projectiles do
{
_shrapnel = _AmmoType createVehicle _pos;
_hAngle = _minDir + (random _horSpread);
_vAngle = _claymoreVAngle + (random _vertSpread);
_velocity = [(sin _hAngle) * (cos _vAngle) * _speed, (cos _hAngle) * (cos _vAngle) * _speed, (sin _vAngle) * _speed];
_shrapnel setVelocity _velocity;
};
-
I'll clarify what I said in my last post:
if (_explosionType != "") then
{
_bang = "Bomb" createVehicle _pos; // Creates an object that does nothing then is deleted after 0.1s.
_bang setPos _pos; // Moves an object that has no purpose.
_bang1 = _explosionType createVehicle _pos; // Creates the actual explosive.
sleep 0.1; // Sleeps for no reason.
deleteVehicle _bang1; // Don't need to delete an object that has already exploded by now.
deletevehicle _bang; // Don't need to delete an object that has no effect.
};
Should be just:
if (_explosionType != "") then
{
_explosionType createVehicle _pos;
};
Incidentally, you don't really need to repeat the code in its entirely in the post if you are attaching it anyway.
-
I don't get it Spooner! if I use this code...
if (_explosionType != "") then
{
_explosionType createVehicle _pos;
};
Then the object that's created for the explosion just falls to the ground then explodes, or if its missile type ammo then it just shoots off. Using this code...
if (_explosionType != "") then
{
_bang = "Bomb" createVehicle _pos;
_bang setPos _pos;
_bang1 = _explosionType createVehicle _pos;
sleep 0.1;
deleteVehicle _bang1;
deletevehicle _bang;
};
The object explodes where I want it to explode, so for an air burst I can have a "G_40mm_HE" or a "M_TOW_AT" explode 10 meters above the ground with 200 projectiles raining down on to its target. The only reason for _explosionType is to vary the effect a little. I did try the "bomb" setdamage 1 approach, but that explosion and sound didn't always suit the desired effect.
Regards,
Turk.
-
Sorry, I was a bit off there. In my version, I just want the claymore to go off near the ground (_pos was close enough to the ground that you don't notice the delay of dropping the explosive onto the ground). I thought you were creating the bomb object in order to set it off (but not doing so, so I couldn't understand why you'd made it). I had experimented a great deal with trying to collide objects in order to set off explosives when I was making SPON VBIED, but in the end, as Mandoble explained, setting damage on a bomb object is the only way to predictably get an explosion in the air.
Still, the method you use, by creating a bomb to "trigger" the explosive is a bit random, since sometimes the bomb will be destroyed by the explosive, producing a much larger explosion than intended (well, assuming the explosion you want is smaller than the bomb's explosion). If you have such a large explosion, the true claymore effect gets a bit lost, since unless you have a large number of projectiles, the effective range of the projectiles is not much more than the blast radius of the bomb. Perhaps you could try with a different collision object; one that doesn't explode when the explosive goes off?
-
Hi its me again :)
Never gave it a thought that the "Bomb" itself might go off on the odd occasion, so I needed to find something small enough as not to be noticed, but large enough to collide with the ammo type. In the end I found that the Radio with the modelToWorld command worked 100% of the time, well at least it did for me in testing so i'll settle with that.
So for anyone who's interested and has read this far and would like to use the script with some degree of reliability you should replace part of the code with this...
//==================================================================
if (_explosionType != "") then
{
_bang = "radio" createVehicle _pos;
_bang setPos _pos;
_bang1 = _explosionType createVehicle (_bang modelToWorld [0,0,0]);
sleep 0.1;
deleteVehicle _bang1;
deletevehicle _bang;
};
//==================================================================
Ok Spooner that's it, I promise not to bother you again on this topic, I'm sure by now you're sick and tired of this claymore thing :)
I'm somewhat reluctant to submit this script to the beta testing section in case someone asks an awkward question, I'm sure you've guessed by now my knowledge of scripting is copy/paste and mess.
Cheers.
Turk.