Jump to content
Sign in to follow this  
Radioactive

waitUntil Distance <=10 question

Recommended Posts

I have a question regarding an issue I'm having with my distance script:

while {true} do
{
waituntil {((player distance a1) <= 10);};
a1 say3d "sound";;

Basically, when the player gets within 10 meters of an AI named a1, I want him to play a dialogue named "sound". This distance script is in init.sqf as

execVM “distance.sqfâ€;

.

It doesn't work when I walk within 10 meters of the AI, and I can't seem to figure out why.

Also I have a question about the object name "player", as this will be a multiplayer mission. Will this object name work for all players or will it only work if the host player activates the distance <= 10? If so do I need to set the object as an array of names of the playable units?

Any insight would be very appreciated. Thank you.

Share this post


Link to post
Share on other sites

Firstly, no need to put your waitUntil in a while loop, as waitUntil is already a loop.

Secondly, you have a syntax error in your waitUntil (you don't need a ";" after the condition).

Thirdly, you have a double ";" at the end of your play sound line.

Fourthly, as long as this script is run locally to each player (I recommend putting it in the initPlayerLocal.sqf), you shouldn't have any issues using the player element in the script.

waitUntil {((player distance a1) <= 10)};
a1 say3d "sound";

Share this post


Link to post
Share on other sites

Oh dear those syntax errors are humbling, thanks a bunch JShock :)

Edit: Still not working...I'll keep trying to figure it out

Edited by Radioactive

Share this post


Link to post
Share on other sites
Edit: Still not working...I'll keep trying to figure it out

Possible derp moment my side, try this (FYI never code late on a Sunday night :p):

[] spawn {waitUntil {(player distance a1) < 10}; a1 say3d "sound";};

EDIT1: Actually, there has to be something else wrong with your code, my code needed to be spawned due to the fact I was running it in the debug console, and wasn't thinking, reference EDIT2 and then post #6 in this thread for a clarifying question.

EDIT2:

Oh, and just to help us help you better, try adding -showScriptErrors to your startup parameters for Steam, it will display any script errors (obviously :p).

And, to be sure, you moved this script call into the initPlayerLocal.sqf, yes?

Edited by JShock

Share this post


Link to post
Share on other sites
You never closed your while loop. You have the required semicolon, but no closing bracket.

Well, using the while loop is determinant on whether or not he wants the sound played everytime the player is within that distance or he just wants the sound played once after the player gets within 10 meters, but if the first case is true, then the below code should work:

while {true} do
{
waitUntil {(player distance a1) < 10};
a1 say3D "sound";
};

Share this post


Link to post
Share on other sites
the below code should work:

while {true} do
{
waitUntil {(player distance a1) < 10};
a1 say3D "sound";
};

As soon as player closer than 10m to a1, say3D will be executed hundreds times per frame....endlessly.

Share this post


Link to post
Share on other sites

Got this from the rpt file.

"3:37:54 Error in expression <ssions\soundtest.Altis\init.sqf"

execVM “distance.sqfâ€;>

3:37:54 Error position: <“distance.sqfâ€;>

3:37:54 Error Invalid number in expression"

Apparently my init file is wrong...

execVM “distance.sqfâ€;

This is wrong? I looked...way too closely to see if I misspelled distance or any other syntax error and I can't find a thing...

Edit: Same thing with InitPlayerLocal as well, doesn't make a difference.

Share this post


Link to post
Share on other sites

how about just attaching a trigger to the desired unit and play sound on act..

Much simpler and less problems come with it.

Share this post


Link to post
Share on other sites

You could also trigger the sound with an addaction-condition. Not sure what sound ur playing and if it makes sense in your case, but it automatically happens only when you get close enough and look at the target.

So this for example would be a good and easy script to make a unit play some sound once, when you first meet him.

this setVariable["greetings", this addAction [ "", '', "", -5, false, false, "",
'
	_target say3D "sound";
	_target removeAction (_target getVariable "greetings");
'
];

It's only triggered locally, unless you use it in combination with bis_fnc_mp.

If you don't care if the player looks at the unit or not, then I agree with Lappihuan – a simple trigger would totally suffice for that.

Share this post


Link to post
Share on other sites
Got this from the rpt file.

"3:37:54 Error in expression <ssions\soundtest.Altis\init.sqf"

execVM “distance.sqfâ€;>

3:37:54 Error position: <“distance.sqfâ€;>

3:37:54 Error Invalid number in expression"

Apparently my init file is wrong...

execVM “distance.sqfâ€;

This is wrong? I looked...way too closely to see if I misspelled distance or any other syntax error and I can't find a thing...

Edit: Same thing with InitPlayerLocal as well, doesn't make a difference.

You are using wrong quotes “ instead of " or '. Just use single to make sure: execVM 'distance.sqf';

Edited by Killzone_Kid

Share this post


Link to post
Share on other sites
As soon as player closer than 10m to a1, say3D will be executed hundreds times per frame....endlessly.

Endlessly while the player is within 10m of a1, I didn't understand why he needed the while loop in the first place, that's why I just had the waitUntil, but seeing how the main issue is in the RPT as an execution problem. And I also agree with a simple attached trigger as it's the same thing, just no scripting :p.

Share this post


Link to post
Share on other sites
You are using wrong quotes “ instead of " or '. Just use single to make sure: execVM 'distance.sqf';

Works after this. Strange, I use the same quotes around other scripts when using execVM in other missions and it works fine.

Share this post


Link to post
Share on other sites
Works after this. Strange, I use the same quotes around other scripts when using execVM in other missions and it works fine.

I've never seen these kinds of quotes before, how did you make them?

Share this post


Link to post
Share on other sites
I've never seen these kinds of quotes before, how did you make them?

Erm, well, they are supposed to be just standard double quotes... like shift + ' = ". That is what I'm using. I don't know why it's acting weird.

Share this post


Link to post
Share on other sites
Erm, well, they are supposed to be just standard double quotes... like shift + ' = ". That is what I'm using. I don't know why it's acting weird.

What software are you typing your code in?

Share this post


Link to post
Share on other sites
I am typing in notepad.

In that case, welcome to scripting!

Starter pack:

Arma Edit (what I use)

my personal nearly-completely-updated command list (I haven't added the commands from the last 2 patches yet)

OR

Notepad++ (very reputable, I'm pretty sure 90% of the community uses this, and extremely flexible, allows users to create their own syntax highlighting. I even used this for a while, but not for arma projects)

Killzone's Hybrid Syntax Highlighter for Arma 2/3 (for notepad++)

Share this post


Link to post
Share on other sites

Not to forget: Poseidon

(maintained by one of the BIS devs. It has full syntax highlighting, all the latest script commands and also packs some special functions, snippets and tools.)

Share this post


Link to post
Share on other sites
On 12/8/2014 at 9:55 AM, killzone_kid said:
JShock said:
the below code should work:

 


while {true} do
{
waitUntil {(player distance a1) < 10};
a1 say3D "sound";
};
 

 

As soon as player closer than 10m to a1, say3D will be executed hundreds times per frame....endlessly.

 

i have the same problem how can i get this script to work everytime the condition is fulfilled instead once only.but without "while", because using "while" the script will be executed hundreds times per frame....endlessly causing a gamecrash.

 

[] spawn {  
	waitUntil {(player distance Medikit) < 1.3}; 

	if (getDammage player == 0) then {     
		playSound "ignoreItem";} else { 
 
	if (getDammage player > 0) then { 
  		playsound "pickItem";     
		player setDamage (damage player - 0.5);}; 
      };   
  
}; 

it only works once per condition

and then not anymore even if condition is fulfilled.

Share this post


Link to post
Share on other sites
7 hours ago, Alert23 said:

using "while" the script will be executed hundreds times per frame....endlessly causing a gamecrash

 

I guess that depends on where and how you use a while loop. I can see (hear) those sounds being played every frame and I doubt that's gonna be good for anyone. After you spawn the code, you still need to start the loop (with while for example), but you need a condition at the end of the loop to wait until the unit has moved away again. 

  • Like 1

Share this post


Link to post
Share on other sites

I don't know if it solves the looping but, just have a sleep for cooldown then execVM the script again after the sleep timer. Sorry if I shouldn't bump but it might help.

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  

×