Jump to content
anfo

Restrict script to run for limited arma ID

Recommended Posts

Hi

 

I have a script called from init.sqf that starts with:

if (isServer) then {

I'd also like to add something along of the lines of

 if (player/arma id is [123456789, 987654321]) then {

I'm vainly hoping I can restrict the script's use to certain players rather than everybody. May I request syntax for what I am attempting to achieve?

Share this post


Link to post
Share on other sites
3 hours ago, anfo said:

if (isServer) then {

will only work if you are hosting then on dedicated server "player" makes no sense

  • Like 1

Share this post


Link to post
Share on other sites

in your initplayerLocal.sqf
 

private _uids = ["UID1","UID2"];  //list allowed player uids here eg. ["01234567"] OR ["0123456","0147896"]
if ((getPlayerUID player) in _uids)
then
{
	//your code here
};

 

  • Like 2

Share this post


Link to post
Share on other sites
3 hours ago, anfo said:

May I request syntax for what I am attempting to achieve

 

if (uid in ["7651234", "76514253"]) then { ... };

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On 10/22/2019 at 7:25 PM, Mr H. said:

in your initplayerLocal.sqf

 

@Mr H. Thank you, your option works.

 

@Dedmen

if (|#|uid in ["012346678945645"]) then {
[] ...'
Error undefined variable in expression: uid

It would also be fair to assume it could be a mistake I've made.

init.sqf:

if (uid in ["012346678945645"]) then {
[] execVM "scripts\fn_advancedSlingLoadingInit.sqf";
};

 

Share this post


Link to post
Share on other sites

nope @Dedmen used pseudo code to show you how it works but not actual code, no mistake on your end.

Share this post


Link to post
Share on other sites
1 hour ago, anfo said:

It would also be fair to assume it could be a mistake I've made.

Nah I just took you literally. You asked for syntax, I gave you a non-working sample with the correct syntax. You need to replace uid by the actual uid of whoever you want to check.
I guess maybe getPlayerUID (See wiki for reference)

Share this post


Link to post
Share on other sites
49 minutes ago, Dedmen said:

You need to replace uid by the actual uid of whoever you want to check.

 

I did use a correct UID (my own) in testing, that's how I found out Mr H.'s code worked. The UID I used above is noticeably fake, as presumably was the one used in your example.

Share this post


Link to post
Share on other sites
46 minutes ago, anfo said:

 

I did use a correct UID (my own) in testing, that's how I found out Mr H.'s code worked. The UID I used above is noticeably fake, as presumably was the one used in your example.

I meant the "uid" variable, not the uids in the arrays.

This:

firefox_2019-10-24_11-08-31.png

 

  • Thanks 1

Share this post


Link to post
Share on other sites
2 hours ago, Dedmen said:

I meant the "uid" variable, not the uids in the arrays.

 

I think I get it now, thanks. uid wasn't declared yet, like Mr H.'s example, or something to that effect? Regardless, any UID option involving running on a dedicated server doesn't work it seems. I think I'll just give up while I'm behind. 😕

Share this post


Link to post
Share on other sites
14 minutes ago, anfo said:

Regardless, any UID option involving running on a dedicated server doesn't work it seems.

player doesn't exist on server.

You need to find the players object and pass that.

As Mr H. already said.

On 10/22/2019 at 1:21 PM, Mr H. said:

will only work if you are hosting then on dedicated server "player" makes no sense

 

Maybe you could just explain to us what you are trying to do instead of just saying that things don't work for you.

Share this post


Link to post
Share on other sites
2 hours ago, Dedmen said:

Maybe you could just explain to us what you are trying to do instead of just saying that things don't work for you.

 

A script called sling loading has been developed by duda123 (hope I got that right), which is designed to run from init.sqf. Since every player has access to the feature from mission start, it has been observed that somebody will always deploy it without authorisation, or at the wrong time often damaging the helicopter in flight.

I had to bright idea of restricting its use to certain player UIDs, thereby preventing misuse. Hence my trip and stumble question to begin with.

 

I agree, starting the thread with something like this now makes more sense.

  • Like 1

Share this post


Link to post
Share on other sites
17 hours ago, anfo said:

which is designed to run from init.sqf

So why do you want to do server-side only stuff with isServer then? That doesn't seem to make any sense? Just get rid of the isServer part?

You need to run this clientside, and you are already running it clientside.

 

Only initialize duda's slingloading script, if the uid is in your list.

Share this post


Link to post
Share on other sites
On 10/25/2019 at 3:20 PM, Dedmen said:

So why do you want to do server-side only stuff with isServer then? That doesn't seem to make any sense?

 

I'm no longer using that understanding it was incorrectly included. However @Mr H. code, seemed to work in SP and MP, but on a dedi server unfortunately. This is the code if there is anything that jumps out:

private _uids = ["77777777777777777"];
if ((getPlayerUID player) in _uids)
then
{
	[] execVM "fn_advancedSlingLoadingInit.sqf";
};

 

Share this post


Link to post
Share on other sites

Player is not a valid variable on the server. Either run it client side or get the player object.

  • Like 1

Share this post


Link to post
Share on other sites
17 hours ago, Mr H. said:

Player is not a valid variable on the server. Either run it client side or get the player object.

 

Thank you for your insight and patience. So this applies even if loaded from initPlayerLocal?

 

17 hours ago, Mr H. said:

or get the player object.

 

Like?
 

waitUntil { !isNull player };

 

Share this post


Link to post
Share on other sites
19 hours ago, anfo said:

seemed to work in SP and MP, but on a dedi server unfortunately

Uh.

 

On 10/24/2019 at 1:53 PM, Dedmen said:
On 10/24/2019 at 1:37 PM, anfo said:

Regardless, any UID option involving running on a dedicated server doesn't work it seems.

player doesn't exist on server.

You need to find the players object and pass that.

As Mr H. already said.

On 10/22/2019 at 1:21 PM, Mr H. said:

will only work if you are hosting then on dedicated server "player" makes no sense

 

Maybe you could just explain to us what you are trying to do instead of just saying that things don't work for you.

 

 

 

1 hour ago, anfo said:

So this applies even if loaded from initPlayerLocal?

No. player is valid there as initPlayerLocal runs only on players machines.

 

1 hour ago, anfo said:

Like?

no thats not "getting" any object.

You can find the players object in the allPlayers array.

 

But as I already said (seems like I need to repeat lots of things here which were already said?) you need to run it clientside, and you are already doing so.

On 10/25/2019 at 9:20 AM, Dedmen said:

Only initialize duda's slingloading script, if the uid is in your list.

just run it clientside (like youre already doing) and put an if/then about the slingloading init script.

  • Like 1

Share this post


Link to post
Share on other sites
17 minutes ago, Dedmen said:

seems like I need to repeat lots of things here which were already said?

 

It appears I need to apologise for not immediately understanding the information presented in the time frame you expected. I promise to do better?

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

×