Jump to content
Sign in to follow this  
JOHN007

Random Snake Location Script

Recommended Posts

Hello,

 

Searched and searched and found nothing regarding a simple script that could dynamically spawn snakes across a map? I tried using a trigger to first spawn three snakes but no luck. Here is the script named Snake.sqf.

 

Quote

if (!isServer) exitWith {};
_spawnPos = markerPos (_this select 0);

_group1 = createGroup CIVILIAN;
_unit1 = _group1 createUnit ["CSJ_Snake", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;
_unit2 = _group1 createUnit ["CSJ_Snake2", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;
_unit2 = _group1 createUnit ["CSJ_Snake3", [_spawnPos select 0,_spawnPos select 1,1], [], 1, "FORM"]; sleep 0.2;

 

 

Activated trigger with...

 

Quote

nul = [200,"spawnmarker"] execvm "Snake.sqf";

 

 

Activated with a marker named ''spawnmarker'' but no luck I tried to remove the 200'' from the trigger activate which, from reading the forums randomly spawns the unit 200 meters from the marker/trigger location?

 

Now I believe the ''createGroup'' is wrong which I tried EAST'' and RESISTANCE'' but still no luck I'm afraid?

 

Any help on this would be greatly appreciated.

 

Thankyou for your time and hope to speak soon.

 

John.

 

 

 

 

Share this post


Link to post
Share on other sites

Anybody?

 

Don't make us put a simple placement radius and % of spawn on these snakes, must be a more efficient way?

 

Spawning OPFOR units is no problem, these bloody snakes are.

Share this post


Link to post
Share on other sites

Has to be done through a script its silly placing x amount.

 

No replies?

Share this post


Link to post
Share on other sites

Hello.

.

The great TPW has provided a script which will dynamically spawn these bloody snakes but upon spawn they die.

 

They need a driver allocated to the snake which is Citizen1.

 

May I ask if anyone could spare some of their valuable time which I eternally appreciate. I will pay you through Patreon if needs be I don't mind. Time = money so I understand.

 

There's a small bug in the code which doesn't spawn the crew/driver. This is the reason why the snake dies upon spawn.

 

// Random snake spawner 
// TPW 20171025

hint "TPW Snakes active";
sleep 1;

// Variables
_min = 5; // minimum distance (m) from player to spawn snake
_max = 20; // maximum distance (m) from player to spawn snake - snakes will be removed if further than this from player
_time = 10; // maximum time (sec) in between each snake spawning
_maxsnakes = 10; // maximum number of snakes
_treemin = 5; // minimum number of trees within _max around player needed in order to spawn snakes
_hind1Group = creategroup east;

// Main loop
_snakearray = [];
while {true} do
    {
    // Delete distant snakes
    for "_i" from 0 to ((count _snakearray) - 1) do     
        {
        _snake = _snakearray select _i;
        if (_snake distance player > _max) then
            {
            _snakearray set [_i,-1];
            deletevehicle _snake;
            hint format ["Deleting %1",_snake];
            };
        };
    _snakearray = _snakearray - [-1];

    //Spawn new snake
        if (count _snakearray < _maxsnakes) then
        {
        // Random position around player 
        _pos = getposasl player;
        _dir = random 360;
        _dist = _min + random (_max - _min);
        _posx = (_pos select 0) + (_dist * sin _dir);
        _posy = (_pos select 1) +  (_dist * cos _dir);

        // If not in water???What??
		if !(surfaceiswater [_posx,_posy]) then
            { 
            _snake = createVehicle (["CSJ_Snake", "CSJ_Snake2", "CSJ_Snake3"] select floor random 3) [_posx,_posy];
			_driver = _hind1Group createUnit ["Citizen1", _spawn, [], 0, "NONE"];
			_driver assignAsDriver _snake;
			_driver moveindriver _snake;
			_driver hideobject true;
            //_snake = createAgent [_model,[_posx,_posy], [], 0, "FORM"];
            _snakearray = _snakearray +  [_snake];
            hint format ["Spawning %1",_snake];
            };
    };
    hint format ["%1 snakes", count _snakearray];
    sleep random _time;
    };

The actual snake isn't the problem as we have tried to spawn a bike with a driver using the same script method.

 

Thankyou for your time and hope to speak soon. SOS.

 

John.

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  

×