ProfTournesol 956 Posted April 20, 2013 Well, as i'm not satisfied with the vanilla explosion when a shell explodes, i'm trying to attach a script to the shell that create smokes and particles at the explosion location. So thanks to an eventhandler "fired" i'm monitoring the shell position until it explodes, and create some particles then. The script : ? !(local server): exit _u = _this select 0 _ca = _this select 2 _d1=0.001 _shell=nearestObject [_u,_ca] #loop1 _gp=getPos _shell ~_d1 ? (alive _shell): goto "loop1" _i = 0 _z = 3 _z2 = -3 #loop _z = _z - 0.2 _z2 = _z2 + 0.5 _w = 0 #loop2 _w = _w + 20 _XposF = (sin(_w) * _i)+ (_gp select 0) _YposF = (cos(_w) * _i)+ (_gp select 1) _XposB = (sin(_w) * (_i+1))+ (_gp select 0) _YposB = (cos(_w) * (_i+1))+ (_gp select 1) drop ["cl_basic", "", "Billboard", 1, 4, [_XposB,_YposB,(_gp select 2)+_z], [random 2, random 2, random 10], 1, 0.85, 1, 1, [4], [[0.1,0.1,0.1,0], [0.2,0.2,0.2,1], [0.4,0.4,0.4,0.6], [1,1,1,0]], [0,1,0], 5, 0.05, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+2], [0, 0, random 28], 1, 1.75, 1, 0.5, [4], [[0.31,0.31,0.31,0.6], [0.31,0.31,0.31,0.3]], [0,1,0], 5, 0.1, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+4], [0, 0, random 28], 1, 1.75, 1, 0.5, [4], [[0.31,0.31,0.31,0.6], [0.31,0.31,0.31,0.3]], [0,1,0], 5, 0.1, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+1], [0, 0, random 18], 1, 1.75, 1, 0.1, [3], [[0.41,0.29,0.21,0.6], [0.41,0.29,0.21,0.4]], [0,1,0], 5, 0.1, "", "", ""] drop ["halflight", "", "Billboard", 1, 0.8, [_XposF,_YposF, ((_gp select 2)+_z2)+2], [random 2, random 2, random 8], 0.5, 0.75, 1, 1, [4], [[1,1,0,1], [1,0.5,0,0.8], [1,1,0,0.3], [1,1,0,0.2], [1,1,0,0.1], [1,1,0,0]], [0,1,0], 5, 0.05, "", "", ""] ?(_w < 360):goto "loop2" _i = _i + 1 ?(_i < 5):goto "loop" exit The problem : The particles are created something like 10 meters BEFORE the explosion created by the game. That's not good for my nerves :rolleyes: Share this post Link to post Share on other sites
vektorboson 8 Posted April 20, 2013 You should change your loop to look like this: _gp=getpos _shell #loop1 ~_d1 ?alive _shell: _gp = getpos _shell; goto "loop1" Share this post Link to post Share on other sites
faguss 63 Posted April 20, 2013 (edited) When shell explodes two objects are created Explosion and Crater. Taking position from the first one results in a crash so I need to wait for it to disappear and then get position of the latter. Here's the code: ? !(local server): exit _u = _this select 0 [color="#008000"][b]_ca = _this select 4[/b][/color] _d1=0.001 _shell=nearestObject [_u,_ca] #loop1 _gp=getPos _shell ~_d1 ? (alive _shell): goto "loop1" [color="#008000"][b]_startTime = _time #WaitForCrater ~0.01 _nearObj = nearestObject _gp _type = typeOf _nearObj ? _type == "Crater" : _gp=getpos _nearObj; goto "EndWaiting" ? _time < _startTime+0.5 : goto "WaitForCrater" #EndWaitin[/b]g[/color] _i = 0 _z = 3 _z2 = -3 #loop _z = _z - 0.2 _z2 = _z2 + 0.5 _w = 0 #loop2 _w = _w + 20 _XposF = (sin(_w) * _i)+ (_gp select 0) _YposF = (cos(_w) * _i)+ (_gp select 1) _XposB = (sin(_w) * (_i+1))+ (_gp select 0) _YposB = (cos(_w) * (_i+1))+ (_gp select 1) drop ["cl_basic", "", "Billboard", 1, 4, [_XposB,_YposB,(_gp select 2)+_z], [random 2, random 2, random 10], 1, 0.85, 1, 1, [4], [[0.1,0.1,0.1,0], [0.2,0.2,0.2,1], [0.4,0.4,0.4,0.6], [1,1,1,0]], [0,1,0], 5, 0.05, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+2], [0, 0, random 28], 1, 1.75, 1, 0.5, [4], [[0.31,0.31,0.31,0.6], [0.31,0.31,0.31,0.3]], [0,1,0], 5, 0.1, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+4], [0, 0, random 28], 1, 1.75, 1, 0.5, [4], [[0.31,0.31,0.31,0.6], [0.31,0.31,0.31,0.3]], [0,1,0], 5, 0.1, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+1], [0, 0, random 18], 1, 1.75, 1, 0.1, [3], [[0.41,0.29,0.21,0.6], [0.41,0.29,0.21,0.4]], [0,1,0], 5, 0.1, "", "", ""] drop ["halflight", "", "Billboard", 1, 0.8, [_XposF,_YposF, ((_gp select 2)+_z2)+2], [random 2, random 2, random 8], 0.5, 0.75, 1, 1, [4], [[1,1,0,1], [1,0.5,0,0.8], [1,1,0,0.3], [1,1,0,0.2], [1,1,0,0.1], [1,1,0,0]], [0,1,0], 5, 0.05, "", "", ""] ?(_w < 360):goto "loop2" _i = _i + 1 ?(_i < 5):goto "loop" exit I've changed muzzle class to ammo class (line 4) to make it work for me. As for the particle effect itself in my opinion it does provide a punch. Edited April 21, 2013 by Faguss marked code green; smaller gif Share this post Link to post Share on other sites
ProfTournesol 956 Posted April 21, 2013 Hi, thanks both of you for the answer :) Unfortunately, the nearestobject loop doesn't solve the problem on a real map (with a lot of objects and units), though it's somehow better, and even better if i replace _nearObj = nearestObject _gp by _nearObj = nearestObject [_gp,"Crater"] and increase the nearestobject loop time. But very often the effect is still not created where the explosion occurs, and the big flaw is that it crashes my PC almost each time after a certain time (after 10 to 20 explosions). Do you know if someone ever tries to do the same so that i could have a look at it ? Share this post Link to post Share on other sites
faguss 63 Posted April 21, 2013 (edited) even better if I replace Forgot about that. So you could even omit the loop: ? !(local server): exit _u = _this select 0 _ca = _this select 4 _d1=0.001 _shell=nearestObject [_u,_ca] #loop1 _gp=getPos _shell ~_d1 ? (alive _shell): goto "loop1" [b][color="#008000"]~0.01 _nearObj = nearestObject [_gp,"Crater"] _type = typeOf _nearObj ? _type == "Crater" : _gp=getpos _nearObj[/color][/b] _i = 0 _z = 3 _z2 = -3 #loop _z = _z - 0.2 _z2 = _z2 + 0.5 _w = 0 #loop2 _w = _w + 20 _XposF = (sin(_w) * _i)+ (_gp select 0) _YposF = (cos(_w) * _i)+ (_gp select 1) _XposB = (sin(_w) * (_i+1))+ (_gp select 0) _YposB = (cos(_w) * (_i+1))+ (_gp select 1) drop ["cl_basic", "", "Billboard", 1, 4, [_XposB,_YposB,(_gp select 2)+_z], [random 2, random 2, random 10], 1, 0.85, 1, 1, [4], [[0.1,0.1,0.1,0], [0.2,0.2,0.2,1], [0.4,0.4,0.4,0.6], [1,1,1,0]], [0,1,0], 5, 0.05, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+2], [0, 0, random 28], 1, 1.75, 1, 0.5, [4], [[0.31,0.31,0.31,0.6], [0.31,0.31,0.31,0.3]], [0,1,0], 5, 0.1, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+4], [0, 0, random 28], 1, 1.75, 1, 0.5, [4], [[0.31,0.31,0.31,0.6], [0.31,0.31,0.31,0.3]], [0,1,0], 5, 0.1, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+1], [0, 0, random 18], 1, 1.75, 1, 0.1, [3], [[0.41,0.29,0.21,0.6], [0.41,0.29,0.21,0.4]], [0,1,0], 5, 0.1, "", "", ""] drop ["halflight", "", "Billboard", 1, 0.8, [_XposF,_YposF, ((_gp select 2)+_z2)+2], [random 2, random 2, random 8], 0.5, 0.75, 1, 1, [4], [[1,1,0,1], [1,0.5,0,0.8], [1,1,0,0.3], [1,1,0,0.2], [1,1,0,0.1], [1,1,0,0]], [0,1,0], 5, 0.05, "", "", ""] ?(_w < 360):goto "loop2" _i = _i + 1 ?(_i < 5):goto "loop" exit Haven't experienced crashes. The other way would be to calculate ballistics of a bullet but I have no idea how air friction works in OFP. Edited April 21, 2013 by Faguss full code example Share this post Link to post Share on other sites
ProfTournesol 956 Posted April 21, 2013 (edited) Yep, what works the best ATM is the following : ? !(local server): exit _u = _this select 0 _ca = _this select 2 _Dist = 0 _MaxSearchDist = 20 _shell=nearestObject [_u,_ca] #loop1 _gp=getPos _shell _Ang = (GetDir _shell) ~0.001 ? (alive _shell): goto "loop1" #FindTarget ~0.01 _TgtPos = [((_gp select 0) + ((sin _Ang) * _Dist)),((_gp select 1) + ((cos _Ang) * _Dist)),(_gp select 2)] _Tgt = NearestObject _TgtPos ? (typeof _Tgt == "Crater"):_gp=getpos _Tgt;goto "next" _Dist = _Dist + 1 ? _Dist > _MaxSearchDist:exit Goto "FindTarget" #next _i = 0 _z = 3 _z2 = -3 #loop _z = _z - 0.2 _z2 = _z2 + 0.5 _w = 0 #loop2 _w = _w + 20 _XposF = (sin(_w) * _i)+ (_gp select 0) _YposF = (cos(_w) * _i)+ (_gp select 1) _XposB = (sin(_w) * (_i+1))+ (_gp select 0) _YposB = (cos(_w) * (_i+1))+ (_gp select 1) drop ["cl_basic", "", "Billboard", 1, 4, [_XposB,_YposB,(_gp select 2)+_z], [random 2, random 2, random 10], 1, 0.85, 1, 1, [4], [[0.1,0.1,0.1,0], [0.2,0.2,0.2,1], [0.4,0.4,0.4,0.6], [1,1,1,0]], [0,1,0], 5, 0.05, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+2], [0, 0, random 28], 1, 1.75, 1, 0.5, [4], [[0.31,0.31,0.31,0.6], [0.31,0.31,0.31,0.3]], [0,1,0], 5, 0.1, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+4], [0, 0, random 28], 1, 1.75, 1, 0.5, [4], [[0.31,0.31,0.31,0.6], [0.31,0.31,0.31,0.3]], [0,1,0], 5, 0.1, "", "", ""] drop ["cl_water", "", "Billboard", 1, 8, [_XposF,_YposF, ((_gp select 2)+_z2)+1], [0, 0, random 18], 1, 1.75, 1, 0.1, [3], [[0.41,0.29,0.21,0.6], [0.41,0.29,0.21,0.4]], [0,1,0], 5, 0.1, "", "", ""] drop ["halflight", "", "Billboard", 1, 0.8, [_XposF,_YposF, ((_gp select 2)+_z2)+2], [random 2, random 2, random 8], 0.5, 0.75, 1, 1, [4], [[1,1,0,1], [1,0.5,0,0.8], [1,1,0,0.3], [1,1,0,0.2], [1,1,0,0.1], [1,1,0,0]], [0,1,0], 5, 0.05, "", "", ""] ?(_w < 360):goto "loop2" _i = _i + 1 ?(_i < 5):goto "loop" "_tgtpos" is following the trajectory of the former shell for 20 meters and the scripts looks every meter if there's a nearestobject of "crater" class (which doesn't crash, contrary to nearestobject [position,"crater"], which seems to crash sometimes). Weird. Not perfect though, sometimes the crater isn't found, so then i stick to the vanilla explosion. Edited April 21, 2013 by ProfTournesol Share this post Link to post Share on other sites
faguss 63 Posted April 21, 2013 I've edited my previous post. See code there. The point of my implementation is to apply correction if possible (aka crater was found). If not then it's going with the primary method (last known bullet position). You quit with: ? _Dist > _MaxSearchDist:exit By relying on only one way you're making it in my opinion less effective. Share this post Link to post Share on other sites
ProfTournesol 956 Posted April 22, 2013 Yes, you're right, with my script you've got the scripted explosion (most of the time...) or the vanilla explosion. It isn't that bad, creates some diversity. It's better than seeing the explosion scripted effect far from the real explosion. Thanks a lot for helping :) Share this post Link to post Share on other sites