Jump to content
Sign in to follow this  
ward1591

My POS check isn't checking the other condition?

Recommended Posts

Im not sure if the title is worded correctly but that how i worded. My problem with the script i wrote below is it only seems to check this part...

if {true} do
{
if (player distance pmcb1 < 4) exitWith {}; //PMC Base Building 1 
}

However, i need to it to also run these too incase someone is near pmcb2d1 & pmcb2d2....

if {true} do
{
if (player distance pmcb2d1 < 4) exitWith {}; //PMC Base Building 2 Door 1
}

if {true} do
{
if (player distance pmcb2d2 < 4) exitWith {}; //PMC Base Building 2 Door 2
}

Below is the entire script for POS check.

if {true} do
{
if (player distance pmcb1 < 4) exitWith {}; //PMC Base Building 1 
}

if {true} do
{
if (player distance pmcb2d1 < 4) exitWith {}; //PMC Base Building 2 Door 1
}

if {true} do
{
if (player distance pmcb2d2 < 4) exitWith {}; //PMC Base Building 2 Door 2
}

//PLAYER LOCATION LOCATION RESULTS

switch(true) do 
{
case (player distance pmcb1 < 4): //PMC Base Building 1 
{
	if (_uid in _getUID) then {((nearestobjects [pmcbuilding1, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true]; Sleep 2; hint "Locked";} else {Hint "You are not a PMC member!";};
};

case (player distance pmcb2d1 < 4): //PMC Base Building 2 Door 1
{
	if (_uid in _getUID) then {((nearestobjects [pmcbuilding2, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true]; Sleep 2; hint "Locked";} else {Hint "You are not a PMC member!";};
};

case (player distance pmcb2d2 < 4): //PMC Base Building 2 Door 2
{
	if (_uid in _getUID) then {((nearestobjects [pmcbuilding2, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_2',1,true]; Sleep 2; hint "Locked";} else {Hint "You are not a PMC member!";};
};
};

Or should i format the POS check like this?

while {true} do
{
if (player distance pmcb1 < 4) exitWith {}; //PMC Base Building 1 
if (player distance pmcb2d1 < 4) exitWith {}; //PMC Base Building 2 Door 1
if (player distance pmcb2d2 < 4) exitWith {}; //PMC Base Building 2 Door 2
}

IF ANYONE CAN HELP WITH THIS I WOULD APPRECIATE IT THANKS!

Edited by ward1591

Share this post


Link to post
Share on other sites

I'm not sure why you need the if {true} do lines (or if they are even proper scripting syntax) and then you could just have one if statement with || between the statements:

if (condition1 || condtion2 || condition3) then { };

Share this post


Link to post
Share on other sites
I'm not sure why you need the if {true} do lines (or if they are even proper scripting syntax) and then you could just have one if statement with || between the statements:

if (condition1 || condtion2 || condition3) then { };

So like this?

if (player distance pmcb1 < 4 || player distance pmcb2d1 < 4 || player distance pmcb2d2 < 4) exitwith{ };

Now i'm amateur at scripting as you pointed out with the bad syntax SORRY but would the above adjustment tie into my cases below it?

switch(true) do  
{ 
   case (player distance pmcb1 < 4): //PMC Base Building 1  
   { 
       if (_uid in _getUID) then {((nearestobjects [pmcbuilding1, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true]; Sleep 2; hint "Locked";} else {Hint "You are not a PMC member!";}; 
   }; 

   case (player distance pmcb2d1 < 4): //PMC Base Building 2 Door 1 
   { 
       if (_uid in _getUID) then {((nearestobjects [pmcbuilding2, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true]; Sleep 2; hint "Locked";} else {Hint "You are not a PMC member!";}; 
   }; 

   case (player distance pmcb2d2 < 4): //PMC Base Building 2 Door 2 
   { 
       if (_uid in _getUID) then {((nearestobjects [pmcbuilding2, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_2',1,true]; Sleep 2; hint "Locked";} else {Hint "You are not a PMC member!";}; 
   }; 
}; 

Share this post


Link to post
Share on other sites

Well depending on what your going for I don't really see the need for the if statement you could just go straight into the switch statement with something like:

_pos = position player;

switch (_pos) do {

case (_pos distance thing < 4): { stuff };
case (...): { };
case (...): { };

};

Edited by JShock

Share this post


Link to post
Share on other sites
Well depending on what your going for I don't really see the need for the if statement you could just go straight into the switch statement with something like:

_pos = position player;

switch (_pos) do {

case (_pos distance thing < 4): { stuff };
case (...): { };
case (...): { };

};

By doing what you said would that hinder me from doing UID check since i added in this UID string to make sure only they can activate that certain door Unlock/Lock...

_uid = getPlayerUID player;
PMCMembers = compileFinal str
[
"76561198060694901", // Scotsman
"76561198010318478", // Happy
"76561198064773232", // Louis
"76561197985268626" // Booth
];
_getUID = call PMCMembers;

Share this post


Link to post
Share on other sites
By doing what you said would that hinder me from doing UID check since i added in this UID string to make sure only they can activate that certain door Unlock/Lock...

_uid = getPlayerUID player;
PMCMembers = compileFinal str
[
   "76561198060694901", // Scotsman
   "76561198010318478", // Happy
   "76561198064773232", // Louis
   "76561197985268626" // Booth
];
_getUID = call PMCMembers;

I might have missed the conversation, but using "compileFinal str" in this context does not make sense as it would be the same as simply saying:

PMCMembers =
[ 
   "76561198060694901", // Scotsman 
   "76561198010318478", // Happy 
   "76561198064773232", // Louis 
   "76561197985268626" // Booth 
];

Share this post


Link to post
Share on other sites
I might have missed the conversation, but using "compileFinal str" in this context does not make sense as it would be the same as simply saying:

PMCMembers =
[ 
   "76561198060694901", // Scotsman 
   "76561198010318478", // Happy 
   "76561198064773232", // Louis 
   "76561197985268626" // Booth 
];

Oh okay i did not know that. Thanks walt!

Share this post


Link to post
Share on other sites

Actually sorry, no need for the position command, just make it player, or see if that helps. Because with a switch statement you input a variable to compare to a number of different conditions of that variable, I'm not sure if inputing a "true" into the switch will let it run properly.

Share this post


Link to post
Share on other sites
Actually sorry, no need for the position command, just make it player, or see if that helps. Because with a switch statement you input a variable to compare to a number of different conditions of that variable, I'm not sure if inputing a "true" into the switch will let it run properly.

Sorry i i understood switch _pos with player instead but after that you lost me.

This is what i did from what i understood

_pos = position player;

switch (_pos) do 
{
case (player distance pmcb1 < 4): 
{ 
	if (_uid in _getUID) then {((nearestobjects [pmcbuilding1, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true]; Sleep 2; hint "Locked";} else {Hint "You are not a PMC member!";}; 
};
case (player distance pmcb2d1 < 4): 
{ 
	if (_uid in _getUID) then {((nearestobjects [pmcbuilding2, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true]; Sleep 2; hint "Locked";} else {Hint "You are not a PMC member!";};
};
case (player distance pmcb2d2 < 4): 
{ 
	if (_uid in _getUID) then {((nearestobjects [pmcbuilding2, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_2',1,true]; Sleep 2; hint "Locked";} else {Hint "You are not a PMC member!";};
};
};

Share this post


Link to post
Share on other sites

First off, some hints and SQF basics, because you don't really seem to know what you're doing.

Go to ArmA 3 in your Steam account, right click it, go to "Properties" hit "Startup parameters" and add "-showScriptErrors" (with the dash, but without the quotes). That way, a big grey box will pop up whenever the compiler recognizes a script error and will tell you in which file and where it is.

Then, always end every statement with a semicolon! That includes "if () then {} else {};", "switch () do {};", "if () exitWith {};" as well. You simply left the semicolons at your if-statements as JShock already statet.

Be aware that certain variable names can be "magic variables" in certain cases, such as "player", "_this", "_uid", "_pos", "_alt" ... Try to avoid these variable names unless you explicitly want to use them in the respective case with their respective functionality.

A switch works that way: You pass the value to be checked into the brackets, like switch (true). In the cases, the case statement is then evaluated and the result will be compared with the value you passed into the switch ("true" in this case). So if you place "_pos" into the switch, but all your cases are boolean type (true/false) then of course you won't get any result because an array (_pos) is by definition incompatible (hence incomparable) with a boolean value.

Almost done...

And don't feel ashamed to use line breaks. There's no advantage in saving some lines for whatever reason but therefore being barely able to read the 300 character long line containing 4 statements.

And finally, if I get it right, this might be what you're looking for:

PMCMembers =
[
   "76561198060694901", // Scotsman 
   "76561198010318478", // Happy 
   "76561198064773232", // Louis 
   "76561197985268626" // Booth 
];

switch (true) do 
{
   case (player distance pmcb1 < 4): //PMC Base Building 1 
   {
       if ((getPlayerUID player) in PMCMembers) then
       {
           ((nearestObjects [pmcbuilding1, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true];
           sleep 2;
           hint "Locked";
       }
       else
       {
           hint "You are not a PMC member!";
       };
   };

   case (player distance pmcb2d1 < 4): //PMC Base Building 2 Door 1
   {
       if ((getPlayerUID player) in PMCMembers) then
       {
           ((nearestObjects [pmcbuilding2, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true];
           sleep 2;
           hint "Locked";
       }
       else
       {
           hint "You are not a PMC member!";
       };
   };

   case (player distance pmcb2d2 < 4): //PMC Base Building 2 Door 2
   {
       if ((getPlayerUID player)in PMCMembers) then
       {
           ((nearestObjects [pmcbuilding2, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_2',1,true];
           sleep 2;
           hint "Locked";
       }
       else
       {
           hint "You are not a PMC member!";
       };
   };
};

Kind regards,

Johnny

Edited by Heeeere's Johnny!
Corrected the nested if-statements

Share this post


Link to post
Share on other sites
First off, some hints and SQF basics, because you don't really seem to know what you're doing.

Go to ArmA 3 in your Steam account, right click it, go to "Properties" hit "Startup parameters" and add "-showScriptErrors" (with the dash, but without the quotes). That way, a big grey box will pop up whenever the compiler recognizes a script error and will tell you in which file and where it is.

Then, always end every statement with a semicolon! That includes "if () then {} else {};", "switch () do {};", "if () exitWith {};" as well. You simply left the semicolons at your if-statements as JShock already statet.

Be aware that certain variable names can be "magic variables" in certain cases, such as "player", "_uid", "_pos", "_alt" ... Try to avoid these variable names unless you explicitly want to use them in the respective case with their respective functionality.

A switch works that way: You pass the value to be checked into the brackets, like switch (true). In the cases, the case statement is then evaluated and the result will be compared with the value you passed into the switch ("true" in this case). So if you place "_pos" into the switch, but all your cases are boolean type (true/false) then of course you won't get any result because an array (_pos) is by definition incompatible (hence incomparable) with a boolean value.

Almost done...

And don't feel ashamed to use line breaks. There's no advantage in saving some lines for whatever reason but therefore being barely able to read the 300 character long line containing 4 statements.

And finally, if I get it right, this might be what you're looking for:

PMCMembers =
[
   "76561198060694901", // Scotsman 
   "76561198010318478", // Happy 
   "76561198064773232", // Louis 
   "76561197985268626" // Booth 
];

switch (true) do 
{
   case (player distance pmcb1 < 4): //PMC Base Building 1 
   {
       if ((getPlayerUID player) in PMCMembers) then
       {
           ((nearestObjects [pmcbuilding1, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true];
           sleep 2;
           hint "Locked";
       }
       else
       {
           hint "You are not a PMC member!";
       };
   };

   case (player distance pmcb2d1 < 4): //PMC Base Building 2 Door 1
   {
       if ((getPlayerUID player) in PMCMembers) then
       {
           ((nearestObjects [pmcbuilding2, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true];
           sleep 2;
           hint "Locked";
       }
       else
       {
           hint "You are not a PMC member!";
       };
   };

   case (player distance pmcb2d2 < 4): //PMC Base Building 2 Door 2
   {
       if ((getPlayerUID player)in PMCMembers) then
       {
           ((nearestObjects [pmcbuilding2, ["Land_Research_house_V1_F"], 5]) select 0) setVariable ['bis_disabled_Door_2',1,true];
           sleep 2;
           hint "Locked";
       }
       else
       {
           hint "You are not a PMC member!";
       };
   };
};

Kind regards,

Johnny aka waltenberg

I will give a try thanks again Walt and thanks JShock!

Share this post


Link to post
Share on other sites
I will give a try thanks again Walt and thanks JShock!

No problem, and sorry if I was a bit unclear, I was actually doing all that from my phone during class, so I was having to type it quickly without putting too much extra "fluff" in the response :p.

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  

×