Jump to content
Sign in to follow this  
Jnr4817

AimSway Script

Recommended Posts

Arma Scripters,

 

Trying to debug this little script I am adding to our teams mission.

We use Ghost missions and this is a parameter within the mission.

 

I added in description.ext

class PARAM_AimSway
	{
	title = "Player Aiming Sway:";
	values[] = {100,0,1,2,3,4,5,6,7,8,9,10};
	texts[] = {"default","0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9","1.0"};
	default = 2;
	};

I added a initplayerlocal.sqf

if !("PARAM_AimSway" call BIS_fnc_getParamValue == 100) then {
	call fnc_ghst_aimsway;
	player addEventHandler ["Respawn", {call fnc_ghst_aimsway}];
};

fn_functions.sqf

//Aim Sway Mod
fnc_ghst_aimsway = {
	
	params ["_player","_coef"];
	
	_coef = ("PARAM_AimSway" call BIS_fnc_getParamValue) / 10;
	_player setCustomAimCoef _coef;
	_player setUnitRecoilCoefficient 0.2 + _coef;
	
};

I have made the latest changes and the script is working well.

 

Any other suggestions for optimizing, for my learning would be great.

 

Thanks for any help.

 

Reed

Share this post


Link to post
Share on other sites

could it be that the shown error message is not generated while running the shown version of your script sa_aimsway.sqf ???

 

the error message shows this:

private ["player","_coef"];

but in your script it is:

private ["_player","_coef"];

 

Share this post


Link to post
Share on other sites

In your fn_functions.sqf you are using "player" instead of "_player", which will most likely cause that error.

Share this post


Link to post
Share on other sites

Ok,

Changed everything to player and _player and get this error. Only when I pick the parameter of default value.

17:02:45 Error in expression <
private ["_player","_coef"];
_player = _this select 0;
_coef = ("PARAM_AimSway">
17:02:45   Error position: <_this select 0;
_coef = ("PARAM_AimSway">
17:02:45   Error Undefined variable in expression: _this
17:02:45 File C:\Users\Jason Reed\Documents\Arma 3 - Other Profiles\[SA]Reed\mpmissions\SATemplate_6%2e0%20Bravo.Tanoa\SA\scripts\sa_aimsway.sqf, line 5

THanks for looking

Share this post


Link to post
Share on other sites

Your error comes from using this in initPlayerLocal.sqf:

	player addEventHandler ["Respawn", {call fnc_ghst_aimsway}];

Should be this:

	player addEventHandler ["Respawn", {_this call fnc_ghst_aimsway}];

Also try using params instead of private and _this select n.

 

Cheers

Share this post


Link to post
Share on other sites

Also in init.sqf you are not passing anything to sa_aimsway.sqf

Overall you are mixing _player and player quite a lot, which doesn't look quite right.

 

Now that I think about it, in initPlayerLocal.sqf you call fnc_ghst_aimsway and addEventHandler, while in your sa_aimsway.sqf you do pretty much the same thing again.

Share this post


Link to post
Share on other sites

So, which is better, calling from the init or initplayerlocal?

 

It does seem , the same thing is happening twice.

 

I'm noob to scripting and trying the trouble shoot this is not easy, as I don't understand some of it.

 

Grumpy or Clayman,

if you were going to add iny our mission, how would you do it?

 

I have adjusted the code to reflect the latest change, which isn't much, still trying to figure out how to accomplish the param

 

still getting error

7:54:37 Error in expression <
private ["_player","_coef"];
_player = _this select 0;
_coef = ("PARAM_AimSway">
 7:54:37   Error position: <_this select 0;
_coef = ("PARAM_AimSway">
 7:54:37   Error Undefined variable in expression: _this
 7:54:37 File C:\Users\Jason Reed\Documents\Arma 3 - Other Profiles\[SA]Reed\mpmissions\SATemplate_6%2e0%20Bravo.Tanoa\SA\scripts\sa_aimsway.sqf, line 5

 

Humbly,

Reed

Share this post


Link to post
Share on other sites

Is this the way I should use the params for the function?

//Aim Sway Mod
fnc_ghst_aimsway = {
	
	params ["_player","_coef"];
	
	_coef = ("PARAM_AimSway" call BIS_fnc_getParamValue) / 10;
	_player setCustomAimCoef _coef;
	_player setUnitRecoilCoefficient 0.2 + _coef;
	
};

 

Share this post


Link to post
Share on other sites

I figured it out I think.

 

I changed the fn_function.sqf to the above post and deleted the sa_aimsway.sqf.

 

No more errors and it still mitigates sway.

 

Thanks,

Reed

Share this post


Link to post
Share on other sites

Is there any way I could optimize it anymore?

 

Share this post


Link to post
Share on other sites

I dont get the idea behind optimizing your script to get a 10th of a second less runtime. If I understood what you do then it is executed on respawn only and therefore it dont need agressive optimizing I think.

 

But one thing I do everytime I write a script is:

Store a value as variable if u need to calculate it (or return it by function) a second time.

 

You could do that with this

"PARAM_AimSway" call BIS_fnc_getParamValue;

because you do that all the time. You could store it in a global variable which you fill only on mission start.

 

Same thing is the dividing by 10. If you do that more than one time on a script run then store the result as a value (maybe local this time) and use this value for the second time you need ist.

Storing is (mostly) faster than calculating

Share this post


Link to post
Share on other sites
9 minutes ago, sarogahtyp said:

I dont get the idea behind optimizing your script to get a 10th of a second less runtime. If I understood what you do then it is executed on respawn only and therefore it dont need agressive optimizing I think.

 

But one thing I do everytime I write a script is:

Store a value as variable if u need to calculate it (or return it by function) a second time.

 

You could do that with this

"PARAM_AimSway" call BIS_fnc_getParamValue;

because you do that all the time. You could store it in a global variable which you fill only on mission start.

 

Same thing is the dividing by 10. If you do that more than one time on a script run then store the result as a value (maybe local this time) and use this value for the second time you need ist.

Storing is (mostly) faster than calculating

How would I do this? I am new to scripting, so I am trying to learn as I go.

Thank you for any links to the above suggestions, so I can learn.

Thanks for the help.

 

Reed

Share this post


Link to post
Share on other sites

https://community.bistudio.com/wiki/Code_Optimisation

 

In your initPlayerLocal.sqf:

GL_param_aimsway = "PARAM_AimSway" call BIS_fnc_getParamValue;

now you can substitute everywhere in your scripts this

"PARAM_AimSway" call BIS_fnc_getParamValue

whith that:

GL_param_aimsway

 

your function would look like this then:

 

//Aim Sway Mod
fnc_ghst_aimsway = {
	
	params ["_player","_coef"];
	
	_coef = GL_param_aimsway / 10;
	_player setCustomAimCoef _coef;
	_player setUnitRecoilCoefficient 0.2 + _coef;
	
};

 

Share this post


Link to post
Share on other sites

Yes sir,

Thank you for the teach. IS this how my initPlayerlocal>sqf will look?

 

 

if !("PARAM_AimSway" call BIS_fnc_getParamValue == 100) then {
	call fnc_ghst_aimsway;
	player addEventHandler ["Respawn", {_this call fnc_ghst_aimsway}];
};

GL_param_aimsway = "PARAM_AimSway" call BIS_fnc_getParamValue;

 

Reed

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  

×