Jump to content

Recommended Posts

Hi,
I am currently trying to find a way to check if local player is function caller in sqf file.
I have civilian with addAction, which calls this script:

_caller = _this select 2;
if (local player == _caller) then {
	_handle = createdialog "Interaction";
}

I need to show the GUI only to player using the action.
Sorry if it's somewhere on these forums, but I was unable to find it.
Thanks for your answers 🙂
WendAF

Share this post


Link to post
Share on other sites

If the function is called locally (via the add action it's the case by default) you don't need to worry about it, the rest will only show locally too.

  • Like 1

Share this post


Link to post
Share on other sites

That's not my case. I have NPC with this addAction .... that launches small GUI. Unfortunately, the GUI is shown to all players, not the one who called it. I'm trying to solve that problem but having issues. Either the Interact action doesn't show up on dedicated server  or GUI shows to all players.
I have a suspicion that it shows it to everyone because GUI command is launched on server for everyone. (I'm beginner in scripting, so that assumption might be entirely wrong)

Share this post


Link to post
Share on other sites

That's possible yes, you should paste the whole code here if you want more help.

  • Like 1

Share this post


Link to post
Share on other sites

This is in init of the NPC

_entityName = "Alexander";
this setName _entityName;

_actionID = this addAction ["Interact", "script.sqf", _entityName, 5, true, true, "", "player distance this < 2"];

This is script.sqf

DialogOwner = _this select 3;
DialogOption = 1;
if (local player == _this select 2) then {
	_handle = createdialog "Interakce";
}

This is dialogManager.sqf

_DialogText = [DialogOwner, DialogOption] call compile preprocessFileLineNumbers "getText.sqf";

[ 
 [DialogOwner, _DialogText ,0] 
] spawn BIS_fnc_EXP_camp_playSubtitles;

getText.sqf is just a simple switch
variables DialogOwner and DialogOption are storled at initPlayerLocal.sqf
 

Share this post


Link to post
Share on other sites

" Local player " does not make sense.

 

"variables DialogOwner and DialogOption are storled at initPlayerLocal.sqf" does not make sense either since they are defined in your script.sqf

 

Nothing here explains the remote execution, can you also provide the getText.sqf ?
 

Share this post


Link to post
Share on other sites

I know now that local player returns boolean.
The DialogOwner and DialogOption are in intiPlayerLocal.sqf but are given new values in that script.
getText is just a simple switch:

params ["_speaker", "_option"];

_outputText = "";

switch (_speaker) do {
	case "Journalist": { 
		switch (_option) do {
			case 1: { 
				_outputText = "I am standing here";
			};
			case 2: { 
				_outputText = "Noting happened here";
			};
			case 3: { 
				_outputText = "I don't need help";
			};
			default { 
				_outputText = "Que?";
			};
		};
	};
	case "Alexander": { 
		switch (_option) do {
			case 1: { 
				_outputText = "I am curing that guy";
			};
			case 2: { 
				_outputText = "He got hit by shrapnel";
			};
			case 3: { 
				_outputText = "If you have some bandages to spare, that would be lovely";
			};
			default { 
				_outputText = "Que?";
			};
		};
	};
	case "Rebel": { 
		switch (_option) do {
			case 1: { 
				_outputText = "Fighting for the motherland";
			};
			case 2: { 
				_outputText = "Nothing";
			};
			case 3: { 
				_outputText = "Come help fight with us";
			};
			default { 
				_outputText = "Que?";
			};
		};
	};
	default { 
		_outputText = "... Silence ...";
	};
};

I can upload the mission somewhere, if you want to check the whole thing. There's also framework, but that shouldn't influence the script in any way.

Share this post


Link to post
Share on other sites

Maybe in the event handlers of the ui itself? I don't see anything here that would explain the global MP execution.

Share this post


Link to post
Share on other sites
On 2/23/2019 at 5:55 PM, wendaf said:

I am currently trying to find a way to check if local player is function caller in sqf file.

Easy. Answer is: "true".

Scripts are always executed locally, and if there is a player, then it's executed on that players machine.

 

On 2/23/2019 at 6:44 PM, wendaf said:

Unfortunately, the GUI is shown to all players

Then you are remoteExecuting something somewhere.

 

On 2/23/2019 at 6:44 PM, wendaf said:

I have a suspicion that it shows it to everyone because GUI command is launched on server for everyone.

no.

On 2/23/2019 at 9:12 PM, wendaf said:

if (local player == _this select 2) then {

Doesn't make sense, player is always local, meaning local will return true. And you cannot compare a boolean using == so this is a script error.

On 2/23/2019 at 9:12 PM, wendaf said:

"player distance this < 2"

What? Why not just use the radius parameter of addAction?

 

 

Can't find any cause for remoteExecution in your mission. But considering your script that shows the dialog is broken and shouldn't work at all, I wonder why it even opens a dialog.

  • Like 2

Share this post


Link to post
Share on other sites

I have absolutely no clue, what is wrong and what is causing the execution

Share this post


Link to post
Share on other sites
_actionID = this addAction ["Interact", "script.sqf", [_entityName,player], 5, true, true, "", "player distance this < 2"];

and in your script.sqf

params ["_dialogowner","_caller"];
if (player != _caller) exitWith {};
DialogOwner = _dialogowner;
DialogOption = 1;

	_handle = createdialog "Interakce";

should solve your issue, but is messy and unnecessary, you should rework your script from the start.

Share this post


Link to post
Share on other sites

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

This returns BOOL so why check it against an OBJECT? As Dedmen said.

player addAction ["Open Interaction Menu",
{
	createDialog "Interaction";
}];

No need for local as explained by Dedmen above. This should create dialog for only the person not everyone.

Share this post


Link to post
Share on other sites

None of it works but thanks anyway

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

×