Jump to content
Sign in to follow this  
Online

Loop .sqf

Recommended Posts

Hi Guys,

i searched a loop function, but i am not sure what i need.

I have a script to remove the nvgoggles, but after the respawn everyone has again the goggles.

My .sqf

{

{

if (side _x == east) then {

_x unassignItem "NVGoggles";

_x removeItem "NVGoggles";

};

} foreach allunits;

{

if (side _y == west) then {

_y unassignItem "NVGoggles";

_yremoveItem "NVGoggles";

};

} foreach allunits;

};

I have also a virtual ammobox on my map and the people should take the normal gear, but only without the nvgoggles. The script works fine and it should only repeat every 5 or 10 seconds maybe.

Regards

Share this post


Link to post
Share on other sites

_x is special variable, it is not a Cartesian coordinate so using _y in second loop do nothing.

Share this post


Link to post
Share on other sites

that should do it, since you are removing it from boths sides

 {
_x unassignItem "NVGoggles";
_x removeItem "NVGoggles";
} foreach allunits;

Share this post


Link to post
Share on other sites

i had _x for both before, and this works for both sides.

I know i have no loop included at the moment. I know that loop do nothing, because i ask how to loop this function.

Share this post


Link to post
Share on other sites

Simple loop script

while {true} do {Your script here ; Sleep 5;};

Share this post


Link to post
Share on other sites

Thanks Mikie boy, i will change it.

I will try thy loop script.

And if i use this, how fast will work this loop? Instant if a player try to get the goggles?

Share this post


Link to post
Share on other sites

Every 5 seconds. Thus the sleep command at the end of each loop

Share this post


Link to post
Share on other sites

Yes now i see, my fault :)

---------- Post added at 19:06 ---------- Previous post was at 19:04 ----------

Now i have this:

while {true} do

{

_x unassignItem "NVGoggles";

_x removeItem "NVGoggles";

} foreach allunits;

Sleep 5;};

But the script doesnt work now.

Share this post


Link to post
Share on other sites
while {true} do

{

private [_x];

_x unassignItem "NVGoggles";

_x removeItem "NVGoggles";

} foreach allunits;

Sleep 5;};

Now change

Share this post


Link to post
Share on other sites

while {true} do {
{
{
if (side _x == east) then {
_x unassignItem "NVGoggles";
_x removeItem "NVGoggles";
};

} foreach allunits;
{
if (side _y == west) then {
_y unassignItem "NVGoggles";
_yremoveItem "NVGoggles";
};

} foreach allunits;
};
Sleep 5;};

Try that.

  • Like 1

Share this post


Link to post
Share on other sites

Okay just a second :)

---------- Post added at 19:24 ---------- Previous post was at 19:16 ----------

What the hell.. now the script doesnt work, i mean without the loop.

I use the same script like in the beginning and now it doenst work, how can that happend?

---------- Post added at 19:37 ---------- Previous post was at 19:24 ----------

Perfect!! Now it works fine. :D

I used this:

while {true} do {

{

if (side _x == east) then {

_x unassignItem "NVGoggles";

_x removeItem "NVGoggles";

};

} foreach allunits;

{

if (side _x == west) then {

_x unassignItem "NVGoggles";

_x removeItem "NVGoggles";

};

} foreach allunits;

Sleep 5;};

Really big thanks BangaBob!

Share this post


Link to post
Share on other sites
try putting this at the top of the script

private [_x];

it is private ["_x"]; (quotation mark) and you also dont need it since _x is special variable it is private by default within the scope.

Share this post


Link to post
Share on other sites

Sorry didnt see the bit that you required a loop, in any case I don't seethe relevance of differentiating between side if you are taking the NV goggles from everyone. Would assume its pointless waste of cpu wizardry :)

while {true} do
{
 {

  _x unassignItem "NVGoggles";
  _x removeItem "NVGoggles";

 } foreach allunits;


Sleep 5;

};

If you dont need a loop to remove the goggles and only for respawn you could always just plop this into the init.sqf;

RemoveGoggles= compile (preprocessFileLineNumbers "RemoveGoggles.sqf");
player addEventHandler ["Killed",{[_this select 0] spawn RemoveGoggles; }];

RemoveGoggles.sqf


Waitunily {!isnull Player};
_respawnedDude = _this select 0;

_respawnedDude unassignItem "NVGoggles"; 
_respawnedDude removeItem "NVGoggles";

not tested but just a thought :)

Share this post


Link to post
Share on other sites

It works fine now and i dont want to edit.

"Dont change a running system" ;)

Btw. i need the loop, because i have a virtual ammobox and the people should use every weapon and saved kits but only without the nv. Its a night mission and a lot more action if the people only use the lamp at the weapon.

Share this post


Link to post
Share on other sites

BTW you can easily remove the NVgoggles from VAS.

Search for the missionfolder/gear/config.sqf

Iniside the config file just add "NVGoggles" to the bottom string

//Items to remove from VAS

vas_r_items = [];

So it looks like

//Items to remove from VAS

vas_r_items = ["NVGoggles"];

Share this post


Link to post
Share on other sites

Lol. Nice one. Online suggest u use that method instead of having an unnecessary loop.

Share this post


Link to post
Share on other sites

I think i use at first my method and if i will have cpu or other problems, i will try the other one.

Or i try this later, but for now it works. :)

But the tip with the VAS is really helpful.

Thanks to everyone!!!

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  

×