Jump to content
Sign in to follow this  
MrMichael

Remove Nightvision Add Flashnight ZEUS script loop server

Recommended Posts

Hello,

I'm trying to make a script that constantly removes nightvision and adds flashlight attachments to units spawned in a dedicated server ZEUS environment.

Currently it looks like this in init.sqf:

if (isserver) then {

while {true} do {

{

if (side _x == independent) then

{

_x removeweapon "NVGoggles_INDEP";

_x removePrimaryWeaponItem "acc_pointer_IR";

_x addPrimaryWeaponItem "acc_flashlight";

_x enableGunLights "forceon";

};

}foreach allUnits;

sleep 5;

}

};

While removing nightvision seems to work, the next parts, removing the acc_pointer_ir and adding acc_flashlight do not do anything.

It all runs fine on a non-dedicated server, but I have no idea how to make it work on a dedicated server.

Does anyone have any ideas on how I could make this work?

Share this post


Link to post
Share on other sites

Like is posted so many times on these forums, please do NOT put sleep's or waitUntil's in the init.sqf

init.sqf

==========

execVM "nightStuff.sqf"

nightStuff.sqf

=============

if (!isServer) exitWith {};

while {true} do
{
   sleep 5;
   {
       if (side _x == independent) then
       {
           _x removeweapon "NVGoggles_INDEP";
           _x removePrimaryWeaponItem "acc_pointer_IR";
           _x addPrimaryWeaponItem "acc_flashlight";
           _x enableGunLights "forceon";
       };
   } forEach allUnits;
};

Share this post


Link to post
Share on other sites

you should use resistance. there is no such thing as independent :P

if (!isServer) exitWith {};

while {true} do
{
   sleep 5;
   {
       if (side _x == resistance) then
       {
           _x removeweapon "NVGoggles_INDEP";
           _x removePrimaryWeaponItem "acc_pointer_IR";
           _x addPrimaryWeaponItem "acc_flashlight";
           _x enableGunLights "forceon";
       };
   } forEach allUnits;
};

Share this post


Link to post
Share on other sites
Like is posted so many times on these forums, please do NOT put sleep's or waitUntil's in the init.sqf

init.sqf

==========

execVM "nightStuff.sqf"

nightStuff.sqf

=============

if (!isServer) exitWith {};

while {true} do
{
   sleep 5;
   {
       if (side _x == independent) then
       {
           _x removeweapon "NVGoggles_INDEP";
           _x removePrimaryWeaponItem "acc_pointer_IR";
           _x addPrimaryWeaponItem "acc_flashlight";
           _x enableGunLights "forceon";
       };
   } forEach allUnits;
};

Sorry, I didn't know it made a difference. I actually do have it like that

In Init.sqf:

//NVGs    
if (isserver) then {execVM "nvg.sqf";};

and in nvg.sqf

//if (isserver) then {
//while {true} do {
//{ 
//        if (side _x == east) then  
//        { 
//                _x removeweapon "NVGoggles_OPFOR"; 
//                _x removePrimaryWeaponItem "acc_pointer_IR"; 
//                _x addPrimaryWeaponItem "acc_flashlight"; 
//        }; 
//    }foreach allUnits;
// 
//sleep 5;
//}
//};
//
//if (isserver) then { 
//while {true} do {
//{ 
//        if (side _x == west) then  
//        { 
//                _x removeweapon "NVGoggles_BLUFOR"; 
//                _x removePrimaryWeaponItem "acc_pointer_IR"; 
//                _x addPrimaryWeaponItem "acc_flashlight"; 
//        }; 
//   }foreach allUnits;
//
//sleep 5;
//}
//};
//
if (isserver) then {
while {true} do {
{ 
       if (side _x == independent) then  
       { 
               _x removeweapon "NVGoggles_INDEP"; 
               _x removePrimaryWeaponItem "acc_pointer_IR"; 
               _x addPrimaryWeaponItem "acc_flashlight"; 
		_x enableGunLights "forceon";
       }; 
   }foreach allUnits;

sleep 5;
}
};

you should use resistance. there is no such thing as independent :P

if (!isServer) exitWith {};

while {true} do
{
   sleep 5;
   {
       if (side _x == resistance) then
       {
           _x removeweapon "NVGoggles_INDEP";
           _x removePrimaryWeaponItem "acc_pointer_IR";
           _x addPrimaryWeaponItem "acc_flashlight";
           _x enableGunLights "forceon";
       };
   } forEach allUnits;
};

So far it's working with Independant, but only on non-dedicated servers.

With dedicated server, it runs up to the point of removing the NVGs, but not removing the IR laser and adding the flashlight.

I'll give Kushluk's solution a try now

Share this post


Link to post
Share on other sites

I would do if (isServer OR isDedicated)

---------- Post added at 18:42 ---------- Previous post was at 18:35 ----------

if (!isServer OR !isDedicated) exitWith {};

if (isServer OR isDedicated) then {
[] spawn {
	while {true} do
	{
		sleep 5;
		{
			if (side _x == resistance) then
			{
				_x removeweapon "NVGoggles_INDEP";
				_x removePrimaryWeaponItem "acc_pointer_IR";
				_x addPrimaryWeaponItem "acc_flashlight";
				_x enableGunLights "forceon";
			};
		} forEach allUnits;
	};  
};
};

Share this post


Link to post
Share on other sites

you can delete the first line:

if (!isServer OR !isDedicated) exitWith {};

as you determine in the next line that only servers and dedicated servers execute this code, so all clients just check the if condition of:

if (isServer OR isDedicated)

and scipt to end of this if case.

at the end is nothing so it will exit.

So this will be enough:

if (isServer OR isDedicated) then {
   [] spawn {
       while {true} do
       {
           sleep 5;
           {
               if (side _x == resistance) then
               {
                   _x removeweapon "NVGoggles_INDEP";
                   _x removePrimaryWeaponItem "acc_pointer_IR";
                   _x addPrimaryWeaponItem "acc_flashlight";
                   _x enableGunLights "forceon";
               };
           } forEach allUnits;
       };  
   };
};  

there are more elegant ways to do this but, for a simple mission this will be ok.

Share this post


Link to post
Share on other sites

Just tested all solutions above, still end up with the same result as before.

On dedicated servers, it removes the NVGs but not replace the designator with the flashlight

Whereas on local server, it works fine.

EDIT:

Seems the solution is to remove:

if (isServer OR isDedicated) then {

then it works.

Thanks for you all your help!

Edited by MrMichael

Share this post


Link to post
Share on other sites

Is there a way to only have this apply the fia units? I suppose an array of some I kind?

Share this post


Link to post
Share on other sites

Try this...

 

Add this to init.sqf

[] execVM 'RemoveNV.sqf';

RemoveNV.sqf

/*    ConfigAI With Flashlight Based on Faction
    By Beerkan
    Add this to the init.sqf
    [] execVM 'RemoveNV.sqf';
    Factions
    West: "BLU_F" (NATO), "BLU_G_F" (FIA)
    East: "OPF_F" (CSAT), "OPF_G_F" (FIA)
    Guer: "IND_F" (AAF), "IND_G_F" (FIA)
    Civ: "CIV_F" (Civilians)
*/

//Client/Server Check
if (!isServer) exitWith {};
    {if (_x IsKindof 'Man' && faction _x isEqualTo 'OPF_G_F')
            then {
                    if ('NVGoggles_OPFOR' in assignedItems _x) then {_x unlinkitem 'NVGoggles_OPFOR';_x removeitem 'NVGoggles_OPFOR';};
                    if ('NVGoggles_INDEP' in assignedItems _x) then {_x unlinkitem 'NVGoggles_INDEP';_x removeitem 'NVGoggles_INDEP';};
                //Now add Flashlight only if it's night..
                _GiveFlashlight = sunOrMoon;
                    if (_x IsKindof 'Man' && _GiveFlashlight < 1)
                        then {
                            _x unassignItem 'acc_pointer_IR';
                            _x removePrimaryWeaponItem 'acc_pointer_IR';
                            _x addPrimaryWeaponItem 'acc_flashlight';
                            _x assignItem 'acc_flashlight';
                            _x enableGunLights 'ForceOn';
                            _x setskill ['spotDistance',(0 + random 0.4)];// Reduce vision for night time
                            _x setskill ['spotTime',(0 + random 0.4)];
                            };
                };
    } forEach allUnits;

Share this post


Link to post
Share on other sites

 

Then the commands are captious to |where it is executed| try to run it everywhere and find where it is working `(would be nice to have the knowledge).

Share this post


Link to post
Share on other sites

Then the commands are captious to |where it is executed| try to run it everywhere and find where it is working `(would be nice to have the knowledge).

The reason for this oddity is unit locality. AFAIK units created using Zeus are local to the machine that created them (a.k.a. the player playing as Zeus) until that player leaves. At that point the units are transferred to the server. Since addPrimaryWeaponItem and other similiar commands require a local argument they take no effect when run solely on the dedicated server because the units are simulated on the Zeus client. The workaround is to let each client take care of all units it is simulating, e.g. run something like this on every client:

{
    if(local unit) then {
        unit addPrimaryWeaponItem "whatever"
        ....
    };
} forEach allUnits;

Additionally removing NVG's and IR-lasers is not required on Guerrillas since they do not spawn with that equipment.

  • Like 1

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  

×