OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Odin on 03 Nov 2008, 02:44:09

Title: Strange side effect using EH "HIT"
Post by: Odin on 03 Nov 2008, 02:44:09
G'day, I have just made a deployable MGnest for a mission I am making, it worked great but I wanted more so I added a few eventhandlers to make the MG near on indestructable, But I have a strange side effect resulting in once deployed and mounted, when Tanks fire the tank's shell explodes underneath themselves?? and I cant seem to fix it.

To make the Deployable MGnest I placed an Empty Marker and called it "MGnest"
I placed an empty MGnest/US and named it "nest" (It's class type is "WarfareBWestMGNest_M240"

in the init I gave the player an action,
Code: [Select]
deploy = player addAction ["Deploy MG nest", "mgnest.sqs"]
mgnest.sqs
Code: [Select]
_vehicle = _this select 0
_position = _this select 1
_unit = _this select 2

titleText ["Deploying MG nest...", "Plain Down"]
deleteMarker "MGnest"
deleteVehicle nest
~1
_markerObj = createMarker ["MGnest", position player]
_markerObj setMarkerShape "ICON"
"MGnest" setMarkerType "FLAG"
"MGnest" setMarkerText "MGnest Pos"
"MGnest" setMarkerColor "ColorGreen"
_d = direction player
player playmove "AinvPknlMstpSlayWrflDnon_AmovPercMstpSrasWrflDnon"
~2
nest = "WarfareBWestMGNest_M240" Createvehicle getMarkerPos "MGnest"
nest setDir _d;
~0.001
nest addEventHandler ["getin", {_this exec "nestOn.sqs"}];
nest addEventHandler ["getout",{_this exec "nestOff.sqs"}];
titleText ["MG nest deployed...", "Plain Down"]

The nestOn script is what I think is causing the side effect
nestOn.sqs
Code: [Select]
hint "start"
~1
_vehicle = _this select 0
_position = _this select 1
_unit = _this select 2
~0.001
?not (vehicle nest isKindOf "WarfareBWestMGNest_M240") and (_position == "Gunner"): exit
;?not (_position == "Gunner"): exit
~1
_unit setdamage -500; _unit addEventHandler ["HIT",{(_this select 0) setDamage (-500 * damage (_this select 0));}];
hint "you should be bulletproof"
~1
nest setdamage -500; nest addEventHandler ["HIT",{(_this select 0) setDamage (-500 * damage (_this select 0));}];
hint "Nest should be bulletproof"
exit

and the last script
nestOff.sqs
Code: [Select]
hint "loser get back here"
_vehicle = _this select 0
_position = _this select 1
_unit = _this select 2
~1
_unit removeEventHandler ["HIT", 0]
nest removeEventHandler ["HIT", 0]
_unit setdamage 0;
hint "you should be normal"

Anyone got any Ideas on what is happening?

Here is a small example mission

Cheers
Odin
Title: Re: Strange side effect using EH "HIT"
Post by: Luke on 03 Nov 2008, 03:04:30
What do you mean underneath themselves? 
The nest fires the shells?

Or does the shell explode underneath the nest when it is hit?
Or does the shell explode under the tank firing?
Or does the shell explode underneath the tank firing shells while manning the nest?  :P

What do you mean exactly, Odin?

Luke
Title: Re: Strange side effect using EH "HIT"
Post by: Odin on 03 Nov 2008, 03:09:03
No I mean the firing tank,  Tank fires at target and the fired shell explodes underneath the Tank that fired the shell.
Arty is unaffected, only tanks are affected. :dunno:

Here is a small example mission
Title: Re: Strange side effect using EH "HIT"
Post by: JasonO on 03 Nov 2008, 21:36:20
Sounds odd. I don't personally think this is a result of the script. Does it do it in any other missions? Maybe a mod or something is conflicting ?
Title: Re: Strange side effect using EH "HIT"
Post by: Odin on 04 Nov 2008, 05:30:11
G'day, I tried it in another mission, samething happens but a few rounds did actualy make it to the nest, The only addons I have is 6thsense editor upgrade, lowflys editor, RTE and the Curatalos_Afghanistan island. In the tests I have done it only starts after I or an AI get in the nest, before that all is normal ??? only seems to affect the T72 and M1A when they use the turret gun, their MG work.

Cheers
Odin
Title: Re: Strange side effect using EH "HIT"
Post by: Rommel92 on 19 Nov 2008, 21:58:24
Code: [Select]
deploy = player addAction ["Deploy MG nest", "mgnest.sqf"]
mgnest.sqf
Code: [Select]
_unit = _this select 1;
_idx = _this select 2;

titleText ["Deploying MG nest...", "Plain Down"];

sleep 1.0;

_markerObj = createMarker ["MGnest", position player];_markerObj setMarkerShape "ICON";
"MGnest" setMarkerType "FLAG";"MGnest" setMarkerText "MGnest Pos";"MGnest" setMarkerColor "ColorGreen";

_d = direction player;
player playmove "AinvPknlMstpSlayWrflDnon_AmovPercMstpSrasWrflDnon";
sleep 2.0;
nest = "WarfareBWestMGNest_M240" createVehicle getPos _unit;
nest setDir _d;

nest addEventHandler ["getIn", {_this execVM "nestOn.sqf"}];
titleText ["MG nest deployed...", "Plain Down"];

nestOn.sqf
Code: [Select]
sleep 2.0;

_vehicle = _this select 0;
_position = _this select 1;
_unit = _this select 2;

while {_unit in (crew nest)} do
{
_unit setdamage -50000;
nest setdamage -50000;
sleep 2.0;
};

_unit setDamage 0;
nest setDamage 0;

Should work, also should get rid-of any nasty bugs, and the constant adding/removal of EH, which is not good practice.
Title: Re: Strange side effect using EH "HIT"
Post by: Odin on 22 Nov 2008, 01:54:55
G'day, Thx for the script Rommel, It works great appart from the nest and gunner still can be Killed, so I may have to go back to the EH.
 I am only learning SQF now trying to break away from my SQS addiction so it is handy to see your script next to my SQS allowing me to understand SQF syntax better much appreciated :good:

Odin
Title: Re: Strange side effect using EH "HIT"
Post by: Ext3rmin4tor on 29 Nov 2008, 16:28:44
Learn it as fast as you can. SQF is great compared to SQS, it's like High level programming vs assembly code. Plus you can write functions with a returning value, so if you make a boolean function you can create complex conditions for triggers that can't  normally be put in the condition field.