Jump to content
Sign in to follow this  
Maximus-Sniper

Run two script when firing??

Recommended Posts

Hi all smile_o.gif

Well, now i'm working with my config file to my sniper pack smile_o.gif

And i have a problem sad_o.gif I like to run two script when i firing with my rifle. And i like to add this as:

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

class EventHandlers

{

fired = "if ((_this select 4) == ""AMMOM82APMag"" || (_this select 4) == ""AMMOM82ATMag"") then {_this call loadFile ""\myaddon\script\weaponFX\m82fx.sqf""};";

};

As you all can see i have added a effect smoke/fire when i firing, and it's works. But the problem is, i like to add a tracer to  rock.gif I want to use Wolfbane´s tracerfx script, so it is possible to make a another file who included \myaddon\script\weaponFX\m82fx.sqf and \wbe_tracerfx\wbe_tracerfx.sqs  ?

Thanks smile_o.gif

Share this post


Link to post
Share on other sites

Hi,

Might be better to set it up like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init="RAST_M82fx=loadFile ""\myaddon\script\weaponFX\m82fx.sqf""";

fired="if ((_this select 4) in [""AMMOM82APMag"",""AMMOM82ATMag""]) then {_this call RAST_M82fx}";

This way you only load the function once, rather than everytime a unit fires.

Quote[/b] ]so it is possible to make a another file who included \myaddon\script\weaponFX\m82fx.sqf and \wbe_tracerfx\wbe_tracerfx.sqs?

If you dont want to include any of Wolfbane´s tracerfx files, in your own addon. You could make two versions of your sniper, one with tracers and one without. You would have to add a required addons section to CFGPatches for the one with tracers.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init="RAST_M82fx=loadFile ""\myaddon\script\weaponFX\m82fx.sqf""";

fired="if ((_this select 4) in [""AMMOM82APMag"",""AMMOM82ATMag""]) then {_this call RAST_M82fx; _this Exec ""\wbe_tracerfx\wbe_tracerfx.sqs""}";

But you might just be able to use one version of your addon, and get your scripts to detect if Wolfbane´s tracerfx addon is installed, then act accordingly.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init="RAST_M82fx=loadFile ""\myaddon\script\weaponFX\m82fx.sqf""; RIST_DetectedWBETFX=_This call loadFile ""\myaddon\script\weaponFX\RIST_DetectWBETFX.sqf""";

fired="if ((_this select 4) in [""AMMOM82APMag"",""AMMOM82ATMag""]) then {_this call RAST_M82fx; If RIST_DetectedWBETFX Then {_this Exec ""\wbe_tracerfx\wbe_tracerfx.sqs""}}";

Ok so I did not include any code for RIST_DetectedWBETFX.sqf. If you wanted to go down that route, I would need more info.

Or you could just add everything into one addon with the permission of, and suitable credits to, Wolfbane.

Share this post


Link to post
Share on other sites
Might be better to set it up like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init="RAST_M82fx=loadFile ""\myaddon\script\weaponFX\m82fx.sqf""";

fired="if ((_this select 4) in [""AMMOM82APMag"",""AMMOM82ATMag""]) then {_this call RAST_M82fx}";

This way you only load the function once, rather than everytime a unit fires.

Only follow this advice if you're using TAGs (visit OFPEC) for your global variables though

Share this post


Link to post
Share on other sites

Hi UNN smile_o.gif

Thanks alot smile_o.gif It allmost work, hehe

Work fine with the ...\weaponFX\m82fx.sqf smoke/fire efect smile_o.gifsmile_o.gif

But when i add this:

fired="if ((_this select 4) in [""AMMOM82APMag"",""AMMOM82ATMag""]) then {_this call RAST_M82fx; _this Exec ""\wbe_tracerfx\wbe_tracerfx.sqs""}";

I got this error:

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

'((_tracerglow==2)&&|#|((Daytime >= 5)&&(Daytime < 18)))': Error Genric error in expression

And i read in the wbe_tracerfx's  readme.txt file and found this:

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

The simplest way to run this script is to put this line in the init field of the unit you want to fire tracers:

[unitname]exec "\wbe_tracerfx\wbe_tracerfx.sqs"

Maybe this one have to put in the init="RAST_M82fx=loadFile ""\myaddon\script\weaponFX\m82fx.sqf""";    after here i think  rock.gif  rock.gif

Share this post


Link to post
Share on other sites

Sorry, I don't have Wolfbane´s  scripts so I cant say for sure.

Quote[/b] ]'((_tracerglow==2)&&|#|((Daytime >= 5)&&(Daytime < 18)))': Error Genric error in expression

But _tracerglow==2 is a local variable defined in his scripts. So I would look at what is supposed to set _tracerglow to 2. As this is probably where its hitting the problem. Never used the Daytime command, so I can't say what would cause that to bomb out.

If wbe_tracerfx.sqs is not to big, post it here. Or perhaps a link to the script?

If you happy doing it the way I suggested then, yes get an OFPEC tag. Assuming you dont have one already.

Share this post


Link to post
Share on other sites

Hi UNN smile_o.gif

A link to the script here:

Wolfbane´s tracerfx script addon v 1.06

And i read more in his readme.txt file and found this:

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

Misc

You are free to use, modify or improve this addon in any way you like :) That includes adding it to your own addon in any way you like, modified or not. No crediting needed.

But i send him a PM anyway smile_o.gifsmile_o.gif

Here is the wbe_tracerfx.sqs:

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

; Get the list of parameters

_arglist = _this

; Number of parameters

_argnum = count _arglist

; Unit calling the script

_unit = _arglist select 0

;== Default values for the parameters ==

; Tracers toggle (1=on, 0=off, default set to on)

_tracers = 1

; Ricochet toggle (1=on,0=off, default set to on)

_ricochet = 1

; Glowing tracers toggle (2=auto, 1=on, 0=off, default set to auto)

_tracerglow = 2

; Color of the tracers and ricochet, "white","red","yellow", "green" or "side" (default is set to "side")

; The "side" color value will enable default colors of the tracers for weapons from different sides. West and resistance side

; weapons will have green tracers, east side weapons will have red tracers.

_tracercolor = "side"

; Number of rounds between each tracer (default is set to 2)

_numrounds = 2

; The size of the tracers (default is set to 0.2)

_tracersize = 0.2

; Speed modifier for the tracer, if you set it to say 4 the speed of the

; tracer will be 1/4 the speed of the actual bullet (default is 1, ie tracer speed is actual bullet speed)

_speedmod = 1

; == Save the parameters from the _arglist variable ==

; The default value will be used depending on

; the the number of parameters provided when calling the script

if (_argnum > 1) then { _tracers = _arglist select 1 }

if (_argnum > 2) then { _ricochet = _arglist select 2 }

if (_argnum > 3) then { _tracerglow = _arglist select 3 }  

if (_argnum > 4) then { _tracercolor = _arglist select 4 }

if (_argnum > 5) then { _numrounds = _arglist select 5 }

if (_argnum > 6) then { _tracersize = _arglist select 6 }

if (_argnum > 7) then { _speedmod = _arglist select 7 }

; If _tracerglow is set to auto (ie 2) select glowing (_tracerglow=1) or normal (_tracerglow=0)

; tracers depending on the time of the day. Thanks to nubbin77 and RED from the offical ofp forums for the

; suggestion and code to implement this

?((_tracerglow==2)&&(((Daytime >= 18) && (Daytime < 24))||((Daytime>=0) && (Daytime<5)))): _tracerglow = 1

?((_tracerglow==2)&&((Daytime >= 5)&&(Daytime < 18))): _tracerglow = 0

; == Init ==

; If WBE_TRACER_INIT is true skip init

?(WBE_TRACERFX_INIT) : goto "noinit"

WBE_TRACERFX_TRACER = loadfile "\wbe_tracerfx\scripts\wbe_tracerfx_tracer.sqf"

WBE_TRACERFX_FIRED_EH = loadfile "\wbe_tracerfx\scripts\wbe_tracerfx_fired.sqf"

WBE_TRACERFX_WEST_WPNS_ARRAY = []

WBE_TRACERFX_EAST_WPNS_ARRAY = []

WBE_TRACERFX_RES_WPNS_ARRAY = []

WBE_TRACERFX_UNIT_ARRAY = []

WBE_TRACERFX_INIT = true

#noinit

[]exec "\wbe_tracerfx\scripts\wbe_tracerfx_cleanup.sqs"

[_unit] call loadfile "\wbe_tracerfx\scripts\wbe_tracerfx_setup_wpns.sqf"

_unit addEventHandler ["fired",{_this call WBE_TRACERFX_FIRED_EH}]

_size = count WBE_TRACERFX_UNIT_ARRAY

? (_size <= 0) : goto "addunit"

_index = 0

#check

_arr = []

_arr = _arr + WBE_TRACERFX_UNIT_ARRAY select _index

?(_unit in _arr) : goto "updateunit"

_index = _index + 1

~0.1

?(_index < _size) : goto "check"

#addunit

WBE_TRACERFX_UNIT_ARRAY = WBE_TRACERFX_UNIT_ARRAY + [[_unit,_tracers,_ricochet,_numrounds,1,_tracersize,_tracercolor,_tracerglow,_speedmod]]

exit

#updateunit

WBE_TRACERFX_UNIT_ARRAY set[_index,[_unit,_tracers,_ricochet,_numrounds,1,_tracersize,_tracercolor,_tracerglow,_speedmod]]

exit

His script work fine if i add this into my man in the init....?rock.gif field:

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

[unitname]exec "\wbe_tracerfx\wbe_tracerfx.sqs"

Do you maybe have any idea how i can fix that to work in the class EventHandlers into my config.cpp??

Maybe add exec "\wbe_tracerfx\wbe_tracerfx.sqs" into

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

init="RAST_M82fx=loadFile ""\myaddon\script\weaponFX\m82fx.sqf""";

if that is possible?

Thanks again for helping smile_o.gif

Share this post


Link to post
Share on other sites
Quote[/b] ]Do you maybe have any idea how i can fix that to work in the class EventHandlers into my config.cpp?

I see, to add this to your own config event you would need to remove the following from wbe_tracerfx.sqs:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit addEventHandler ["fired",{_this call WBE_TRACERFX_FIRED_EH}]

It would work just as well without any changes, does it really matter if the fired event is added by your config or Wolfbanes script?

With Wolfbanes fired event added to your config, and his wbe_tracerfx.sqs modified, it would be this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init="RAST_M82fx=loadFile ""\myaddon\script\weaponFX\m82fx.sqf""; [_This Select 0] Exec ""\wbe_tracerfx\wbe_tracerfx.sqs""";

fired="if ((_this select 4) in [""AMMOM82APMag"",""AMMOM82ATMag""]) then {_this call RAST_M82fx; _this call WBE_TRACERFX_FIRED_EH}";

That will only add his traces when your weapons are fired.

But if you don't edit Wolfbanes scripts:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">init="RAST_M82fx=loadFile ""\myaddon\script\weaponFX\m82fx.sqf""; [_This Select 0] Exec ""\wbe_tracerfx\wbe_tracerfx.sqs""";

fired="if ((_this select 4) in [""AMMOM82APMag"",""AMMOM82ATMag""]) then {_this call RAST_M82fx}";

This will add his tracers to any weapon fired, including yours.

Share this post


Link to post
Share on other sites

Hi UNN biggrin_o.gif

It's works, you are the man, hehe smile_o.gifsmile_o.gifsmile_o.gif

i use this line:

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

init="RAST_M82fx=loadFile ""\myaddon\script\weaponFX\m82fx.sqf""; [_This Select 0] Exec ""\wbe_tracerfx\wbe_tracerfx.sqs""";

fired="if ((_this select 4) in [""AMMOM82APMag"",""AMMOM82ATMag""]) then {_this call RAST_M82fx}";

I'm gonna add your name into my addon when i'm sometime are finish with this pack. smile_o.gif

Thanks alot biggrin_o.gifbiggrin_o.gif

jiippi smile_o.gif

Share this post


Link to post
Share on other sites
Quote[/b] ]Thanks alot

Glad I could help smile_o.gif

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  

×