OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: The-Architect on 22 Mar 2005, 22:55:26
-
Ok, here's the problem. I have a hunter script which will send enemy ai units after the player if you fire a non silenced weapon. I can get the script send the guys once a loud weapon has been fired but the problem arises when the player fires a silenced weapon and then a loud one after it. It seems like the script is finished after its decided the first shot is safe.
I'll post the script shortly.
-
Ok, I have a trigger which covers everything, when fired it calls "hunter.sqs".
Here's hunter.sqs,
me1 addeventhandler ["fired", {me1 exec "hunterkiller.sqs"}]
Here's the hunterkiller.sqs,
;Based on Baron Hurlothrumbo IIX's Hunterkiller Script.
;Edited by The-Architect.
#Begin
? _weapon = "NOR_BTR60_KPVT" : goto "Busted"
? _weapon = "NOR_BTR60_PKT" : goto "Busted"
? _weapon = "AK47" : goto "Busted"
? _weapon = "HK" : goto "Busted"
? _weapon = "SJB_TOS_M4" : goto "Busted"
? _weapon = "SJB_TOS_M4_M203" : goto "Busted"
? _weapon = "SJB_TOS_M249" : goto "Busted"
? _weapon = "SJB_TOS_M60E3" : goto "Busted"
? _weapon = "SJB_TOS_MK43" : goto "Busted"
? _weapon = "SJB_TOS_MK43_E4flash_hider" : goto "Busted"
? _weapon = "SJB_TOS_M21" : goto "Busted"
? _weapon = "SJB_TOS_M24" : goto "Busted"
? _weapon = "ak47cz" : goto "Busted"
? _weapon = "pk" : goto "Busted"
? _weapon = "kozlice" : goto "Busted"
? _weapon = "rpglauncher" : goto "Busted"
#Busted
me1 RemoveAllEventhandlers "fired"
~5
hintcadet "You have been detected."
ainf SetCombatmode "RED"
ainf SetBehaviour "COMBAT"
ainf SetSpeedMode "FULL"
#loop
"_x domove (getpos me1)" foreach units ainf
"_x doTarget me1" foreach units ainf
~60
;waits 60 seconds before updating- change time if you want but bear
;in mind if it updates too fast AI will be swamped with move commands
?alive me1: goto "loop"
;checks if the target is alive, if so goes looking for him, if not exits script.
#Exit
hint "not the right one"
exit
I don't know if you can make it out from that but what I want is the script to ignore silenced shots and to send ainf if a non silenced weapon is fired. That's why I listed all the loud weapons that appear in my mission.
As you can see I'm not too good at this and any help would be greatly appreciated.
-
I see you have an HK in that list.........isn't it a silenced weapon?
Where about have you defined the variable _weapon?
Planck
-
Is the TRIGGER set to Repeat?
-
Yep, I just noticed the HK. Will fix that.
I don't understand the bit about he variable _weapon. :-[
Yep, I tried setting the trigger to repeat.
Gawd 'elp me. :-\
-
Try putting _weapon = _this select 1 before those ? _weapon == blah blah checks...
The reason why the script is run completely everytime is that you don't have the variable _weapon defined anywhere so the script gets executed to the end...
Why it will not 'register' the second shot is because of this:
me1 RemoveAllEventhandlers "fired"This removes the eventhandler from the unit...
So the script will not be executed after the first shot as there is no eventHandler to do that...
Then, if you want the script to ignore silenced weapons you just put
? _weapon = "theSilencedWeaponsName": exit
among the other ? _weapon checks...
Of course do that to all the silenced weapons that might be used in the mission...
-
The problem is, when I use the eventhandler, every time I fire it calls the script. If I'm firing on fully automatic it'll call the script loads of times.
I still don't get the whole _weapon = _this stuff. Bear with me, I'm a dumbass when it comes to this stuff.
-
If you want to check for an equality you need == not =. The latter is used to assign values not check on values.
Why not use something like:
_noisyWeaponsInMission = ["NOR_BTR60_KPVT","NOR_BTR60_PKT" ,"AK47" ...]
if (_weapon in _noisyWeaponsInMission) then {goto"Busted"}
exit
#Busted
....
Having previously initialised _weapon as described above by HateR_Kint
EDIT:
Do you really have to use:
"_x domove (getpos me1)" foreach units ainf
It feels like cheating to me.
EDIT:
Also note the
exit
immediately before
#Busted
That is something else your script is missing
-
just to help you out here on the understanding bit
to execute a script, we use lines like
[] exec "scriptname.sqs"
this exec "scriptname.sqs"
[alpha, 3, 5] exec "scriptname.sqs"
basically an array is used to execute a script
[] = empty array
[alpha,3,5] = 3 elements in an array
this = (normally a unit) = a single element array
this first element in an array is seen as being in position 0
a fired event handler that executes a script is actually made up of a 5 element array
element 0 (referred to as _this select 0)
element 1 (referred to as _this select 1)
element 2 (referred to as _this select 2)
element 3 (referred to as _this select 3)
element 4 (referred to as _this select 4)
_this refers to the fired eventhandler array
FOR REFERENCE
The comref entry for fired eventhandlers is incorrect
here's what it actually returns
;;__________ fired eventhandler returns________
_Unit = _this select 0
_weapon = _this select 1
_muzzle = _this select 2
_mode = _this select 3
_ammo = _this select 4
[Unit, Weapon, Muzzle, Mode, Ammo] exec "myfiredeventhandlerscript.sqs"
Muzzle examples are:
M16muzzle
M16grenadelauncher
Mode examples are:
Auto
Single
Burst
-------------------------------------------------------------------------------------
hope that clarifies it a bit for ya
one thing to note, the variable name returned for _ammo, is the actual round fired, this is not always the same as the magazine name
-
Do you really have to use:
"_x domove (getpos me1)" foreach units ainf
It feels like cheating to me
True, when you hide in the bushes for a while, the ainf guys will stand on top of your head :)
Use something like this
#loop
_rad = 100
_newposx = getpos me1 select 0
_newposy = getpos me1 select 0
#newpos
   _newposx = (_mx + Random (2 * _rad) - _rad)
   _newposy = (_my + Random (2 * _rad) - _rad)
"_x domove [_newposx,_newposy]" foreach units ainf
~60
?alive me1 : goto "loop"
and Here (http://www.ofpec.com/editors/resource_view.php?id=543) you can find the best Eventhandler tutorial around. :)
-
I suggest you completely get rid of the detction routine in the script, and use the eventhandler instead ;)
eg.
unit addEventHandler ["FIRED",{if ("_this select 1 == _x" count ["GlockS","Bizon","HK","Uzi"] == 0) then {[] exec "Detected.sqs"}}]
-
Sui, i am not very good with if - then statements.
unit addEventHandler ["FIRED",{if ("_this select 1 == _x" count ["GlockS","Bizon","HK","Uzi"] == 0) then {[] exec "Detected.sqs"}}]
If the fired event handler was to trigger only when the unit fired his primary weapon, how would your line look then ??