Jump to content
Sign in to follow this  
Whiplash

Passing parameters to script (BIS_fnc_holdActionAdd)

Recommended Posts

Hey.

 

Been trying to make a little teleport script by using the BIS_fnc_holdActionAdd.  Basically, I am adding the BIS_fnc_holdActionAdd to a object.  When executing this function, a script gets called that is supposed to teleport the player (the one calling the script by executing the BIS_fnc_holdActionAdd function) to another position.

 

Here is the script (very easy example):

 

This is the BIS_fnc_holdActionAdd function used to call the script:

[flag_mhq,
"teleport to the mhq",
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_takeOff1_ca.paa",
"\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_takeOff1_ca.paa",
"_this distance _target < 7",
"_caller distance _target < 7",
{},
{},
{[-2,{execVM "scripts\mhq_teleport.sqf";}] call CBA_fnc_globalExecute},  //execute teleport script!
{},
[],
5,
0,
false,
false] remoteExec ["BIS_fnc_holdActionAdd",0,flag_mhq];
And this is the script that gets called by the above function:

// If variable is true, then allow teleporting

if (var_mhq_enabled) then
{
    //Allow teleporting to MHQ position
    _caller = _this select 0;
 
    _caller setPos (getpos mhq_pos);
}
else
{
    // Exit script
    hint "MHQ not deployed!";
    if (true) exitWith{}
};
Executing the function works perfectly, so does executing the script.  However, since the script is called from within the function, the script does not recognize the "_this select 0" as the caller of the script.  Is there any way to pass on the original caller of the BIS_fnc_holdActionAdd  to the script?  I am apparently too dump to understand the BI wiki page about the BIS_fnc_holdActionAdd function.  Anyone able to guide me in the right direction?

Share this post


Link to post

Find out what it's passing if you don't know by replacing 

[-2,{execVM "scripts\mhq_teleport.sqf";}] call CBA_fnc_globalExecute

 with 

hint format["%1",_this];

Then once you've got that, pass it along in the globalExec using:
 

[-2,{_this execVM "scripts\mhq_teleport.sqf";},_this select whatever] call CBA_fnc_globalExecute;
Edited by TinfoilHate

Share this post


Link to post

Thanks for the quick reply.

 

Replacing the mentioned code snippet gave me no results.  When executing the "hint" command instead of the script it gave me no output at all.

 

The BI wiki page about the BIS_fnc_holdActionAdd function mentions arguments passed to the script section.  But regardless what I tried to pass ("_this select 1", "caller", "_caller", ...) always resulted in the same error.  This seems to be such a simple thing, yet I am unable to do it and feel totally clueless.

 

Got any more ideas up your sleeve? :)

Share this post


Link to post

https://cbateam.github.io/CBA_A3/docs/files/network/fnc_globalExecute-sqf.html

 

Function is deprecated, should probably use something else as it may be removed in the future.

 

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

 

The variables that are passed are mentioned in the parameters portion of the wiki page. For your code field (codeCompleted) they are: target, caller, ID, arguments with target being _this select 0.

 

Your teleport to MHQ script also does not need to be run globally as the only command that would require global effect already does so on it's own (setPos).

 

The arguments passed to script parameter is to pass additional arguments, look at example 2 for more detailed comments.

 

 

If you cannot get a hint to fire to tell your the contents of _this, you need to look at your conditions again as it is likely not firing.

Share this post


Link to post

Thanks, beta.

 

Turns out the CBA function was the problem why trying to pass on the parameter to my script didn't work.  Thought it is good practice using it, but turns out it caused the format I used to not work.  Now it seems to work just fine.  So simply replacing the CBA function with the execVM and passing the "caller" parameter along works flawlessly.

 

No idea why the hint command did not work, but since I can now relocate the player I am happy.

 

Thanks for your guys time!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...