Jump to content
Sign in to follow this  
lato1982

Condition of presence based on script

Recommended Posts

Hi,

I have a small issue with the condition of presence. I want to spawn a rebel camp, but I want it to have random (1 of 3) locations. So I placed all 3 camps on the map, with units fireplaces tents etc. and put into the init file a randomizer.

Init.sqf

camp_01_number = ceil (random 3);
camp_01a = false;
camp_01b = false;
camp_01c = false;

switch (true) do { 
				case (camp_01_number == 1): {camp_01a = true;};
				case (camp_01_number == 2): {camp_01b = true;};
				case (camp_01_number == 3): {camp_01c = true;};
			};

hint (str camp_01_number);

I put into each unit/object of the camp a presence condtion.

Example - a fireplace in Camp A

condition of presence

camp_01a

but nothing gets spawned. I assume that this is because the editor places the objects before the init defines and changes the values. Is there anyway to delay the editor objects spawn? Or the problem is different than I think?

I think this soultion is best to easy script a randomized camp location.

Thanks in Advance

EDIT:

I did an additional test and put this into the first spawned unit in game (looking at the mission.sqm):

camp_01a = true

but camp A is still not there,

Edited by Lato1982

Share this post


Link to post
Share on other sites

could try this...

camp_01_number = ceil (random 3); 
camp_01a = false; 
camp_01b = false; 
camp_01c = false; 

switch (camp_01_number) do {  
                   case  1: {camp_01a = true;}; 
                   case  2: {camp_01b = true;}; 
                   case  3: {camp_01c = true;}; 
                    default {hint "error"};
               }; 

hint (str camp_01_number);  

Share this post


Link to post
Share on other sites

Thanks, but still isn't this the problem that units are created before the init? The units are created before the init can define the variables.

Share this post


Link to post
Share on other sites

Everything you place using the Editor will be written into your mission.sqm-file, which gets read and executed way before your init.sqf can kick in - if you want to randomly create one of the camps, you have to do it in your init.sqf (e.g. the server/dedi).

One possible way could be this:

  1. gather all the objects' references for every camp in arrays. Name your objects according to your camps, like "tent3_camp1", or "fireplace1_camp2" or whatever you feel comfortable with.
    Now define a two dimensional array and insert the object's names:
    _campObjects = [
       ["tent1_camp1", "tent2_camp1", "fireplace1_camp1"],   // Camp1 objects
       ["tent1_camp2", "tent2_camp2"],                       // Camp2 objects
       ["tent3_camp3" ...... ]                               // Camp3 objects
    ];


  2. Randomly select one of the camps
    _selectedCamp = floor(random 3);


  3. Cycle through all the other camps objects and delete them (in your init.sqf):
    if (isServer) then
    {
       _selectedCamp = floor(random 3);
       _campObjects = [
           ["tent1_camp1", "tent2_camp1", "fireplace1_camp1"],   // Camp1 objects
           ["tent1_camp2", "tent2_camp2"],                       // Camp2 objects
           ["tent3_camp3" ...... ]                               // Camp3 objects
       ];
    
       for "_i" from 0 to 2 do 
       {
           if (_i != _selectedCamp) then 
           {
                _objectsInCamp = _campObjects select _i;
                {
                    deleteVehicle _x;
                } forEach _objectsInCamp;
           };
       };
    };
    


    Dont forget to actually fill in the array with the names of your objects, otherwise it won't work.

There is another, an automated way to do this, but it is exhaustive for the server so this should work well if you can put up with naming all of your objects :D

Share this post


Link to post
Share on other sites

Thanks!! I think deleting the objects will be the fastes way.

script:

_campsNumber = 3;

_luckyCamp = ceil (random _campsNumber);
_a = getMarkerPos "camp_01a";
_b = getMarkerPos "camp_01b";
_c = getMarkerPos "camp_01c";

if (_luckyCamp != 1) then {{deleteVehicle  _x} forEach nearestObjects [_a, [], 10] };
if (_luckyCamp != 2) then {{deleteVehicle  _x} forEach nearestObjects [_b, [], 10] };
if (_luckyCamp != 3) then {{deleteVehicle  _x} forEach nearestObjects [_c, [], 10] };

This works pretty good :) Thanks again for the 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  

×