Jump to content
Sign in to follow this  
Messiah

Mine clearing

Recommended Posts

the following is a mine clearance script i was creating, the problem is the debugger line (which tells me the object type) just keeps throwing up 'NOID' and the script fails to blow up the mines...

any ideas?

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_vehicle = _this select 0

#mainloop

?(!alive _vehicle) : exit

?(!isengineon _vehicle) : goto "mainloop"

_vehiclepos = getpos _vehicle

_target = nearestobject _vehiclepos

?(_target == _vehicle) : goto "MainLoop"

?((_target distance _vehicle ) <= 4) : goto "object"

~.4

goto "mainloop"

#object

player globalchat format["%1", _target]

?("mine" counttype[_target] != 0): goto "mineclear"

?("mineE" counttype[_target] != 0): goto "mineclear"

?("car" counttype[_target] != 0): goto "mineclear"

goto "mainloop"

#mineclear

_targetpos = getpos _target

deletevehicle _target

_fakebomb = "grenade" camcreate [(_targetpos select 0), (_targetpos select 1), (_targetpos select 2)]

_ouch = getdammage _vehicle

_reheal = (_ouch +0.1)

_vehicle setdammage (_reheal)

goto "mainloop"

Im just practicing with a M113 to test the code, and then eventually i want mines to only blow up which are just in front of the vehicle, not all the way around.

Share this post


Link to post
Share on other sites

ok, i managed to get it semi working using the type of command to check for mines, but for some reason it will only remove the mine and create the grenade when the vehicle's sitting on top of it... which is fairly useless when its an M113, because it blows up

Share this post


Link to post
Share on other sites

Is this for a mine plow kinda thing?

If so, you probably would be better off to actually search the mines in front of the vehicle and not at the position of the vehicle wink_o.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_target = nearestobject [(_vehiclepos select 0)+2*sin(getDir _vehicle),(_vehiclepos select 1)+2*cos(getDir _vehicle),0]

That should search for the mines 2 meters in front of the vehicle (getPos _vehicle returns the center of the vehicle, not the edges of it..)...

Feel free to play with the distance..

It so happens that I was starting to work on a project of this sort for an AddOn maker but the project was buried before I could start.. whistle.gif

EDIT:

To get the mines only at the front of the vehicle blow up you probably need to cook up some relative positions checks to check where the mine is relative to the vehicle facing, with distance checks added to get them blow up when they should and not 50 meters in front of the vehicle.. Or sumtin'..

Share this post


Link to post
Share on other sites

yes, essentially it will become a sort of mine plow - nothing more than a pet project at the moment, and i was just looking into how well it could work.

will test your new code now, and see how it works. My main worry is how well the script will cope in a heaviy mined mine field... with lots of nearest objects to deal with, will it just go wrong?

Share this post


Link to post
Share on other sites
Quote[/b] ]with lots of nearest objects to deal with, will it just go wrong?

nearestObject will return only the nearest of the mines to the position you search them for..

So it's probably the rest of the script that needs to be fast enough in detecting the closest mine and detonating it so that it can get back to the scanning part..

You would probably be better off to break the script in to two different scripts, the other one doing the scanning (loop) and the other one doing the detonating (executed when a mine is found)..

Or something like that..

Share this post


Link to post
Share on other sites

sounds like an idea, i'll split it into two, once i make it work as one (if that makes sense)

ok, your code works wonders, but for some reason the script refuses to go and delete the mine and replace it with the grenade - i cant see anything wrong with my coding from where i'm looking?

Share this post


Link to post
Share on other sites

It's all about the distances..

Somehow the distances used in scripting seem to be outproprotioned when compared to the ingame models etc.. tounge2.gif

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehicle = _this select 0

#mainloop

~.2

?(!alive _vehicle) : exit

?(!isengineon _vehicle) : goto "mainloop"

_vehiclepos = position _vehicle

_vehicledir = direction _vehicle

_target = nearestobject [(_vehiclepos select 0)+15*sin(_vehicledir),(_vehiclepos select 1)+15*cos(_vehicledir),0]

?(_target == _vehicle) : goto "MainLoop"

? typeOf _target in ["Mine","MineE","Car"] && (_target distance _vehicle ) <= 12: goto "mineclear"

~.2

goto "mainloop"

#mineclear

_targetpos = position _target

deletevehicle _target

_fakebomb = "grenade" camcreate [(_targetpos select 0), (_targetpos select 1), (_targetpos select 2)]

_ouch = damage _vehicle

_reheal = (_ouch +0.1)

_vehicle setdamage (_reheal)

goto "mainloop"

Works fine if you drive slowly.. Drive too fast and you go bye-bye..

I did overdo the distances a bit but as OFP mines actually explode before the vehicle even touches them (sometimes) the distances need to be quite high... You can play around with them to get the results you would like..

Share this post


Link to post
Share on other sites

inlove.gif

legend as always mate biggrin_o.gif and the driving slow thing works perfectly as thats what you have to do in real life wink_o.gif

now to learn how to do particle drops etc so i can fake mud being pushed in front of the plough whistle.gif

Share this post


Link to post
Share on other sites

Aaand drop[] is where I shut down my 'doors' nener.gif

I completely suck in maths so therefore anything cool done with drop[] is out of my hands.. tounge2.gif

Share this post


Link to post
Share on other sites

dont worry, im determined to learn it myself tounge2.gif

one thing you may be able to help on, is would it be possible, say, for it to deploy route markers as it drives along?

basically the way the real thing works is shovel earth in front of it, sets off the mines, and then behind on either side it has automatic flag stick deployers that shoot a marker post into the ground either side of the vehicle. Possible?

For now i was thinking of just camcreating the red and white sticks which came with cwc (part of the barrier thing), but is it possible to make it essentially remember the point at which it started (so in the real addon, when the shovel is deployed) and avery 5m it travels from that point, it deploys two markers either side of rhe vehicle to mark a route of safe passage. Once the shovel is stowed, the markers stop.

sounds complicated though... confused_o.gif

Share this post


Link to post
Share on other sites
Quote[/b] ]basically the way the real thing works is shovel earth in front of it, sets off the mines, and then behind on either side it has automatic flag stick deployers that shoot a marker post into the ground either side of the vehicle. Possible?

Should be possible...

Don't see anything in this that wouldn't work, but of course you never know what odd problems you run into icon_rolleyes.gif

It can be a bit tricky but probably not as tricky as some other stuff wink_o.gif

Share this post


Link to post
Share on other sites

lol, yeah - just a case of trial and error i reckon getting them to be placed in the right... err... place tounge2.gif shall come back with my results

Share this post


Link to post
Share on other sites

hmmm, getting a little confused as to how to make the pole placer script check when the vehicle has moved 5m in any direction from the start location... confused_o.gif

Share this post


Link to post
Share on other sites

You need to store the initial position in a variable, then compare the vehicles position into that position and if the difference is 5 or more meters place another set of sticks..

Can't remember the exact way how it was done though..

Something like

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_origPos = position _vehicle

#looppy

_newPos = position _vehicle

? sqrt(((_origPos select 0)-(_newPos select 0))^2+((_origPos select 1)-(_newPos select 1))^2) >= 5: <place stick>

~.2

goto "looppy"

Or something like that..

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×