-~1ncognito~- 0 Posted December 15, 2002 I only want it to be activated by a certain weapon. Could I have a code sample please? I wish someone would make a little event handler tutorial because event handlers are powerful tools in OFP, but they are hard to figure out on your own. Thanks for any replys Share this post Link to post Share on other sites
Doolittle 0 Posted December 15, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> Â Â "Fired" string:weapon,string:muzzle,string:mode,string:ammo <span id='postcolor'> You need to add the event to the object that does the firing, like so: _obj = player _obj addEventHandler ["fired", {_this exec "fired.sqs"}] fired.sqs </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">_objfiring = _this select 0 _weapon = _this select 1 _muzzle = _this select 2 _mode = _this select 3 _ammo = _this select 4 hint format ["%1", _this] <span id='postcolor'> If you want to see if a specific gun was fired, then you'd need to look at _weapon. This doesn't answer your question, but might help some. Doolittle Share this post Link to post Share on other sites
-~1ncognito~- 0 Posted December 15, 2002 Ok, so if I put: this addeventhandler ["Fired", {if (_this select 1 == theweapon) then {(_this select 0) do whatever}}] would that work? I'll go give it a try.. Share this post Link to post Share on other sites
-~1ncognito~- 0 Posted December 15, 2002 Yeah!!! It works!!! this is what i used: this addeventhandler ["Fired", {if ((_this select 1) == "weapon name") then {(_this select 0) do whatever}}] Good to know... Share this post Link to post Share on other sites
joltan 0 Posted January 31, 2003 Any idea why this doesn't work: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">if (name player != "Error: No Vehicle") then {player addEventHandler ["fired",{if ((_this select 1) == "sebprc25") then {[] exec "radio.sqs"}}];};<span id='postcolor'> It should start the script radio.sqs once the 'weapon' (the us radio from the nam pack) is 'fired'. But nothing happens... Share this post Link to post Share on other sites
InqWiper 0 Posted January 31, 2003 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">if (name player != "Error: No Vehicle") then {player addEventHandler ["fired",{if ((_this select 1) == "sebprc25") then {[] exec "radio.sqs"}}];};<span id='postcolor'> ...I dont think the name of the player is ever "Error: No Vehicle"... Try: ?alive player:player addEventHandler ["fired",{if ((_this select 1) == "sebprc25") then {[] exec "radio.sqs"}}]; I hope I got it right. Share this post Link to post Share on other sites
joltan 0 Posted January 31, 2003 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (InqWiper @ Jan. 31 2003,19:30)</td></tr><tr><td id="QUOTE">...I dont think the name of the player is ever "Error: No Vehicle"...<span id='postcolor'> Doh! (slaps forehead) It should have said 'not' - this prevents the eventhandler from being added on a dedicated server... Unfortunately that doesn't solve my problem - even putting just </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">this addEventHandler ["fired",{if ((_this select 1) == "sebprc25") then {[] exec "radio.sqs"}}]<span id='postcolor'> in the units init line doesn't solve it. I think the readio - while being a weapon and being able to be fired (you hear some static when hitting the fire button) doesn't activate the eventhandler. Share this post Link to post Share on other sites
PSC 0 Posted February 1, 2003 I know why this won't work with the radios. They don't have "ammo" and can't fire - the sound you hear is the "empty" sound. PSC Share this post Link to post Share on other sites
InqWiper 0 Posted February 1, 2003 Laser also doesnt trigger the eventhandler wich is even more strange. Share this post Link to post Share on other sites
joltan 0 Posted February 2, 2003 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (PSC @ Feb. 01 2003,20:48)</td></tr><tr><td id="QUOTE">I know why this won't work with the radios. They don't have "ammo" and can't fire - the sound you hear is the "empty" sound.<span id='postcolor'> Ok, that makes sense - but then there should be a way to 'load' them for firing, else how can to use them? 'hasweapon' works, but isn't quite as elegant as waiting for the user to select the weapon and actually 'fire' it. Share this post Link to post Share on other sites